mirror of https://github.com/zulip/zulip.git
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)
This commit is contained in:
parent
9f499fd364
commit
3ca3be297e
|
@ -212,14 +212,16 @@ class Message(models.Model):
|
|||
# end parentheses, or end brackets (which would confuse Markdown).
|
||||
link_regex = re.compile(r'(\s|\A)(?P<url>https?://[^\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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue