changeset 2868:7b0b85f96fa2

Creole parser: using formatter.linebreak() for inserting line breaks
author Radomir Dopieralski <moindev@sheep.art.pl>
date Mon, 24 Sep 2007 00:59:26 +0200
parents 69234509b7cf
children 592c045c81c5
files MoinMoin/parser/text_creole.py
diffstat 1 files changed, 11 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_creole.py	Mon Sep 24 00:43:54 2007 +0200
+++ b/MoinMoin/parser/text_creole.py	Mon Sep 24 00:59:26 2007 +0200
@@ -439,6 +439,8 @@
         re.sub(self.block_re, self._replace, raw)
 
     def parse(self):
+        """Parse the text given as self.raw and return DOM tree."""
+
         self.parse_block(self.raw)
         return self.root
 
@@ -456,7 +458,7 @@
         self.parent = parent
         self.kind = kind
         self.content = content
-        if not self.parent is None:
+        if self.parent is not None:
             self.parent.children.append(self)
 
 
@@ -747,9 +749,7 @@
 #        ])
 
     def break_emit(self, node):
-        return ''.join([
-            self.formatter.rawHTML('<br>'),
-        ])
+        return self.formatter.linebreak(preformatted=0)
 
 # Not used
 #    def blockquote_emit(self, node):
@@ -774,6 +774,8 @@
         ])
 
     def default_emit(self, node):
+        """Fallback function for emitting unknown nodes."""
+
         return ''.join([
             self.formatter.preformatted(1),
             self.formatter.text('<%s>\n' % node.kind),
@@ -783,13 +785,18 @@
 
     def emit_children(self, node):
         """Emit all the children of a node."""
+
         return ''.join([self.emit_node(child) for child in node.children])
 
     def emit_node(self, node):
+        """Emit a single node."""
+
         emit = getattr(self, '%s_emit' % node.kind, self.default_emit)
         return emit(node)
 
     def emit(self):
+        """Emit the document represented by self.root DOM tree."""
+
         # Try to disable 'smart' formatting if possible
         magic_save = getattr(self.formatter, 'no_magic', False)
         self.formatter.no_magic = True
@@ -799,17 +806,3 @@
         # restore 'smart' formatting if it was set
         self.formatter.no_magic = magic_save
         return output
-
-
-# Private helpers ------------------------------------------------------------
-
-    def setParser(self, name):
-        """ Set parser to parser named 'name' """
-        # XXX this is done by the formatter as well
-
-        try:
-            self.parser = wikiutil.searchAndImportPlugin(self.request.cfg,
-                "parser", name)
-        except wikiutil.PluginMissingError:
-            self.parser = None
-