Exemplo n.º 1
0
    def macro(self, macro_obj, name, args, markup=None):
        """As far as the DocBook formatter is concerned there are three
        kinds of macros: Bad, Handled and Unknown.

        The Bad ones are the ones that are known not to work, and are on its
        blacklist. They will be ignored and an XML comment will be written
        noting that the macro is not supported.

        Handled macros are such macros that code is written to handle them.
        For example for the FootNote macro it means that instead of executing
        the macro, a DocBook footnote entity is created, with the relevant
        pieces of information filles in.

        The Unknown are handled by executing the macro and capturing any
        textual output. There shouldn't be any textual output since macros
        should call formatter methods. This is unfortunately not always true,
        so the output it is then fed in to an xml parser and the
        resulting nodes copied to the DocBook-dom tree. If the output is not
        valid xml then a comment is written in the DocBook that the macro
        should be fixed.

        """
        # Another alternative would be to feed the output to rawHTML or even
        # combining these two approaches. The _best_ alternative would be to
        # fix the macros.
        excludes = (u"articleinfo", u"title")

        if name in self.blacklisted_macros:
            self._emitComment(
                "The macro %s doesn't work with the DocBook formatter." % name)

        elif name == u"FootNote":
            footnote = tree.element(None, u"footnote")
            self._addTextElem(footnote, u"para", str(args))
            self.cur.xml_append(footnote)

        elif name == u"Include":
            was_in_para = self.cur.xml_qname == u"para"
            if was_in_para:
                self.paragraph(0)
            text = FormatterBase.macro(self, macro_obj, name, args)
            if text.strip():
                self._includeExternalDocument(text, exclude=excludes)
            if was_in_para:
                self.paragraph(1)

        else:
            text = FormatterBase.macro(self, macro_obj, name, args)
            if text:
                try:
                    self._includeExternalDocument(text, exclude=excludes)
                #FIXME: check for parse-related errors, realy
                except ExpatError:
                    self._emitComment(
                        u"The macro %s caused an error and should be blacklisted (and you might want to file a bug with the developer). It returned the following data which caused the docbook-formatter to choke. '%s'"
                        % (name, text))

        return u""
Exemplo n.º 2
0
    def macro(self, macro_obj, name, args, markup=None):
        """As far as the DocBook formatter is concerned there are three
        kinds of macros: Bad, Handled and Unknown.

        The Bad ones are the ones that are known not to work, and are on its
        blacklist. They will be ignored and an XML comment will be written
        noting that the macro is not supported.

        Handled macros are such macros that code is written to handle them.
        For example for the FootNote macro it means that instead of executing
        the macro, a DocBook footnote entity is created, with the relevant
        pieces of information filles in.

        The Unknown are handled by executing the macro and capturing any
        textual output. There shouldn't be any textual output since macros
        should call formatter methods. This is unfortunately not always true,
        so the output it is then fed in to an xml parser and the
        resulting nodes copied to the DocBook-dom tree. If the output is not
        valid xml then a comment is written in the DocBook that the macro
        should be fixed.

        """
        # Another alternative would be to feed the output to rawHTML or even
        # combining these two approaches. The _best_ alternative would be to
        # fix the macros.
        excludes = (u"articleinfo", u"title")

        if name in self.blacklisted_macros:
            self._emitComment("The macro %s doesn't work with the DocBook formatter." % name)

        elif name == u"FootNote":
            footnote = tree.element(None, u"footnote")
            self._addTextElem(footnote, u"para", str(args))
            self.cur.xml_append(footnote)

        elif name == u"Include":
            was_in_para = self.cur.xml_qname == u"para"
            if was_in_para:
                self.paragraph(0)
            text = FormatterBase.macro(self, macro_obj, name, args)
            if text.strip():
                self._includeExternalDocument(text, exclude=excludes)
            if was_in_para:
                self.paragraph(1)

        else:
            text = FormatterBase.macro(self, macro_obj, name, args)
            if text:
                try:
                    self._includeExternalDocument(text, exclude=excludes)
                # FIXME: check for parse-related errors, realy
                except ExpatError:
                    self._emitComment(
                        u"The macro %s caused an error and should be blacklisted (and you might want to file a bug with the developer). It returned the following data which caused the docbook-formatter to choke. '%s'"
                        % (name, text)
                    )

        return u""
Exemplo n.º 3
0
    def macro(self, macro_obj, name, args, markup=None):
        """As far as the DocBook formatter is conserned there are three
        kinds of macros: Bad, Handled and Unknown.

        The Bad ones are the ones that are known not to work, and are on its
        blacklist. They will be ignored and an XML comment will be written
        noting that the macro is not supported.

        Handled macros are such macros that code is written to handle them.
        For example for the FootNote macro it means that instead of executing
        the macro, a DocBook footnote entity is created, with the relevant
        pieces of information filles in.

        The Unknown are handled by executing the macro and capturing any
        textual output. There shouldn't be any textual output since macros
        should call formatter methods. This is unfortunately not always true,
        so the output it is then fed in to an xml parser and the
        resulting nodes copied to the DocBook-dom tree. If the output is not
        valid xml then a comment is written in the DocBook that the macro
        should be fixed.

        """
        # Another alternative would be to feed the output to rawHTML or even
        # combining these two approaches. The _best_ alternative would be to
        # fix the macros.
        excludes=("articleinfo", "title")

        if name in self.blacklisted_macros:
            self._emitComment("The macro %s doesn't work with the DocBook formatter." % name)

        elif name == "FootNote":
            footnote = self.doc.createElement('footnote')
            self._addTextElem(footnote, "para", str(args))
            self.cur.appendChild(footnote)

        elif name == "Include":
            was_in_para = self.cur.nodeName == "para"
            if was_in_para:
                self.paragraph(0)
            text = FormatterBase.macro(self, macro_obj, name, args)
            if text.strip():
                self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
            if was_in_para:
                self.paragraph(1)

        else:
            text = FormatterBase.macro(self, macro_obj, name, args)
            if text:
                from xml.parsers.expat import ExpatError
                try:
                    xml_dom = Sax.FromXml(text).documentElement.childNodes
                    self._copyExternalNodes(xml_dom, exclude=excludes)
                except ExpatError:
                    self._emitComment("The macro %s caused an error and should be blacklisted. It returned the data '%s' which caused the docbook-formatter to choke. Please file a bug." % (name, text))

        return u""
Exemplo n.º 4
0
 def macro(self, macro_obj, name, args, markup=None):
     # Macro response are (unescaped) markup.  Do what little clean-up we camn, and cross fingers
     output = FormatterBase.macro(self, macro_obj, name, args, markup=markup)
     # response is Unicode
     if output:
         output_body = markup_fragment(inputsource.text(output.encode(config.charset)))
         # print "macro 2", repr(output)
         self._curr.xml_append(output_body)
     return ""
Exemplo n.º 5
0
 def macro(self, macro_obj, name, args, markup=None):
     try:
         # plugins that are defined in the macro class itself
         # can't generate headings this way, but that's fine
         gen_headings = wikiutil.importPlugin(self.request.cfg, 'macro',
                                              name, 'generates_headings')
         return FormatterBase.macro(self, macro_obj, name, args, markup)
     except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
         pass
     return ''
Exemplo n.º 6
0
Arquivo: TOC.py Projeto: 130s/roswiki
 def macro(self, macro_obj, name, args, markup=None):
     try:
         # plugins that are defined in the macro class itself
         # can't generate headings this way, but that's fine
         gen_headings = wikiutil.importPlugin(self.request.cfg, 'macro',
                                              name, 'generates_headings')
         return FormatterBase.macro(self, macro_obj, name, args, markup)
     except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
         pass
     return ''
Exemplo n.º 7
0
 def macro(self, macro_obj, name, args, markup=None):
     #Macro response are (unescaped) markup.  Do what little clean-up we camn, and cross fingers
     output = FormatterBase.macro(self,
                                  macro_obj,
                                  name,
                                  args,
                                  markup=markup)
     #response is Unicode
     if output:
         output_body = markup_fragment(
             inputsource.text(output.encode(config.charset)))
         #print "macro 2", repr(output)
         self._curr.xml_append(output_body)
     return ''
Exemplo n.º 8
0
    def macro(self, macro_obj, name, args, markup=None):
        """As far as the DocBook formatter is conserned there are three
        kinds of macros: Bad, Handled and Unknown.

        The Bad ones are the ones that are known not to work, and are on its
        blacklist. They will be ignored and an XML comment will be written
        noting that the macro is not supported.

        Handled macros are such macros that code is written to handle them.
        For example for the FootNote macro it means that instead of executing
        the macro, a DocBook footnote entity is created, with the relevant
        pieces of information filles in.

        The Unknown are handled by executing the macro and capturing any
        textual output. There shouldn't be any textual output since macros
        should call formatter methods. This is unfortunately not always true,
        so the output it is then fed in to an xml parser and the
        resulting nodes copied to the DocBook-dom tree. If the output is not
        valid xml then a comment is written in the DocBook that the macro
        should be fixed.

        """
        # Another alternative would be to feed the output to rawHTML or even
        # combining these two approaches. The _best_ alternative would be to
        # fix the macros.
        excludes = ("articleinfo", "title")

        if name in self.blacklisted_macros:
            self._emitComment(
                "The macro %s doesn't work with the DocBook formatter." % name)

        elif name == "FootNote":
            footnote = self.doc.createElement('footnote')
            self._addTextElem(footnote, "para", str(args))
            self.cur.appendChild(footnote)

        elif name == "Include":
            was_in_para = self.cur.nodeName == "para"
            if was_in_para:
                self.paragraph(0)

            # Regular Expression to match editlink arg, remove it because it causes trouble.
            _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
            macro_args = re.sub(_arg_editlink, '', args)

            text = FormatterBase.macro(self, macro_obj, name, macro_args)
            if text.strip():
                self._copyExternalNodes(
                    minidom.parseString(text).documentElement.childNodes,
                    exclude=excludes)
            if was_in_para:
                self.paragraph(1)

        else:
            text = FormatterBase.macro(self, macro_obj, name, args)
            if text:
                from xml.parsers.expat import ExpatError
                try:
                    xml_dom = minidom.parseString(
                        text).documentElement.childNodes
                    self._copyExternalNodes(xml_dom, exclude=excludes)
                except ExpatError:
                    self._emitComment(
                        "The macro %s caused an error and should be blacklisted. It returned the data '%s' which caused the docbook-formatter to choke. Please file a bug."
                        % (name, text))

        return u""