From 0356e64f9f3c869de4cf81fd8ef3fc330d7f589f Mon Sep 17 00:00:00 2001 From: a-tal Date: Sun, 14 Jun 2015 16:39:37 -0700 Subject: [PATCH 1/5] adds support for linenostart --- markdown/extensions/codehilite.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py index 0657c3768..0bca79b99 100644 --- a/markdown/extensions/codehilite.py +++ b/markdown/extensions/codehilite.py @@ -75,7 +75,9 @@ class CodeHilite(object): def __init__(self, src=None, linenums=None, guess_lang=True, css_class="codehilite", lang=None, style='default', - noclasses=False, tab_length=4, hl_lines=None, use_pygments=True): + noclasses=False, tab_length=4, hl_lines=None, linenostart=1, + use_pygments=True): + self.linenostart = linenostart self.src = src self.lang = lang self.linenums = linenums @@ -119,7 +121,8 @@ def hilite(self): cssclass=self.css_class, style=self.style, noclasses=self.noclasses, - hl_lines=self.hl_lines) + hl_lines=self.hl_lines, + linenostart=self.linenostart,) return highlight(self.src, lexer, formatter) else: # just escape and build markup usable by JS highlighting libs @@ -170,6 +173,7 @@ def _parseHeader(self): \s* # Arbitrary whitespace # Optional highlight lines, single- or double-quote-delimited (hl_lines=(?P"|')(?P.*?)(?P=quot))? + (linenostart=(?P[0-9]*))? ''', re.VERBOSE) # search first line for shebang m = c.search(fl) @@ -187,6 +191,10 @@ def _parseHeader(self): self.linenums = True self.hl_lines = parse_hl_lines(m.group('hl_lines')) + linenostart = m.group('linenostart') + if linenostart: + # this will allow starting line 0 + self.linenostart = int(linenostart) else: # No match lines.insert(0, fl) From ee1dbe71604993e62e8b8bf7b123094fc5810a75 Mon Sep 17 00:00:00 2001 From: a-tal Date: Sun, 14 Jun 2015 21:33:01 -0700 Subject: [PATCH 2/5] adds test for linenostart --- tests/test_extensions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 38f0be3c9..a091dad76 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -236,6 +236,14 @@ def testUsePygmentsFalse(self): '' ) + def testUseLineNoStart(self): + text = '\t:::Python linenostart=42\n\t# A Code Comment' + md = markdown.Markdown(extensions=[ + markdown.extensions.codehilite.CodeHiliteExtension(linenums=True) + ]) + if self.has_pygments: + self.assertIn("42", md.convert(text)) + class TestFencedCode(unittest.TestCase): """ Test fenced_code extension. """ From fd42c86e65d6d3484221d0539cad42359efbc6b5 Mon Sep 17 00:00:00 2001 From: a-tal Date: Sun, 14 Jun 2015 21:48:11 -0700 Subject: [PATCH 3/5] add Pygments to install --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index cd0bbef20..91b663ce6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ before_install: install: - pip install tox - pip install coveralls + - pip install Pygments script: - tox after_success: From a7f238dc4855c8fe6328374b5fdf3ff63dc64204 Mon Sep 17 00:00:00 2001 From: Adam Talsma Date: Sun, 14 Jun 2015 22:04:16 -0700 Subject: [PATCH 4/5] -, --- markdown/extensions/codehilite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py index 0bca79b99..6a2c0489a 100644 --- a/markdown/extensions/codehilite.py +++ b/markdown/extensions/codehilite.py @@ -122,7 +122,7 @@ def hilite(self): style=self.style, noclasses=self.noclasses, hl_lines=self.hl_lines, - linenostart=self.linenostart,) + linenostart=self.linenostart) return highlight(self.src, lexer, formatter) else: # just escape and build markup usable by JS highlighting libs From e97792a2c1be398aa381933724b81251c876bff7 Mon Sep 17 00:00:00 2001 From: a-tal Date: Sun, 14 Jun 2015 22:18:50 -0700 Subject: [PATCH 5/5] explicit skip --- .travis.yml | 1 - tests/test_extensions.py | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 91b663ce6..cd0bbef20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ before_install: install: - pip install tox - pip install coveralls - - pip install Pygments script: - tox after_success: diff --git a/tests/test_extensions.py b/tests/test_extensions.py index a091dad76..9e8ceee39 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -237,12 +237,13 @@ def testUsePygmentsFalse(self): ) def testUseLineNoStart(self): + if not self.has_pygments: + self.skipTest("linenos only supported with Pygments") text = '\t:::Python linenostart=42\n\t# A Code Comment' md = markdown.Markdown(extensions=[ markdown.extensions.codehilite.CodeHiliteExtension(linenums=True) ]) - if self.has_pygments: - self.assertIn("42", md.convert(text)) + self.assertIn("42", md.convert(text)) class TestFencedCode(unittest.TestCase):