From c18ce238e39c2ccac92da25a6429bdade0db4dff Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Fri, 3 Jan 2014 18:03:15 -0500 Subject: Add feature for emphasizing some lines in a code block. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A code blocked headed by “:::python{1,3}” now emphasizes the first and third lines. With fences enabled, ```python{1,3} has the same effect. --- tests/test_extensions.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/test_extensions.py') diff --git a/tests/test_extensions.py b/tests/test_extensions.py index add759a..e918695 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -126,12 +126,33 @@ class TestCodeHilite(unittest.TestCase): '
# A Code Comment'
                 '
') + def testHighlightLinesWithColon(self): + text = '\t:::Python{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
') class TestFencedCode(unittest.TestCase): """ Test fenced_code extension. """ def setUp(self): self.md = markdown.Markdown(extensions=['fenced_code']) + self.has_pygments = True + try: + import pygments + except ImportError: + self.has_pygments = False def testBasicFence(self): """ Test Fenced Code Blocks. """ @@ -191,6 +212,32 @@ Fenced code block '~~~~~ # these tildes will not close the block\n' '') + def testFencedCodeWithHighlightLines(self): + """ Test Fenced Code with Highlighted Lines. """ + + text = ''' +```{1,3} +line 1 +line 2 +line 3 +```''' + md = markdown.Markdown(extensions=[ + 'codehilite(linenums=None,guess_lang=False)', + 'fenced_code']) + + 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 TestHeaderId(unittest.TestCase): """ Test HeaderId Extension. """ -- cgit v1.2.3 From 436b420c1c6bb9db569d6ce4be2d06cff829aea9 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Mon, 6 Jan 2014 22:10:51 -0500 Subject: =?UTF-8?q?Support=20syntax=20for=20highlighted=20lines=20like:=20?= =?UTF-8?q?```python=20hl=5Flines=3D=E2=80=9C1=203=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_extensions.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'tests/test_extensions.py') diff --git a/tests/test_extensions.py b/tests/test_extensions.py index e918695..ea4adad 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -127,7 +127,7 @@ class TestCodeHilite(unittest.TestCase): '') def testHighlightLinesWithColon(self): - text = '\t:::Python{2}\n\t#line 1\n\t#line 2\n\t#line 3' + text = '\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: @@ -216,7 +216,7 @@ Fenced code block """ Test Fenced Code with Highlighted Lines. """ text = ''' -```{1,3} +```hl_lines="1 3" line 1 line 2 line 3 @@ -238,6 +238,39 @@ line 3 'line 2\n' 'line 3') + def testFencedLanguageAndHighlightLines(self): + """ Test Fenced Code with Highlighted Lines. """ + + text0 = ''' +```.python hl_lines="1 3" +#line 1 +#line 2 +#line 3 +```''' + text1 = ''' +~~~{.python hl_lines="1 3"} +#line 1 +#line 2 +#line 3 +~~~''' + for text in (text0, text1): + md = markdown.Markdown(extensions=[ + 'codehilite(linenums=None,guess_lang=False)', + 'fenced_code']) + + 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 TestHeaderId(unittest.TestCase): """ Test HeaderId Extension. """ -- cgit v1.2.3 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. --- tests/test_extensions.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'tests/test_extensions.py') 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