changeset 1748:dc0db3897437

StringIO operation moved from FootNote to wikiutil.executeText
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 20 Jan 2007 22:29:31 +0100
parents b7e0a36a1219
children 3567062fc66f
files MoinMoin/macro/FootNote.py MoinMoin/wikiutil.py
diffstat 2 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/FootNote.py	Thu Jan 18 10:10:02 2007 +0100
+++ b/MoinMoin/macro/FootNote.py	Sat Jan 20 22:29:31 2007 +0100
@@ -6,11 +6,12 @@
     text cannot contain wiki markup.
 
     @copyright: 2002 by Jürgen Hermann <jh@web.de>
+                2007 Reimar Bauer
     @license: GNU GPL, see COPYING for details.
 """
 
-import sha, StringIO
-from MoinMoin import config
+import sha
+from MoinMoin import config, wikiutil
 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
 
 Dependencies = ["time"] # footnote macro cannot be cached
@@ -58,16 +59,7 @@
             result.append(formatter.text(str(idx + 1)))
             result.append(formatter.anchorlink(0))
             result.append(formatter.text(" "))
-
-            out = StringIO.StringIO()
-            request.redirect(out)
-            parser = WikiParser(request.footnotes[idx][0], request,
-                               line_anchors=False)
-            parser.format(formatter)
-            result.append(out.getvalue())
-            request.redirect()
-            del out
-            # [1] paragraph is automagically closed by wiki parser! 
+            result.append(wikiutil.executeText(request, WikiParser, request.footnotes[idx][0]))
             result.append(formatter.listitem(0))
 
         result.append(formatter.bullet_list(0))
--- a/MoinMoin/wikiutil.py	Thu Jan 18 10:10:02 2007 +0100
+++ b/MoinMoin/wikiutil.py	Sat Jan 20 22:29:31 2007 +0100
@@ -3,6 +3,7 @@
     MoinMoin - Wiki Utility Functions
 
     @copyright: 2000 - 2004 by Jürgen Hermann <jh@web.de>
+    @copyright: 2007 Reimar Bauer
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -1643,3 +1644,15 @@
     ourticket = createTicket(request, timestamp_str)
     return ticket == ourticket
 
+def executeText(request, Parser, text, line_anchors=False):
+    '''render text with Parser execute each page element'''
+    import StringIO
+    out = StringIO.StringIO()
+    request.redirect(out)
+    wikiizer = Parser(text, request, line_anchors=line_anchors)
+    wikiizer.format(request.formatter)
+    result = out.getvalue()
+    request.redirect()
+    del out
+    return result
+