From fac2bf37e4b1032efe670d5f63d126ff9faa6f88 Mon Sep 17 00:00:00 2001 From: jordan Date: Sat, 2 Jul 2011 18:14:54 +0000 Subject: [PATCH] OSQA-593, resolves an issue with backslashes \ during markdown processing. Thanks to @kristi for the provided patch. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1097 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/comment.py | 3 ++- forum/models/node.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/forum/models/comment.py b/forum/models/comment.py index b62e7b5..32fdf5d 100644 --- a/forum/models/comment.py +++ b/forum/models/comment.py @@ -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 diff --git a/forum/models/node.py b/forum/models/node.py index 72ef0c0..6d51793 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -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) -- 2.45.1