]> git.openstreetmap.org Git - osqa.git/commitdiff
OSQA-593, resolves an issue with backslashes \ during markdown processing. Thanks...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 2 Jul 2011 18:14:54 +0000 (18:14 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 2 Jul 2011 18:14:54 +0000 (18:14 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1097 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/comment.py
forum/models/node.py

index b62e7b5e97e6b399498cfa40049129d63ba2bb3f..32fdf5dfe3596c91858e424b262548ac635023b2 100644 (file)
@@ -17,7 +17,8 @@ class Comment(Node):
     @property
     def comment(self):
         if settings.FORM_ALLOW_MARKDOWN_IN_COMMENTS:
-            return self.as_markdown('limitedsyntax')
+           # Avoid doing double replacement of backslashes
+            return self._as_markdown_raw(self.body,'limitedsyntax')
         else:
             return self.body
 
index 72ef0c0737c12efa2a1b04abaa4fc18dd24660cc..6d51793517b4db408c835145a31ce53028962b97 100644 (file)
@@ -29,7 +29,7 @@ class NodeContent(models.Model):
         return auto_user_link(self, self._as_markdown(content, *['auto_linker']))
 
     @classmethod
-    def _as_markdown(cls, content, *extensions):
+    def _as_markdown_raw(cls, content, *extensions):
         try:
             return mark_safe(sanitize_html(markdown.markdown(content, extensions=extensions)))
         except Exception, e:
@@ -38,6 +38,11 @@ class NodeContent(models.Model):
                 str(e), cls.__name__, str(e), traceback.format_exc()))
             return ''
 
+    # Replace \ with \\ to preserve backslashes during markdown processing
+    @classmethod
+    def _as_markdown(cls, content, *extensions):
+       return cls._as_markdown_raw(content.replace('\\','\\\\'), *extensions)
+
     def as_markdown(self, *extensions):
         return self._as_markdown(self.body, *extensions)