From 3ca3be297e98062033c4a77b06dc080d8450514b Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Thu, 11 Oct 2012 15:45:36 -0400 Subject: [PATCH] Disable Markdown heading markers by padding with spaces Because # will display literally now. This still fails in some cases, such as > # foo (imported from commit 40654a4f1dac940ba131f2a104440b6ecb7eafd1) --- zephyr/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zephyr/models.py b/zephyr/models.py index a8df918ebd..c629a7cb90 100644 --- a/zephyr/models.py +++ b/zephyr/models.py @@ -212,14 +212,16 @@ class Message(models.Model): # end parentheses, or end brackets (which would confuse Markdown). link_regex = re.compile(r'(\s|\A)(?Phttps?://[^\s\])]+)') + # Pad heading markers to make Markdown ignore them + # FIXME: Write a real extension for the markdown library + heading_regex = re.compile(r'^([#-=])', flags=re.MULTILINE) + def html_content(self): def linkify(match): url = match.group('url') return ' [%s](%s) ' % (url, url) - # Escape the # (pound sign) to avoid markdown making them into - # (giant) headers. - content = self.content.replace("#", "#") + content = self.heading_regex.sub(r' \1', self.content) with_links = self.link_regex.sub(linkify, content) return md_engine.convert(with_links)