mirror of https://github.com/zulip/zulip.git
Remove ``` support from code fence
Supporting ``` as a code fence marker complicates the auto-fence closing, and as per a discussion with Keegan on code-review@, it is not worth the extra complexity. (imported from commit 405afb95c4295a02f4677181456caf9d49913ac4)
This commit is contained in:
parent
187e8cfa88
commit
ba7dcc320c
|
@ -49,18 +49,6 @@ Language tags:
|
||||||
<pre><code class="python"># Some python code
|
<pre><code class="python"># Some python code
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
Optionally backticks instead of tildes as per how github's code block markdown is identified:
|
|
||||||
|
|
||||||
>>> text = '''
|
|
||||||
... `````
|
|
||||||
... # Arbitrary code
|
|
||||||
... ~~~~~ # these tildes will not close the block
|
|
||||||
... `````'''
|
|
||||||
>>> print markdown.markdown(text, extensions=['fenced_code'])
|
|
||||||
<pre><code># Arbitrary code
|
|
||||||
~~~~~ # these tildes will not close the block
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/).
|
Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/).
|
||||||
|
|
||||||
Project website: <http://packages.python.org/Markdown/extensions/fenced_code_blocks.html>
|
Project website: <http://packages.python.org/Markdown/extensions/fenced_code_blocks.html>
|
||||||
|
@ -80,13 +68,11 @@ import markdown
|
||||||
from zephyr.lib.bugdown.codehilite import CodeHilite, CodeHiliteExtension
|
from zephyr.lib.bugdown.codehilite import CodeHilite, CodeHiliteExtension
|
||||||
|
|
||||||
# Global vars
|
# Global vars
|
||||||
FENCE_RE = re.compile(r'(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*)\}?)', re.MULTILINE|re.DOTALL)
|
FENCE_RE = re.compile(r'(?P<fence>^(?:~{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*)\}?)', re.MULTILINE|re.DOTALL)
|
||||||
FENCED_BLOCK_RE = re.compile( \
|
FENCED_BLOCK_RE = re.compile( \
|
||||||
r'(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P<code>.*?)(?<=\n)(?P=fence)[ ]*$',
|
r'(?P<fence>^(?:~{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P<code>.*?)(?<=\n)(?P=fence)[ ]*$',
|
||||||
re.MULTILINE|re.DOTALL
|
re.MULTILINE|re.DOTALL
|
||||||
)
|
)
|
||||||
# Match an inline code expression in markdown: `x=1` or ``def foo(self): bar`` for example
|
|
||||||
INLINE_CODE_RE = re.compile(r'(?P<fence>`+).+?(?P=fence)')
|
|
||||||
CODE_WRAP = '<pre><code%s>%s</code></pre>'
|
CODE_WRAP = '<pre><code%s>%s</code></pre>'
|
||||||
LANG_TAG = ' class="%s"'
|
LANG_TAG = ' class="%s"'
|
||||||
|
|
||||||
|
@ -125,14 +111,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
|
||||||
while 1:
|
while 1:
|
||||||
m = FENCED_BLOCK_RE.search(text)
|
m = FENCED_BLOCK_RE.search(text)
|
||||||
if not m:
|
if not m:
|
||||||
# If there is an inline code block, skip past it
|
fence = FENCE_RE.search(text)
|
||||||
start = 0
|
|
||||||
inline = INLINE_CODE_RE.search(text, start)
|
|
||||||
while inline:
|
|
||||||
start = inline.end()
|
|
||||||
inline = INLINE_CODE_RE.search(text, start)
|
|
||||||
|
|
||||||
fence = FENCE_RE.search(text, start)
|
|
||||||
if fence:
|
if fence:
|
||||||
# If we found a starting fence but no ending fence,
|
# If we found a starting fence but no ending fence,
|
||||||
# then we add a closing fence before the two newlines that
|
# then we add a closing fence before the two newlines that
|
||||||
|
|
|
@ -1131,7 +1131,7 @@ speak</span><span class="p">(</span><span class="bp">self</span><span class="p">
|
||||||
def test_codeblock_multiline(self):
|
def test_codeblock_multiline(self):
|
||||||
fenced_code = \
|
fenced_code = \
|
||||||
"""Hamlet once said
|
"""Hamlet once said
|
||||||
````
|
~~~~
|
||||||
def func():
|
def func():
|
||||||
x = 1
|
x = 1
|
||||||
|
|
||||||
|
@ -1139,7 +1139,7 @@ def func():
|
||||||
y = 2
|
y = 2
|
||||||
|
|
||||||
z = 3
|
z = 3
|
||||||
````
|
~~~~
|
||||||
And all was good."""
|
And all was good."""
|
||||||
|
|
||||||
expected_convert = \
|
expected_convert = \
|
||||||
|
|
Loading…
Reference in New Issue