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:
Leo Franchi 2013-01-25 17:02:35 -05:00
parent 187e8cfa88
commit ba7dcc320c
2 changed files with 5 additions and 26 deletions

View File

@ -49,18 +49,6 @@ Language tags:
<pre><code class="python"># Some python code
</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/).
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
# 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( \
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
)
# 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>'
LANG_TAG = ' class="%s"'
@ -125,14 +111,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
while 1:
m = FENCED_BLOCK_RE.search(text)
if not m:
# If there is an inline code block, skip past it
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)
fence = FENCE_RE.search(text)
if fence:
# If we found a starting fence but no ending fence,
# then we add a closing fence before the two newlines that

View File

@ -1131,7 +1131,7 @@ speak</span><span class="p">(</span><span class="bp">self</span><span class="p">
def test_codeblock_multiline(self):
fenced_code = \
"""Hamlet once said
````
~~~~
def func():
x = 1
@ -1139,7 +1139,7 @@ def func():
y = 2
z = 3
````
~~~~
And all was good."""
expected_convert = \