Browse Source

Two-step parser implemented

Ralfp 12 years ago
parent
commit
92b2c610e7

+ 9 - 4
misago/markdown/factory.py

@@ -64,7 +64,7 @@ def signature_markdown(acl, text):
     del md.parser.blockprocessors['hr']
     del md.parser.blockprocessors['hr']
     del md.parser.blockprocessors['olist']
     del md.parser.blockprocessors['olist']
     del md.parser.blockprocessors['ulist']
     del md.parser.blockprocessors['ulist']
-
+    
     return md.convert(text)
     return md.convert(text)
 
 
 
 
@@ -84,15 +84,20 @@ def post_markdown(request, text):
         ext = attr()
         ext = attr()
         ext.extendMarkdown(md)
         ext.extendMarkdown(md)
     text = md.convert(text)
     text = md.convert(text)
+    return tidy_markdown(md, text)
+
 
 
-    # Final cleanups
+def tidy_markdown(md, text):
     text = text.replace('<p><h3><quotetitle>', '<h3><quotetitle>')
     text = text.replace('<p><h3><quotetitle>', '<h3><quotetitle>')
     text = text.replace('</quotetitle></h3></p>', '</quotetitle></h3>')
     text = text.replace('</quotetitle></h3></p>', '</quotetitle></h3>')
     text = text.replace('</quotetitle></h3><br>\r\n', '</quotetitle></h3>\r\n<p>')
     text = text.replace('</quotetitle></h3><br>\r\n', '</quotetitle></h3>\r\n<p>')
     text = text.replace('\r\n<p></p>', '')
     text = text.replace('\r\n<p></p>', '')
+    return md, text
+
+
+def finalize_markdown(text):
     def trans_quotetitle(match):
     def trans_quotetitle(match):
         return _("Posted by %(user)s") % {'user': match.group('content')}
         return _("Posted by %(user)s") % {'user': match.group('content')}
     text = re.sub(r'<quotetitle>(?P<content>.+)</quotetitle>', trans_quotetitle, text)
     text = re.sub(r'<quotetitle>(?P<content>.+)</quotetitle>', trans_quotetitle, text)
     text = re.sub(r'<quotesingletitle>', _("Quote"), text)
     text = re.sub(r'<quotesingletitle>', _("Quote"), text)
-
-    return md, text
+    return text

+ 6 - 0
misago/template/templatetags/django2jinja.py

@@ -58,6 +58,12 @@ def short_markdown(value, length=300):
     return value
     return value
 
 
 
 
+@register.filter(name='markdown_final')
+def finalize_markdown(value):
+    from misago.markdown.factory import finalize_markdown
+    return finalize_markdown(value)
+
+
 """
 """
 Date and time filters
 Date and time filters
 """
 """

+ 1 - 1
templates/sora/threads/posting.html

@@ -35,7 +35,7 @@
 {% if preview %}
 {% if preview %}
 <div class="well" style="margin: 0px; margin-bottom: 32px; padding: 12px;">
 <div class="well" style="margin: 0px; margin-bottom: 32px; padding: 12px;">
   <div class="markdown">
   <div class="markdown">
-    {{ preview|safe }}
+    {{ preview|markdown_final|safe }}
   </div>
   </div>
 </div>
 </div>
 <hr>
 <hr>

+ 2 - 2
templates/sora/threads/thread.html

@@ -138,7 +138,7 @@
     </div>
     </div>
     <div class="post-content">
     <div class="post-content">
       <div class="markdown">
       <div class="markdown">
-        {{ post.post_preparsed|safe }}
+        {{ post.post_preparsed|markdown_final|safe }}
       </div>
       </div>
       {% if post.user.signature %}
       {% if post.user.signature %}
       <div class="post-foot">
       <div class="post-foot">
@@ -146,7 +146,7 @@
         {% if post.user.signature %}
         {% if post.user.signature %}
         <div class="signature">
         <div class="signature">
           <div class="markdown">
           <div class="markdown">
-            {{ post.user.signature_preparsed|safe }}
+            {{ post.user.signature_preparsed|markdown_final|safe }}
           </div>
           </div>
         </div>
         </div>
         {% endif %}
         {% endif %}

+ 1 - 1
templates/sora/usercp/signature.html

@@ -13,7 +13,7 @@
 {% if user.signature_preparsed %}
 {% if user.signature_preparsed %}
 <div class="well" style="margin: 0px; margin-bottom: 32px; padding: 12px;">
 <div class="well" style="margin: 0px; margin-bottom: 32px; padding: 12px;">
   <div class="markdown">
   <div class="markdown">
-    {{ user.signature_preparsed|safe }}
+    {{ user.signature_preparsed|markdown_final|safe }}
   </div>
   </div>
 </div>
 </div>
 {% endif %}
 {% endif %}