comparison MoinMoin/formatter/text_docbook.py @ 3187:4232b56627c7

Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
author Mikko Virkkil? <mvirkkil@cc.hut.fi>
date Wed, 05 Mar 2008 00:46:53 +0100
parents a36faa9f9d9f
children fd905ed64dff
comparison
equal deleted inserted replaced
3186:a36faa9f9d9f 3187:4232b56627c7
31 31
32 #this list is extended as the page is parsed. Could be optimized by adding them here? 32 #this list is extended as the page is parsed. Could be optimized by adding them here?
33 section_should_break = ['abstract', 'para', 'emphasis'] 33 section_should_break = ['abstract', 'para', 'emphasis']
34 34
35 blacklisted_macros = ('TableOfContents', 'ShowSmileys') 35 blacklisted_macros = ('TableOfContents', 'ShowSmileys')
36
37 # If the current node is one of the following and we are about the emit
38 # text, the text should be wrapped in a paragraph
39 wrap_text_in_para = ('listitem', 'glossdef', 'article', 'chapter', 'tip', 'warning', 'note', 'caution', 'important')
36 40
37 def __init__(self, request, doctype="article", **kw): 41 def __init__(self, request, doctype="article", **kw):
38 FormatterBase.__init__(self, request, **kw) 42 FormatterBase.__init__(self, request, **kw)
39 self.request = request 43 self.request = request
40 44
101 from xml.dom.ext import Node 105 from xml.dom.ext import Node
102 if self.cur.lastChild.nodeType == Node.CDATA_SECTION_NODE: 106 if self.cur.lastChild.nodeType == Node.CDATA_SECTION_NODE:
103 self.cur.lastChild.nodeValue = self.cur.lastChild.nodeValue + srcText 107 self.cur.lastChild.nodeValue = self.cur.lastChild.nodeValue + srcText
104 else: 108 else:
105 self.cur.appendChild(self.doc.createCDATASection(srcText)) 109 self.cur.appendChild(self.doc.createCDATASection(srcText))
110 elif self.cur.nodeName in self.wrap_text_in_para:
111 """
112 If we already wrapped one text item in a para, we should add to that para
113 and not create a new one. Another question is if we should add a space?
114 """
115 if self.cur.lastChild is not None and self.cur.lastChild.nodeName == 'para':
116 self.cur.lastChild.appendChild(self.doc.createTextNode(srcText))
117 else:
118 self.paragraph(1)
119 self.text(text)
120 self.paragraph(0)
106 else: 121 else:
107 self.cur.appendChild(self.doc.createTextNode(srcText)) 122 self.cur.appendChild(self.doc.createTextNode(srcText))
108 return "" 123 return ""
109 124
110 def heading(self, on, depth, **kw): 125 def heading(self, on, depth, **kw):