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 preformatted(self, on): 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 paragraph(self, on, **kw): FormatterBase.paragraph(self, on) if on: para = self.doc.createElement("para") self.cur.appendChild(para) self.cur = para else: self.cur = self.cur.parentNode return ""
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 paragraph(self, on): if self._terse: return '' FormatterBase.paragraph(self, on) if self._in_li: self._in_li = self._in_li + 1 tag = 'p' if on: return self.open(tag) return self.close(tag)
def __init__(self, request, **kw): '''We should use this for creating the doc''' FormatterBase.__init__(self, request, **kw) self.doc = dom.createDocument(None, "article", dom.createDocumentType( "article", "-//OASIS//DTD DocBook V4.4//EN", "http://www.docbook.org/xml/4.4/docbookx.dtd")) self.root = self.doc.documentElement self.curdepth = 0 self.outputFormatter = DocBookOutputFormatter(self.doc) self.exchangeKeys = [] self.exchangeValues = []
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 macro(self, macro_obj, name, args): if name == "TableOfContents": # Table of content can be inserted in docbook transformation return u"" # output of all macros is added as the text node # At the begining text mode contain some string which is later # exchange for real value. There is problem that data inserted # as text mode are encoded to xml, e.g. < is encoded in the output as < text = FormatterBase.macro(self, macro_obj, name, args) if len(text) > 0: # prepare identificator sKey = "EXCHANGESTRINGMACRO-" + str(len(self.exchangeKeys)) + "-EXCHANGESTRINGMACRO" self.exchangeKeys.append(sKey) self.exchangeValues.append(text) # append data to lists self.text(sKey) return u""
def paragraph(self, on): FormatterBase.paragraph(self, on) if self._did_para: on = 0 return [u'\n', u''][not on]
def paragraph(self, on, **kw): FormatterBase.paragraph(self, on) if self.in_table or self.list_depth: return '' return ['', '\n\n'][not on]
def preformatted(self, on, **kw): FormatterBase.preformatted(self, on) result = '' if self.in_p: result = self.paragraph(0) return result + ['<file>', '</file>\n'][not on]
def pagelink(self, on, pagename='', page=None, **kw): FormatterBase.pagelink(self, on, pagename, page, **kw) return self.interwikilink(on, 'Self', pagename) # FIXME
def paragraph(self, on, **kw): FormatterBase.paragraph(self, on) return ['<p>', '</p>\n'][not on]
def preformatted(self, on, **kw): FormatterBase.preformatted(self, on) result = '' if self.in_p: result = self.paragraph(0) return result + ['<source><![CDATA[', ']]></source>'][not on]
def paragraph(self, on): FormatterBase.paragraph(self, on) return self._set_tag('p', on)
def pagelink(self, on, pagename='', page=None, **kw): FormatterBase.pagelink(self, on, pagename, page, **kw) return self.null()
def preformatted(self, on): FormatterBase.preformatted(self, on) tag = 'pre' if on: return self.open(tag, newline=1) return self.close(tag)