From ba7dcc320c49806c60204599921ef31bc0ed7ad5 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 25 Jan 2013 17:02:35 -0500 Subject: [PATCH] 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) --- zephyr/lib/bugdown/fenced_code.py | 27 +++------------------------ zephyr/tests.py | 4 ++-- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/zephyr/lib/bugdown/fenced_code.py b/zephyr/lib/bugdown/fenced_code.py index 584facd0e6..8c24cc103d 100644 --- a/zephyr/lib/bugdown/fenced_code.py +++ b/zephyr/lib/bugdown/fenced_code.py @@ -49,18 +49,6 @@ Language tags:
# Some python code
     
-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']) -
# Arbitrary code
-    ~~~~~ # these tildes will not close the block
-    
- Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). Project website: @@ -80,13 +68,11 @@ import markdown from zephyr.lib.bugdown.codehilite import CodeHilite, CodeHiliteExtension # Global vars -FENCE_RE = re.compile(r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P[a-zA-Z0-9_+-]*)\}?)', re.MULTILINE|re.DOTALL) +FENCE_RE = re.compile(r'(?P^(?:~{3,}))[ ]*(\{?\.?(?P[a-zA-Z0-9_+-]*)\}?)', re.MULTILINE|re.DOTALL) FENCED_BLOCK_RE = re.compile( \ - r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P.*?)(?<=\n)(?P=fence)[ ]*$', + r'(?P^(?:~{3,}))[ ]*(\{?\.?(?P[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P.*?)(?<=\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`+).+?(?P=fence)') CODE_WRAP = '
%s
' 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 diff --git a/zephyr/tests.py b/zephyr/tests.py index 79075cec6a..ed88e847f3 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -1131,7 +1131,7 @@ speak(self 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 = \