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 ''
def __init__(self, request, **kw): FormatterBase.__init__(self, request, **kw) self.members = [] self._bullet_list_level = 0 self._inside_link = False self._new_member = ''
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', {})]
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()
def paragraph(self, on, **kw): FormatterBase.paragraph(self, on) if on: self.paragraph_begin() else: self.paragraph_end() return ''
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 ""
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'
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""
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""
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
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!!!!!
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
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""
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()
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()
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()
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
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)
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)
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)
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>'
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 ''
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
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 ""
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
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 ''
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))
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 ''
def preformatted(self, on, **kw): FormatterBase.preformatted(self, on) self._elem(u'source', on) return ''
def __init__(self, request, **kw): FormatterBase.__init__(self, request, **kw) self.members = [] self._bullet_list_level = 0 self._catch_name = False
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)
def pagelink(self, on, pagename='', page=None, **kw): FormatterBase.pagelink(self, on, pagename, page, **kw) return self.interwikilink(on, 'Self', pagename, **kw)
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""
def __init__(self, request, **kw): FormatterBase.__init__(self, request, **kw) self.in_heading = False self.collected_headings = request._tocfm_collected_headings
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
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
def paragraph(self, on, **kw): FormatterBase.paragraph(self, on) return self._set_tag('p', on)
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)
def endContent(self): res = FormatterBase.endContent(self) self.collected_headings.append( [1, self.request.uid_generator.include_id, None]) return res
def paragraph(self, on, **kw): FormatterBase.paragraph(self, on) self._elem(u'p', on) return ''
def preformatted(self, on, **kw): FormatterBase.preformatted(self, on) self._elem(u"source", on) return ""
def paragraph(self, on, **kw): FormatterBase.paragraph(self, on) self._elem(u"p", on) return ""
def endContent(self): res = FormatterBase.endContent(self) self.collected_headings.append([1, self.request.uid_generator.include_id, None]) return res