changeset 754:86ca6b17aba9

Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
author Matthew Gilbert <gilbert@voxmea.net>
date Thu, 08 Jun 2006 11:37:36 +0200
parents d48400378d4c
children 0ba3bd233965
files MoinMoin/parser/text_rst.py
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_rst.py	Thu Jun 08 09:06:11 2006 +0200
+++ b/MoinMoin/parser/text_rst.py	Thu Jun 08 11:37:36 2006 +0200
@@ -306,13 +306,16 @@
         return html4css1.HTMLTranslator.astext(self)
 
     def fixup_wiki_formatting(self, text):
-        replacement = {'<p>': '', '</p>': '', '\n': '', '> ': '>'}
+        replacement = {'\n': '', '> ': '>'}
         for src, dst in replacement.items():
             text = text.replace(src, dst)
-        # Everything seems to have a space ending the text block. We want to
-        # get rid of this
-        if text and text[-1] == ' ':
-            text = text[:-1]
+        # Fixup extraneous markup
+        # Removes any empty span tags
+        text = re.sub(r'\s*<\s*span.*?>\s*<\s*/\s*span\s*>', '', text)
+        # Removes the first paragraph tag
+        text = re.sub(r'^\s*<\s*p[^>]*?>', '', text)
+        # Removes the ending paragraph close tag and any remaining whitespace
+        text = re.sub(r'<\s*/\s*p\s*>\s*$', '', text)
         return text
 
     def visit_reference(self, node):
@@ -339,8 +342,7 @@
                     (prefix == 'drawing') or
                     (prefix == 'inline')):
                 self.process_wiki_text(refuri)
-                # Don't call fixup_wiki_formatting because who knows what
-                # MoinMoin is inserting. (exits through add_wiki_markup)
+                self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
                 self.add_wiki_markup()
 
             # From here down, all links are handled by docutils (except 
@@ -352,6 +354,7 @@
                     # Attachment doesn't exist, give to MoinMoin to insert
                     # upload text.
                     self.process_wiki_text(refuri)
+                    self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
                     self.add_wiki_markup()
                 # Attachment exists, just get a link to it.
                 node['refuri'] = AttachFile.getAttachUrl(self.request.page.page_name,