From 1fca2a3b2d65bc013e22f7c00c503ea7cea7f72d Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Tue, 7 Jan 2014 12:55:58 -0500 Subject: Allow single as well as double quotes for hl_lines. --- markdown/extensions/codehilite.py | 3 ++- markdown/extensions/fenced_code.py | 3 ++- tests/test_extensions.py | 34 +++++++++++++++++++--------------- 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(?:/\w+)*[/ ])? # Zero or 1 path (?P[\w+-]*) # The language \s* # Arbitrary whitespace - (hl_lines="(?P.*?)")? # Maybe highlight lines + # Optional highlight lines, single- or double-quote-delimited + (hl_lines=(?P"|')(?P.*?)(?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^(?:~{3,}|`{3,}))[ ]* # Opening ``` or ~~~ (\{?\.?(?P[a-zA-Z0-9_+-]*))?[ ]* # Optional {, and lang -(hl_lines="(?P.*?)")?[ ]* # Optional highlight lines +# Optional highlight lines, single- or double-quote-delimited +(hl_lines=(?P"|')(?P.*?)(?P=quot))?[ ]* }?[ ]*\n # Optional closing } (?P.*?)(?<=\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): '') 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), - '
'
-                '#line 1\n'
-                '#line 2\n'
-                '#line 3\n'
-                '
') - else: - self.assertEqual(md.convert(text), - '
#line 1\n'
-                '#line 2\n'
-                '#line 3
') + for text in (text0, text1): + md = markdown.Markdown(extensions=['codehilite']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '
'
+                    '#line 1\n'
+                    '#line 2\n'
+                    '#line 3\n'
+                    '
') + else: + self.assertEqual(md.convert(text), + '
'
+                    '#line 1\n'
+                    '#line 2\n'
+                    '#line 3
') 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 -- cgit v1.2.3