コード例 #1
0
 def pagelink(self, on, pagename='', page=None, **kw):
     FormatterBase.pagelink(self, on, pagename, page, **kw)
     if page is None:
         page = Page(self.request, pagename, formatter=self)
     link_text = page.link_to(self.request, on=on, **kw)
     self._curr.xml_append(tree.text(U(link_text)))
     return ''
コード例 #2
0
ファイル: groups.py プロジェクト: IvanLogvinov/soar
    def __init__(self, request, **kw):
        FormatterBase.__init__(self, request, **kw)

        self.members = []
        self._bullet_list_level = 0
        self._inside_link = False
        self._new_member = ''
コード例 #3
0
ファイル: dom_xml.py プロジェクト: steveyen/moingo
    def __init__(self, request, **kw):
        FormatterBase.__init__(self, request, **kw)

        self.document = minidom.Document()
        self.document.documentElement = self.document.createElement('xml')
        self.position = self.document.documentElement
        self.tag_stack = [('xml', {})]
コード例 #4
0
ファイル: text_x-rst.py プロジェクト: epronk/moin2rst
 def paragraph(self, on, **kw):
     # Maintain the accessible flag `in_p`
     FormatterBase.paragraph(self, on)
     if on:
         return self._output()
     else:
         return self._output_EOL_BLK()
コード例 #5
0
 def paragraph(self, on, **kw):
     FormatterBase.paragraph(self, on)
     if on:
         self.paragraph_begin()
     else:
         self.paragraph_end()
     return ''
コード例 #6
0
ファイル: application_xml.py プロジェクト: pombredanne/akara
 def pagelink(self, on, pagename="", page=None, **kw):
     FormatterBase.pagelink(self, on, pagename, page, **kw)
     if page is None:
         page = Page(self.request, pagename, formatter=self)
     link_text = page.link_to(self.request, on=on, **kw)
     self._curr.xml_append(tree.text(U(link_text)))
     return ""
コード例 #7
0
ファイル: text_plain.py プロジェクト: IvanLogvinov/soar
 def paragraph(self, on, **kw):
     FormatterBase.paragraph(self, on)
     if on:
         self.paragraph_begin()
     else:
         self.paragraph_end()
     return ''
コード例 #8
0
ファイル: groups.py プロジェクト: aahlad/soar
    def __init__(self, request, **kw):
        FormatterBase.__init__(self, request, **kw)

        self.members = []
        self._bullet_list_level = 0
        self._inside_link = False
        self._new_member = ''
コード例 #9
0
    def __init__(self, request, **kw):
        FormatterBase.__init__(self, request, **kw)

        self.document = minidom.Document()
        self.document.documentElement = self.document.createElement('xml')
        self.position = self.document.documentElement
        self.tag_stack = [('xml', {})]
コード例 #10
0
ファイル: text_plain.py プロジェクト: steveyen/moingo
 def preformatted(self, on, **kw):
     FormatterBase.preformatted(self, on)
     snip = u'---%<'
     snip = snip + (u'-' * (78 - len(snip)))
     if on:
         return u'\n' + snip + u'\n'
     else:
         return snip + u'\n'
コード例 #11
0
ファイル: text_docbook.py プロジェクト: mredar/akara
    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""
コード例 #12
0
ファイル: text_docbook.py プロジェクト: pombredanne/akara
    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""
コード例 #13
0
 def __init__(self, request, **kw):
     FormatterBase.__init__(self, request, **kw)
     self._current_depth = 1
     self._base_depth = 0
     self.in_pre = 0
     self._doc = tree.entity()
     self._curr = self._doc
     #self._writer = structwriter(indent=u"yes", encoding=config.charset)
     return
コード例 #14
0
ファイル: text_plain.py プロジェクト: steveyen/moingo
 def __init__(self, request, **kw):
     FormatterBase.__init__(self, request, **kw)
     self._in_code_area = 0
     self._in_code_line = 0
     self._code_area_state = [0, -1, -1, 0]
     self._in_list = 0
     self._did_para = 0
     self._url = None
     self._text = None # XXX does not work with links in headings!!!!!
コード例 #15
0
ファイル: application_xml.py プロジェクト: pombredanne/akara
 def __init__(self, request, **kw):
     FormatterBase.__init__(self, request, **kw)
     self._current_depth = 1
     self._base_depth = 0
     self.in_pre = 0
     self._doc = tree.entity()
     self._curr = self._doc
     # self._writer = structwriter(indent=u"yes", encoding=config.charset)
     return
コード例 #16
0
ファイル: text_docbook.py プロジェクト: steveyen/moingo
    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""
コード例 #17
0
ファイル: dom_xml.py プロジェクト: steveyen/moingo
 def _close_tag(self, tag):
     """ low level function: closes tag right now
         must be the last opened tag!!!
     """
     if tag == 'p':
         FormatterBase.paragraph(self, 0)
     if self.tag_stack[-1][0] != tag:
         raise ValueError, "closing of <%s> expected, but <%s> closed" % (self.tag_stack[-1][0], tag)
     self.position = self.position.parentNode
     return self.tag_stack.pop()
コード例 #18
0
 def _close_tag(self, tag):
     """ low level function: closes tag right now
         must be the last opened tag!!!
     """
     if tag == 'p':
         FormatterBase.paragraph(self, 0)
     if self.tag_stack[-1][0] != tag:
         raise ValueError("closing of <%s> expected, but <%s> closed" %
                          (self.tag_stack[-1][0], tag))
     self.position = self.position.parentNode
     return self.tag_stack.pop()
コード例 #19
0
ファイル: text_x-rst.py プロジェクト: epronk/moin2rst
 def preformatted(self, on, **kw):
     # Maintain the accessible flag `in_pre`
     FormatterBase.preformatted(self, on)
     if on:
         # TODO Minmized styles should be supported
         result = self._output_EOL_BLK(u"::")
         self._indentation += 3
         return result
     else:
         self._indentation -= 3
         return self._output_EOL_BLK()
コード例 #20
0
ファイル: text_x-rst.py プロジェクト: ismaelbej/moin2rst
 def preformatted(self, on, **kw):
     # Maintain the accessible flag `in_pre`
     FormatterBase.preformatted(self, on)
     if on:
         # TODO Minmized styles should be supported
         result = self._output_EOL_BLK(u"::")
         self._indentation += 3
         return result
     else:
         self._indentation -= 3
         return self._output_EOL_BLK()
コード例 #21
0
 def preformatted(self, on, **kw):
     FormatterBase.preformatted(self, on)
     snip = u'%s\n' % u'---%<'.ljust(78 - self._indent, u'-')
     if on:
         self.paragraph_begin()
         return self.wrap(snip)
     else:
         if self._textbuf and not self._textbuf.endswith('\n'):
             self._textbuf += '\n'
         result = self.wrap(snip)
         self.paragraph_end()
         return result
コード例 #22
0
ファイル: text_gedit.py プロジェクト: IvanLogvinov/soar
    def pagelink(self, on, pagename='', page=None, **kw):
        """ Link to a page.

            formatter.text_python will use an optimized call with a page!=None
            parameter. DO NOT USE THIS YOURSELF OR IT WILL BREAK.

            See wikiutil.link_tag() for possible keyword parameters.
        """
        FormatterBase.pagelink(self, on, pagename, page, **kw)
        if page is None:
            page = Page(self.request, pagename, formatter=self)
        return page.link_to(self.request, on=on, **kw)
コード例 #23
0
ファイル: text_plain.py プロジェクト: IvanLogvinov/soar
 def preformatted(self, on, **kw):
     FormatterBase.preformatted(self, on)
     snip = u'%s\n' % u'---%<'.ljust(78 - self._indent, u'-')
     if on:
         self.paragraph_begin()
         return self.wrap(snip)
     else:
         if self._textbuf and not self._textbuf.endswith('\n'):
             self._textbuf += '\n'
         result = self.wrap(snip)
         self.paragraph_end()
         return result
コード例 #24
0
ファイル: text_gedit.py プロジェクト: tanghejun/volunpedia
    def pagelink(self, on, pagename='', page=None, **kw):
        """ Link to a page.

            formatter.text_python will use an optimized call with a page!=None
            parameter. DO NOT USE THIS YOURSELF OR IT WILL BREAK.

            See wikiutil.link_tag() for possible keyword parameters.
        """
        FormatterBase.pagelink(self, on, pagename, page, **kw)
        if page is None:
            page = Page(self.request, pagename, formatter=self)
        return page.link_to(self.request, on=on, **kw)
コード例 #25
0
    def paragraph(self, on, **kw):
        FormatterBase.paragraph(self, on)

        # Let's prevent empty paras
        if not on:
            if not self._hasContent(self.cur):
                oldnode = self.cur
                self.cur = oldnode.parentNode
                self.cur.removeChild(oldnode)
                return ""

        # Let's prevent para inside para
        if on and self.cur.nodeName == "para":
            return ""
        return self._handleNode("para", on)
コード例 #26
0
ファイル: text_docbook.py プロジェクト: mredar/akara
    def paragraph(self, on, **kw):
        FormatterBase.paragraph(self, on)

        # Let's prevent empty paras
        if not on:
            if not self._hasContent(self.cur):
                oldnode = self.cur
                self.cur = oldnode.xml_parent
                self.cur.xml_remove(oldnode)
                return ""

        # Let's prevent para inside para
        if on and self.cur.xml_qname == u"para":
            return ""
        return self._handleNode(u"para", on)
コード例 #27
0
ファイル: text_docbook.py プロジェクト: pombredanne/akara
    def paragraph(self, on, **kw):
        FormatterBase.paragraph(self, on)

        # Let's prevent empty paras
        if not on:
            if not self._hasContent(self.cur):
                oldnode = self.cur
                self.cur = oldnode.xml_parent
                self.cur.xml_remove(oldnode)
                return ""

        # Let's prevent para inside para
        if on and self.cur.xml_qname == u"para":
            return ""
        return self._handleNode(u"para", on)
コード例 #28
0
    def paragraph(self, on, **kw):
        FormatterBase.paragraph(self, on)

        # Let's prevent empty paras
        if not on:
            if not self._hasContent(self.cur):
                oldnode = self.cur
                self.cur = oldnode.parentNode
                self.cur.removeChild(oldnode)
                return ""

        # Let's prevent para inside para
        if on and self.cur.nodeName == "para":
            return ""
        return self._handleNode("para", on)
コード例 #29
0
ファイル: text_xml.py プロジェクト: aahlad/soar
 def image(self, src=None, **kw):
     valid_attrs = ['src', 'width', 'height', 'alt', 'title']
     attrs = {'src': src}
     for key, value in kw.items():
         if key in valid_attrs:
             attrs[key] = value
     return FormatterBase.image(self, **attrs) + '</img>'
コード例 #30
0
ファイル: dom_xml.py プロジェクト: steveyen/moingo
    def _open_tag(self, tag, **attrs):
        """ low level function: opens tag right now

        @param tag: tag name, string
        @param attrs: attributes keywords, ascii or unicode
        """
        if tag == 'p':
            FormatterBase.paragraph(self, 1)
        self.tag_stack.append((tag, attrs))
        node = self.document.createElement(tag)
        for name, value in attrs.items():
            if value:
                node.setAttribute(name, unicode(value))
        self.position.appendChild(node)
        self.position = node
        return ''
コード例 #31
0
    def _open_tag(self, tag, **attrs):
        """ low level function: opens tag right now

        @param tag: tag name, string
        @param attrs: attributes keywords, ascii or unicode
        """
        if tag == 'p':
            FormatterBase.paragraph(self, 1)
        self.tag_stack.append((tag, attrs))
        node = self.document.createElement(tag)
        for name, value in attrs.items():
            if value:
                node.setAttribute(name, unicode(value))
        self.position.appendChild(node)
        self.position = node
        return ''
コード例 #32
0
 def __init__(self, request, **kw):
     FormatterBase.__init__(self, request, **kw)
     self._in_code_area = 0
     self._in_code_line = 0
     self._code_area_state = [0, -1, -1, 0]
     self._lists = []
     self._url = None
     self._text = None  # XXX does not work with links in headings!!!!!
     self._text_stack = []
     self._skip_text = False
     self._wrap_skip_text = False
     self._textbuf = ''
     self._indent = 0
     self._listitem_on = []
     self._empty_line_count = 2
     self._paragraph_ended = False
     self._paragraph_skip_begin = True
コード例 #33
0
ファイル: text_plain.py プロジェクト: IvanLogvinov/soar
 def __init__(self, request, **kw):
     FormatterBase.__init__(self, request, **kw)
     self._in_code_area = 0
     self._in_code_line = 0
     self._code_area_state = [0, -1, -1, 0]
     self._lists = []
     self._url = None
     self._text = None  # XXX does not work with links in headings!!!!!
     self._text_stack = []
     self._skip_text = False
     self._wrap_skip_text = False
     self._textbuf = ''
     self._indent = 0
     self._listitem_on = []
     self._empty_line_count = 2
     self._paragraph_ended = False
     self._paragraph_skip_begin = True
コード例 #34
0
ファイル: application_xml.py プロジェクト: pombredanne/akara
 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 ""
コード例 #35
0
    def __init__(self, request, doctype="article", **kw):
        FormatterBase.__init__(self, request, **kw)
        self.request = request
        '''
        If the formatter is used by the Include macro, it will set
        is_included=True in which case we know we need to call startDocument
        and endDocument from startContent and endContent respectively, since
        the Include macro will not be calling them, and the formatter doesn't
        work properly unless they are called.
        '''
        if kw.has_key("is_included") and kw["is_included"]:
            self.include_kludge = True
        else:
            self.include_kludge = False

        self.doctype = doctype
        self.curdepth = 0
        self.cur = None
コード例 #36
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 ''
コード例 #37
0
    def __init__(self, request, doctype="article", **kw):
        FormatterBase.__init__(self, request, **kw)
        self.request = request

        '''
        If the formatter is used by the Include macro, it will set
        is_included=True in which case we know we need to call startDocument
        and endDocument from startContent and endContent respectively, since
        the Include macro will not be calling them, and the formatter doesn't
        work properly unless they are called.
        '''
        if kw.has_key("is_included") and kw["is_included"]:
            self.include_kludge = True
        else:
            self.include_kludge = False

        self.doctype = doctype
        self.curdepth = 0
        self.cur = None
コード例 #38
0
ファイル: TOC.py プロジェクト: 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 ''
コード例 #39
0
ファイル: text_plain.py プロジェクト: IvanLogvinov/soar
 def pagelink(self, on, pagename='', page=None, **kw):
     FormatterBase.pagelink(self, on, pagename, page, **kw)
     if on:
         if not self._textbuf or self._textbuf[-1] in ('\n', ' '):
             result = self.wrap(u'<')
         else:
             result = self.wrap(u' <')
         self.text_on(True)
         self.add_missing_space()
         return result
     else:
         linktext = self._text
         self.text_off()
         orig_pagename = pagename
         if pagename.find('/'):
             pagename = pagename.replace('/', '.')
         pagename += '.txt'
         if linktext == orig_pagename:
             return self.wrap(u'%s>' % pagename)
         else:
             return self.wrap(u'%s> [%s]' % (linktext, pagename))
コード例 #40
0
 def pagelink(self, on, pagename='', page=None, **kw):
     FormatterBase.pagelink(self, on, pagename, page, **kw)
     if on:
         if not self._textbuf or self._textbuf[-1] in ('\n', ' '):
             result = self.wrap(u'<')
         else:
             result = self.wrap(u' <')
         self.text_on(True)
         self.add_missing_space()
         return result
     else:
         linktext = self._text
         self.text_off()
         orig_pagename = pagename
         if pagename.find('/'):
             pagename = pagename.replace('/', '.')
         pagename += '.txt'
         if linktext == orig_pagename:
             return self.wrap(u'%s>' % pagename)
         else:
             return self.wrap(u'%s> [%s]' % (linktext, pagename))
コード例 #41
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 ''
コード例 #42
0
 def preformatted(self, on, **kw):
     FormatterBase.preformatted(self, on)
     self._elem(u'source', on)
     return ''
コード例 #43
0
ファイル: groups.py プロジェクト: execgit/gwiki-with-moin
    def __init__(self, request, **kw):
        FormatterBase.__init__(self, request, **kw)

        self.members = []
        self._bullet_list_level = 0
        self._catch_name = False
コード例 #44
0
ファイル: text_xml.py プロジェクト: aahlad/soar
 def pagelink(self, on, pagename='', page=None, **kw):
     FormatterBase.pagelink(self, on, pagename, page, **kw)
     if page is None:
         page = Page(self.request, pagename, formatter=self)
     return page.link_to(self.request, on=on, **kw)
コード例 #45
0
 def pagelink(self, on, pagename='', page=None, **kw):
     FormatterBase.pagelink(self, on, pagename, page, **kw)
     return self.interwikilink(on, 'Self', pagename, **kw)
コード例 #46
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""
コード例 #47
0
ファイル: TableOfContents.py プロジェクト: Glottotopia/aagd
 def __init__(self, request, **kw):
     FormatterBase.__init__(self, request, **kw)
     self.in_heading = False
     self.collected_headings = request._tocfm_collected_headings
コード例 #48
0
ファイル: TOC.py プロジェクト: 130s/roswiki
    def startContent(self, *args, **kw):
        res = FormatterBase.startContent(self, *args, **kw)
	self.collected_headings.append([1, self.request.uid_generator.include_id, None])
        return res
コード例 #49
0
 def startContent(self, *args, **kw):
     res = FormatterBase.startContent(self, *args, **kw)
     self.collected_headings.append(
         [1, self.request.uid_generator.include_id, None])
     return res
コード例 #50
0
 def paragraph(self, on, **kw):
     FormatterBase.paragraph(self, on)
     return self._set_tag('p', on)
コード例 #51
0
 def pagelink(self, on, pagename='', page=None, **kw):
     FormatterBase.pagelink(self, pagename, page, **kw)
     if not pagename and page is not None:
         pagename = page.page_name
     kw['pagename'] = pagename
     return self._set_tag('pagelink', on, **kw)
コード例 #52
0
 def endContent(self):
     res = FormatterBase.endContent(self)
     self.collected_headings.append(
         [1, self.request.uid_generator.include_id, None])
     return res
コード例 #53
0
 def paragraph(self, on, **kw):
     FormatterBase.paragraph(self, on)
     self._elem(u'p', on)
     return ''
コード例 #54
0
ファイル: application_xml.py プロジェクト: pombredanne/akara
 def preformatted(self, on, **kw):
     FormatterBase.preformatted(self, on)
     self._elem(u"source", on)
     return ""
コード例 #55
0
ファイル: application_xml.py プロジェクト: pombredanne/akara
 def paragraph(self, on, **kw):
     FormatterBase.paragraph(self, on)
     self._elem(u"p", on)
     return ""
コード例 #56
0
ファイル: TOC.py プロジェクト: 130s/roswiki
    def endContent(self):
        res = FormatterBase.endContent(self)
	self.collected_headings.append([1, self.request.uid_generator.include_id, None])
        return res
コード例 #57
0
 def pagelink(self, on, pagename='', page=None, **kw):
     FormatterBase.pagelink(self, on, pagename, page, **kw)
     return self.interwikilink(on, 'Self', pagename, **kw)