changeset 2963:4f2ce9dc42e8

Creole parser: Work around inconsistent formetter.parser behavior.
author Radomir Dopieralski <moindev@sheep.art.pl>
date Mon, 17 Dec 2007 17:37:49 +0100
parents 5175bd01d5d8
children 49b9e807a51d
files MoinMoin/parser/_creole.py MoinMoin/parser/text_creole.py
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/_creole.py	Mon Dec 17 09:59:39 2007 +0100
+++ b/MoinMoin/parser/_creole.py	Mon Dec 17 17:37:49 2007 +0100
@@ -311,6 +311,7 @@
 
     def _line_repl(self, groups):
         self.cur = self._upto(self.cur, ('document', 'section', 'blockquote'))
+        self.text = None
 
     def _code_repl(self, groups):
         DocNode('code', self.cur, groups.get('code_text', u'').strip())
--- a/MoinMoin/parser/text_creole.py	Mon Dec 17 09:59:39 2007 +0100
+++ b/MoinMoin/parser/text_creole.py	Mon Dec 17 17:37:49 2007 +0100
@@ -380,11 +380,7 @@
     def macro_emit(self, node):
         macro_name = node.content
         args = node.args
-        try:
-            return self.formatter.macro(self.macro, macro_name, args)
-        except Exception, err:
-            raise
-            return self.formatter.text(self.request.getText('macro error') + ' ' + str(err))
+        return self.formatter.macro(self.macro, macro_name, args)
 
 # Not used
 #    def section_emit(self, node):
@@ -409,8 +405,21 @@
     def preformatted_emit(self, node):
         parser_name = getattr(node, 'sect', '')
         if parser_name:
+            # The formatter.parser will *sometimes* just return the result
+            # and *sometimes* try to write it directly. We need to take both
+            # cases into account!
+            lines = node.content.split(u'\n')
+            buf = StringIO.StringIO()
             try:
-                return self.formatter.parser(parser_name, node.content.split('\n'))
+                try:
+                    self.request.redirect(buf)
+                    ret = self.formatter.parser(parser_name, lines)
+                finally:
+                    self.request.redirect()
+                buf.flush()
+                writ = buf.getvalue()
+                buf.close()
+                return ret+writ
             except wikiutil.PluginMissingError:
                 pass
         return ''.join([