diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic/angle-links-and-img.html | 2 | ||||
-rw-r--r-- | tests/misc/brackets-in-img-title.html | 9 | ||||
-rw-r--r-- | tests/misc/brackets-in-img-title.txt | 12 | ||||
-rw-r--r-- | tests/misc/escaped_chars_in_js.html | 12 | ||||
-rw-r--r-- | tests/misc/escaped_chars_in_js.txt | 12 | ||||
-rw-r--r-- | tests/misc/url_spaces.html | 4 | ||||
-rw-r--r-- | tests/test_extensions.py | 84 | ||||
-rw-r--r-- | tests/util.py | 8 |
8 files changed, 136 insertions, 7 deletions
diff --git a/tests/basic/angle-links-and-img.html b/tests/basic/angle-links-and-img.html index 255c299..1ca3b0b 100644 --- a/tests/basic/angle-links-and-img.html +++ b/tests/basic/angle-links-and-img.html @@ -1,4 +1,4 @@ -<p><a href="simple%20link" title="title">link</a> +<p><a href="simple link" title="title">link</a> <img alt="image" src="http://example.com/image.jpg" /> <a href="http://example.com/(()((())923)(">link</a> <img alt="image" src="link(()))(" /></p>
\ No newline at end of file diff --git a/tests/misc/brackets-in-img-title.html b/tests/misc/brackets-in-img-title.html new file mode 100644 index 0000000..3677139 --- /dev/null +++ b/tests/misc/brackets-in-img-title.html @@ -0,0 +1,9 @@ +<p><img alt="alt" src="local-img.jpg" /> +<img alt="alt" src="local-img.jpg" title="" /> +<img alt="alt" src="local-img.jpg" title="normal title" /></p> +<p><img alt="alt" src="local-img.jpg" title="(just title in brackets)" /> +<img alt="alt" src="local-img.jpg" title="title with brackets (I think)" /></p> +<p><img alt="alt" src="local-img.jpg" title="(" /> +<img alt="alt" src="local-img.jpg" title="(open only" /> +<img alt="alt" src="local-img.jpg" title=")" /> +<img alt="alt" src="local-img.jpg" title="close only)" /></p>
\ No newline at end of file diff --git a/tests/misc/brackets-in-img-title.txt b/tests/misc/brackets-in-img-title.txt new file mode 100644 index 0000000..01fcd4e --- /dev/null +++ b/tests/misc/brackets-in-img-title.txt @@ -0,0 +1,12 @@ +![alt](local-img.jpg) +![alt](local-img.jpg "") +![alt](local-img.jpg "normal title") + +![alt](local-img.jpg "(just title in brackets)") +![alt](local-img.jpg "title with brackets (I think)") + +![alt](local-img.jpg "(") +![alt](local-img.jpg "(open only") +![alt](local-img.jpg ")") +![alt](local-img.jpg "close only)") + diff --git a/tests/misc/escaped_chars_in_js.html b/tests/misc/escaped_chars_in_js.html new file mode 100644 index 0000000..b821fb1 --- /dev/null +++ b/tests/misc/escaped_chars_in_js.html @@ -0,0 +1,12 @@ +<p><span id="e116142240">[javascript protected email address]</span> +<script type="text/javascript"> + var a="gqMjyw7lZCaKk6p0J3uAUYS1.dbIW2hXzDHmiVNotOPRe_Ev@c4Gs58+LBr-F9QTfxn"; + var b=a.split("").sort().join(""); + var c="F_-F6F_-FMe_"; + var d=""; + for(var e=0;e<c.length;e++) + d+=b.charAt(a.indexOf(c.charAt(e))); + document + .getElementById("e116142240") + .innerHTML="<a href=\"mailto:"+d+"\">"+d+"</a>"; +</script></p>
\ No newline at end of file diff --git a/tests/misc/escaped_chars_in_js.txt b/tests/misc/escaped_chars_in_js.txt new file mode 100644 index 0000000..ca917c8 --- /dev/null +++ b/tests/misc/escaped_chars_in_js.txt @@ -0,0 +1,12 @@ +<span id="e116142240">[javascript protected email address]</span> +<script type="text/javascript"> + var a="gqMjyw7lZCaKk6p0J3uAUYS1.dbIW2hXzDHmiVNotOPRe_Ev@c4Gs58+LBr-F9QTfxn"; + var b=a.split("").sort().join(""); + var c="F_-F6F_-FMe_"; + var d=""; + for(var e=0;e<c.length;e++) + d+=b.charAt(a.indexOf(c.charAt(e))); + document + .getElementById("e116142240") + .innerHTML="<a href=\"mailto:"+d+"\">"+d+"</a>"; +</script> diff --git a/tests/misc/url_spaces.html b/tests/misc/url_spaces.html index f9c91b3..ebacb75 100644 --- a/tests/misc/url_spaces.html +++ b/tests/misc/url_spaces.html @@ -1,2 +1,2 @@ -<p><a href="http://wikipedia.org/wiki/Dawn%20of%20War">Dawn of War</a></p> -<p><a href="http://wikipedia.org/wiki/Dawn%20of%20War" title="Dawn of War">Dawn of War</a></p>
\ No newline at end of file +<p><a href="http://wikipedia.org/wiki/Dawn of War">Dawn of War</a></p> +<p><a href="http://wikipedia.org/wiki/Dawn of War" title="Dawn of War">Dawn of War</a></p>
\ No newline at end of file diff --git a/tests/test_extensions.py b/tests/test_extensions.py index add759a..d33feec 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -126,12 +126,37 @@ class TestCodeHilite(unittest.TestCase): '<pre class="codehilite"><code class="language-python"># A Code Comment' '</code></pre>') + def testHighlightLinesWithColon(self): + # 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" + + for text in (text0, text1): + md = markdown.Markdown(extensions=['codehilite']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '<div class="codehilite"><pre>' + '<span class="c">#line 1</span>\n' + '<span class="hll"><span class="c">#line 2</span>\n</span>' + '<span class="c">#line 3</span>\n' + '</pre></div>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite">' + '<code class="language-python">#line 1\n' + '#line 2\n' + '#line 3</code></pre>') 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 +216,65 @@ Fenced code block '~~~~~ # these tildes will not close the block\n' '</code></pre>') + def testFencedCodeWithHighlightLines(self): + """ Test Fenced Code with Highlighted Lines. """ + + text = ''' +```hl_lines="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), + '<div class="codehilite"><pre>' + '<span class="hll">line 1\n</span>' + 'line 2\n' + '<span class="hll">line 3\n</span>' + '</pre></div>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite"><code>line 1\n' + 'line 2\n' + 'line 3</code></pre>') + + 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), + '<div class="codehilite"><pre>' + '<span class="hll"><span class="c">#line 1</span>\n</span>' + '<span class="c">#line 2</span>\n' + '<span class="hll"><span class="c">#line 3</span>\n</span>' + '</pre></div>') + else: + self.assertEqual(md.convert(text), + '<pre class="codehilite"><code class="language-python">#line 1\n' + '#line 2\n' + '#line 3</code></pre>') + class TestHeaderId(unittest.TestCase): """ Test HeaderId Extension. """ diff --git a/tests/util.py b/tests/util.py index bbf7aea..0f416fb 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,16 +1,16 @@ import sys if sys.version_info[0] == 3: - from configparser import SafeConfigParser + from configparser import ConfigParser else: - from ConfigParser import SafeConfigParser + from ConfigParser import SafeConfigParser as ConfigParser class MarkdownSyntaxError(Exception): pass -class CustomConfigParser(SafeConfigParser): +class CustomConfigParser(ConfigParser): def get(self, section, option): - value = SafeConfigParser.get(self, section, option) + value = ConfigParser.get(self, section, option) if option == 'extensions': if len(value.strip()): return value.split(',') |