diff options
author | Waylan Limberg <waylan@gmail.com> | 2013-02-14 16:04:24 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2013-02-14 16:04:24 -0500 |
commit | 36ab0c387f84485444e60480382caafb7a807fd6 (patch) | |
tree | 7b2613b9cee201d2cc8eb3fb544d8e34d5e7158d /tests | |
parent | fdfc84405ba690705ff343d46ab658bfc50a8836 (diff) | |
download | markdown-36ab0c387f84485444e60480382caafb7a807fd6.tar.gz markdown-36ab0c387f84485444e60480382caafb7a807fd6.tar.bz2 markdown-36ab0c387f84485444e60480382caafb7a807fd6.zip |
Allow better linenum override in CodeHilite
Fixes #148. The "force_linenos" config setting of the CodeHilite extension has been
marked as Pending Deprecation and a new setting "linenums" has been added to
replace it. See documentation for the [CodeHilite Extension] for an explaination
of the new "linenums" setting. The new setting will honor the old "force_linenos"
if it is set, but it will raise a PendingDeprecationWarning and will likely be
removed in a future version of Python-Markdown.
[CodeHilite Extension]: extensions/codehilite.html
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_extensions.py | 78 |
1 files changed, 74 insertions, 4 deletions
diff --git a/tests/test_extensions.py b/tests/test_extensions.py index fd77e5e..bee270a 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -31,8 +31,6 @@ class TestCodeHilite(unittest.TestCase): """ Test codehilite extension. """ def setUp(self): - self.md = markdown.Markdown(extensions=['codehilite']) - self.has_pygments = True try: import pygments @@ -41,16 +39,88 @@ class TestCodeHilite(unittest.TestCase): def testBasicCodeHilite(self): text = '\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '<div class="codehilite">' + '<pre><span class="c"># A Code Comment</span>\n' + '</pre></div>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite"><code># A Code Comment' + '</code></pre>') + + def testLinenumsTrue(self): + text = '\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=True)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '<table class="codehilitetable"><tr>' + '<td class="linenos"><div class="linenodiv"><pre>1</pre></div></td>' + '<td class="code"><div class="codehilite">' + '<pre><span class="c"># A Code Comment</span>\n</pre>' + '</div>\n</td>' + '</tr></table>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite"><code class="linenums"># A Code Comment' + '</code></pre>') + + def testLinenumsFalse(self): + text = '\t#!Python\n\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=False)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '<div class="codehilite">' + '<pre><span class="c"># A Code Comment</span>\n' + '</pre></div>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite"><code class="language-python"># A Code Comment' + '</code></pre>') + + def testLinenumsNone(self): + text = '\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=None)']) if self.has_pygments: - self.assertEqual(self.md.convert(text), + self.assertEqual(md.convert(text), '<div class="codehilite">' '<pre><span class="c"># A Code Comment</span>\n' '</pre></div>') else: - self.assertEqual(self.md.convert(text), + self.assertEqual(md.convert(text), '<pre class="codehilite"><code># A Code Comment' '</code></pre>') + def testLinenumsNoneWithShebang(self): + text = '\t#!Python\n\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=None)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '<table class="codehilitetable"><tr>' + '<td class="linenos"><div class="linenodiv"><pre>1</pre></div></td>' + '<td class="code"><div class="codehilite">' + '<pre><span class="c"># A Code Comment</span>\n</pre>' + '</div>\n</td>' + '</tr></table>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite"><code class="language-python linenums"># A Code Comment' + '</code></pre>') + + def testLinenumsNoneWithColon(self): + text = '\t:::Python\n\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=None)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '<div class="codehilite">' + '<pre><span class="c"># A Code Comment</span>\n' + '</pre></div>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite"><code class="language-python"># A Code Comment' + '</code></pre>') + class TestFencedCode(unittest.TestCase): """ Test fenced_code extension. """ |