changeset 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
files MoinMoin/formatter/text_docbook.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_docbook.py	Wed Mar 05 00:39:19 2008 +0100
+++ b/MoinMoin/formatter/text_docbook.py	Wed Mar 05 00:46:53 2008 +0100
@@ -34,6 +34,10 @@
  
     blacklisted_macros = ('TableOfContents', 'ShowSmileys')
 
+    # If the current node is one of the following and we are about the emit
+    # text, the text should be wrapped in a paragraph
+    wrap_text_in_para = ('listitem', 'glossdef', 'article', 'chapter', 'tip', 'warning', 'note', 'caution', 'important')
+
     def __init__(self, request, doctype="article", **kw):
         FormatterBase.__init__(self, request, **kw)
         self.request = request
@@ -103,6 +107,17 @@
                     self.cur.lastChild.nodeValue = self.cur.lastChild.nodeValue + srcText
             else:
                 self.cur.appendChild(self.doc.createCDATASection(srcText))
+        elif self.cur.nodeName in self.wrap_text_in_para:
+            """
+            If we already wrapped one text item in a para, we should add to that para
+            and not create a new one. Another question is if we should add a space?
+            """
+            if self.cur.lastChild is not None and self.cur.lastChild.nodeName == 'para':
+                self.cur.lastChild.appendChild(self.doc.createTextNode(srcText))
+            else:
+                self.paragraph(1)
+                self.text(text)
+                self.paragraph(0)
         else:
             self.cur.appendChild(self.doc.createTextNode(srcText))
         return ""