diff options
Diffstat (limited to 'tests/test_syntax/extensions')
-rw-r--r-- | tests/test_syntax/extensions/test_smarty.py | 162 |
1 files changed, 161 insertions, 1 deletions
diff --git a/tests/test_syntax/extensions/test_smarty.py b/tests/test_syntax/extensions/test_smarty.py index fc635ad..f2d074d 100644 --- a/tests/test_syntax/extensions/test_smarty.py +++ b/tests/test_syntax/extensions/test_smarty.py @@ -27,10 +27,170 @@ class TestSmarty(TestCase): default_kwargs = {'extensions': ['smarty']} + def test_basic(self): + self.assertMarkdownRenders( + "It's fun. What's fun?", + '<p>It’s fun. What’s fun?</p>' + ) + self.assertMarkdownRenders( + '"Isn\'t this fun"? --- she said...', + '<p>“Isn’t this fun”? — she said…</p>' + ) + self.assertMarkdownRenders( + '"\'Quoted\' words in a larger quote."', + '<p>“‘Quoted’ words in a larger quote.”</p>' + ) + self.assertMarkdownRenders( + '\'Quoted "words" in a larger quote.\'', + '<p>‘Quoted “words” in a larger quote.’</p>' + ) + self.assertMarkdownRenders( + '"quoted" text and **bold "quoted" text**', + '<p>“quoted” text and <strong>bold “quoted” text</strong></p>' + ) + self.assertMarkdownRenders( + "'quoted' text and **bold 'quoted' text**", + '<p>‘quoted’ text and <strong>bold ‘quoted’ text</strong></p>' + ) + self.assertMarkdownRenders( + 'em-dashes (---) and ellipes (...)', + '<p>em-dashes (—) and ellipes (…)</p>' + ) + self.assertMarkdownRenders( + '"[Link](http://example.com)" --- she said.', + '<p>“<a href="http://example.com">Link</a>” — she said.</p>' + ) + self.assertMarkdownRenders( + '"Ellipsis within quotes..."', + '<p>“Ellipsis within quotes…”</p>' + ) + + def test_years(self): + self.assertMarkdownRenders("1440--80's", '<p>1440–80’s</p>') + self.assertMarkdownRenders("1440--'80s", '<p>1440–’80s</p>') + self.assertMarkdownRenders("1440---'80s", '<p>1440—’80s</p>') + self.assertMarkdownRenders("1960's", '<p>1960’s</p>') + self.assertMarkdownRenders("one two '60s", '<p>one two ’60s</p>') + self.assertMarkdownRenders("'60s", '<p>’60s</p>') + + def test_wrapping_line(self): + text = ( + "A line that 'wraps' with\n" + "*emphasis* at the beginning of the next line." + ) + html = ( + '<p>A line that ‘wraps’ with\n' + '<em>emphasis</em> at the beginning of the next line.</p>' + ) + self.assertMarkdownRenders(text, html) + + def test_escaped(self): + self.assertMarkdownRenders( + 'Escaped \\-- ndash', + '<p>Escaped -- ndash</p>' + ) + self.assertMarkdownRenders( + '\\\'Escaped\\\' \\"quotes\\"', + '<p>\'Escaped\' "quotes"</p>' + ) + self.assertMarkdownRenders( + 'Escaped ellipsis\\...', + '<p>Escaped ellipsis...</p>' + ) + self.assertMarkdownRenders( + '\'Escaped \\"quotes\\" in real ones\'', + '<p>‘Escaped "quotes" in real ones’</p>' + ) + self.assertMarkdownRenders( + '\\\'"Real" quotes in escaped ones\\\'', + "<p>'“Real” quotes in escaped ones'</p>" + ) + def test_escaped_attr(self): self.assertMarkdownRenders( '', '<p><img alt="x"x" src="x" /></p>' ) - # TODO: Move rest of smarty tests here. + def test_code_spans(self): + self.assertMarkdownRenders( + 'Skip `"code" -- --- \'spans\' ...`.', + '<p>Skip <code>"code" -- --- \'spans\' ...</code>.</p>' + ) + + def test_code_blocks(self): + text = ( + ' Also skip "code" \'blocks\'\n' + ' foo -- bar --- baz ...' + ) + html = ( + '<pre><code>Also skip "code" \'blocks\'\n' + 'foo -- bar --- baz ...\n' + '</code></pre>' + ) + self.assertMarkdownRenders(text, html) + + def test_horizontal_rule(self): + self.assertMarkdownRenders('--- -- ---', '<hr />') + + +class TestSmartyAngledQuotes(TestCase): + + default_kwargs = { + 'extensions': ['smarty'], + 'extension_configs': { + 'smarty': { + 'smart_angled_quotes': True, + }, + }, + } + + def test_angled_quotes(self): + self.assertMarkdownRenders( + '<<hello>>', + '<p>«hello»</p>' + ) + self.assertMarkdownRenders( + 'Кавычки-<<ёлочки>>', + '<p>Кавычки-«ёлочки»</p>' + ) + self.assertMarkdownRenders( + 'Anführungszeichen->>Chevrons<<', + '<p>Anführungszeichen-»Chevrons«</p>' + ) + + +class TestSmartyCustomSubstitutions(TestCase): + + default_kwargs = { + 'extensions': ['smarty'], + 'extension_configs': { + 'smarty': { + 'smart_angled_quotes': True, + 'substitutions': { + 'ndash': '\u2013', + 'mdash': '\u2014', + 'ellipsis': '\u2026', + 'left-single-quote': '‚', # `sb` is not a typo! + 'right-single-quote': '‘', + 'left-double-quote': '„', + 'right-double-quote': '“', + 'left-angle-quote': '[', + 'right-angle-quote': ']', + }, + }, + }, + } + + def test_custom_substitutions(self): + text = ( + '<< The "Unicode char of the year 2014"\n' + "is the 'mdash': ---\n" + "Must not be confused with 'ndash' (--) ... >>" + ) + html = ( + '<p>[ The „Unicode char of the year 2014“\n' + 'is the ‚mdash‘: \u2014\n' + 'Must not be confused with ‚ndash‘ (\u2013) \u2026 ]</p>' + ) + self.assertMarkdownRenders(text, html) |