"""
    MoinMoin - Freemind Text Parser
 
    Copyright (c) 2006 by Ben Kavanagh
    All rights reserved, see COPYING for details.
 
"""

from MoinMoin import wikimacro

class Parser:
    """
        Send HTML code raw
    """

    def __init__(self, raw, request, **kw): 
        self.raw_text = raw
        self.request = request
        self.form = []

    
    # All freemind parser does is ignore text and add a FreeMindBrowser section with
    # url pointing to this page with action=getmmap.
    # getmmap action simply uses regular expression to grap first {{{#!freemind <map..> .. </map>}}}
    # section in page.
    # improvements would be to add identifier. This gives weight to the argument for merging
    # macros/processors/parsers.
    
    def format(self, formatter):  
        """ Send the "parsed" text.
        """

        mmapUrl = "http://" + self.request.url + "?action=getmmap"

        # create macro instance
        macro_obj = wikimacro.Macro(self)

        # formatter.macro calls "return macro_obj.execute(name, args)"
        self.html = formatter.macro(macro_obj, "FreeMindBrowser", mmapUrl)

        self.request.write(self.html)
