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') 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