aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/extensions/codehilite.py3
-rw-r--r--markdown/extensions/fenced_code.py3
-rw-r--r--tests/test_extensions.py34
3 files changed, 23 insertions, 17 deletions
diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py
index 7f20efe..9f99518 100644
--- a/markdown/extensions/codehilite.py
+++ b/markdown/extensions/codehilite.py
@@ -168,7 +168,8 @@ class CodeHilite(object):
(?P<path>(?:/\w+)*[/ ])? # Zero or 1 path
(?P<lang>[\w+-]*) # The language
\s* # Arbitrary whitespace
- (hl_lines="(?P<hl_lines>.*?)")? # Maybe highlight lines
+ # Optional highlight lines, single- or double-quote-delimited
+ (hl_lines=(?P<quot>"|')(?P<hl_lines>.*?)(?P=quot))?
''', re.VERBOSE)
# search first line for shebang
m = c.search(fl)
diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py
index 6ee6759..39c6540 100644
--- a/markdown/extensions/fenced_code.py
+++ b/markdown/extensions/fenced_code.py
@@ -110,7 +110,8 @@ class FencedBlockPreprocessor(Preprocessor):
FENCED_BLOCK_RE = re.compile(r'''
(?P<fence>^(?:~{3,}|`{3,}))[ ]* # Opening ``` or ~~~
(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*))?[ ]* # Optional {, and lang
-(hl_lines="(?P<hl_lines>.*?)")?[ ]* # Optional highlight lines
+# Optional highlight lines, single- or double-quote-delimited
+(hl_lines=(?P<quot>"|')(?P<hl_lines>.*?)(?P=quot))?[ ]*
}?[ ]*\n # Optional closing }
(?P<code>.*?)(?<=\n)
(?P=fence)[ ]*$''', re.MULTILINE | re.DOTALL | re.VERBOSE)
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index ea4adad..d33feec 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -127,21 +127,25 @@ class TestCodeHilite(unittest.TestCase):
'</code></pre>')
def testHighlightLinesWithColon(self):
- text = '\t:::Python hl_lines="2"\n\t#line 1\n\t#line 2\n\t#line 3'
+ # Test with hl_lines delimited by single or double quotes.
+ text0 = '\t:::Python hl_lines="2"\n\t#line 1\n\t#line 2\n\t#line 3'
+ text1 = "\t:::Python hl_lines='2'\n\t#line 1\n\t#line 2\n\t#line 3"
- md = markdown.Markdown(extensions=['codehilite'])
- if self.has_pygments:
- self.assertEqual(md.convert(text),
- '<div class="codehilite"><pre>'
- '<span class="c">#line 1</span>\n'
- '<span class="hll"><span class="c">#line 2</span>\n</span>'
- '<span class="c">#line 3</span>\n'
- '</pre></div>')
- else:
- self.assertEqual(md.convert(text),
- '<pre class="codehilite"><code class="language-python">#line 1\n'
- '#line 2\n'
- '#line 3</code></pre>')
+ for text in (text0, text1):
+ md = markdown.Markdown(extensions=['codehilite'])
+ if self.has_pygments:
+ self.assertEqual(md.convert(text),
+ '<div class="codehilite"><pre>'
+ '<span class="c">#line 1</span>\n'
+ '<span class="hll"><span class="c">#line 2</span>\n</span>'
+ '<span class="c">#line 3</span>\n'
+ '</pre></div>')
+ else:
+ self.assertEqual(md.convert(text),
+ '<pre class="codehilite">'
+ '<code class="language-python">#line 1\n'
+ '#line 2\n'
+ '#line 3</code></pre>')
class TestFencedCode(unittest.TestCase):
""" Test fenced_code extension. """
@@ -248,7 +252,7 @@ line 3
#line 3
```'''
text1 = '''
-~~~{.python hl_lines="1 3"}
+~~~{.python hl_lines='1 3'}
#line 1
#line 2
#line 3