def test_from_dict(self): expected = EXT_TABLES | EXT_FENCED_CODE | EXT_FOOTNOTES result = reduce_dict( extension_map, ('tables', 'fenced-code', 'footnotes')) ok(result) == expected
def test_args(self): expected = EXT_TABLES | EXT_FENCED_CODE | EXT_FOOTNOTES result = args_to_int( extension_map, ('tables', 'fenced-code', 'footnotes')) ok(result) == expected
def test_image_src_filtering_with_nice_data(self): actual = render('![](http:"foo")') expected = '<p><img src="http:"foo"" /></p>\n' ok(actual).diff(expected) actual = render('!["bar"](https://example.org/ "\'title\'")') expected = '<p><img src="https://example.org/" alt=""bar"" title="'title'" /></p>\n' ok(actual).diff(expected)
def test_punctuation_before_emphasis(self): markdown = self.render_with('%*test*', extensions=EXT_NO_INTRA_EMPHASIS) ok(markdown).diff('<p>%<em>test</em></p>\n') markdown = self.render_with('~**test**', extensions=EXT_NO_INTRA_EMPHASIS) ok(markdown).diff('<p>~<strong>test</strong></p>\n')
def test_autolink_filtering_with_nice_data(self): for url in ('http://a', "https://b?x&y"): actual = render('<%s>' % url) expected = '<p><a href="{0}">{0}</a></p>\n'.format(escape_html(url)) ok(actual).diff(expected) supplied = "<*****@*****.**>" expected = '<p>%s</p>\n' % escape_html(supplied) ok(render_escape(supplied)).diff(expected)
def test_autolink_filtering_with_naughty_data(self): actual = render('<javascript:foo>') expected = '<p><javascript:foo></p>\n' ok(actual).diff(expected) url = 'javascript:0' encoded_url = ''.join('&x{0:x};'.format(ord(c)) for c in url) html = render('<%s>' % encoded_url) ok(html).not_contains(url)
def test_emphasis_in_autolink(self): markdown = self.render_with('https://example.com/_example_', extensions=EXT_AUTOLINK) ok(markdown).diff( '<p><a href="https://example.com/_example_">https://example.com/_example_</a></p>\n' ) markdown = self.render_with('*****@*****.**', extensions=EXT_AUTOLINK) ok(markdown).diff('<p><em>example</em>@example.com</p>\n')
def test_autolink_rewriting(self): for url in ('http://a', 'https://b?x&y'): actual = render_rewrite('<%s>' % url) expected = '<p><a href="%s">%s</a></p>\n' expected %= (rewrite_url(url), escape_html(url)) ok(actual).diff(expected) supplied = "<*****@*****.**>" expected = '<p>%s</p>\n' % escape_html(supplied) ok(render_escape(supplied)).diff(expected)
def test(): with codecs.open(text_path, 'r', encoding='utf-8') as fd: text = fd.read() with codecs.open(html_path, 'r', encoding='utf-8') as fd: expected_html = fd.read() actual_html = self.r(text) expected_result = clean_html(expected_html) actual_result = clean_html(actual_html) ok(actual_result).diff(expected_result)
def test_list_custom_start(self): class ListCustomStartRenderer(HtmlRenderer): def list(self, text, is_ordered, is_block, prefix): if prefix: return '<ol start="{start}">\n{text}</ol>\n'.format( start=prefix, text=text) return super(ListCustomStartRenderer, self).list(text, is_ordered, is_block, prefix) text = ' 5. five\n 6. six\n 7. seven' rendered = Markdown(ListCustomStartRenderer())(text) ok(rendered).diff('<ol start="5">\n<li>five</li>\n<li>six</li>\n<li>seven</li>\n</ol>\n')
def test_list_custom_start(self): class ListCustomStartRenderer(HtmlRenderer): def list(self, text, is_ordered, is_block, prefix): if prefix: return '<ol start="{start}">\n{text}</ol>\n'.format( start=prefix, text=text) return super(ListCustomStartRenderer, self).list(text, is_ordered, is_block, prefix) text = ' 5. five\n 6. six\n 7. seven' rendered = Markdown(ListCustomStartRenderer())(text) ok(rendered).diff( '<ol start="5">\n<li>five</li>\n<li>six</li>\n<li>seven</li>\n</ol>\n' )
def test_html_escape(self): supplied = 'Example <script>alert(1);</script>' expected = '<p>%s</p>\n' % escape_html(supplied) ok(render_escape(supplied)).diff(expected) html = render_escape('<sc<script>ript>xss</sc</script>ript>') ok(html).not_contains('<sc') ok(html).not_contains('ript>') supplied = '<span><a href="javascript:xss">foo</a></span>' expected = '<p>%s</p>\n' % escape_html(supplied) ok(render_escape(supplied)).diff(expected)
def test_html_skip(self): actual = render('Example <script>alert(1);</script>') expected = '<p>Example alert(1);</p>\n' ok(actual).diff(expected) html = render('<sc<script>ript>xss</sc</script>ript>') ok(html).not_contains('<sc') ok(html).not_contains('ript>') actual = render('<span><a href="javascript:xss">foo</a></span>') expected = '<p>foo</p>\n' ok(actual).diff(expected)
def test_parens(self): ok(smartypants('(c)')) == '©' ok(smartypants('(r)')) == '®' ok(smartypants('(tm)')) == '™'
def test_fractions(self): ok(smartypants('3/4ths')) == '¾ths' ok(smartypants('3/4')) == '¾' ok(smartypants('1/2')) == '½' ok(smartypants('1/4')) == '¼'
def test_nested_bold_italics(self): markdown = self.r('*foo **bar** baz*') ok(markdown).diff('<p><em>foo <strong>bar</strong> baz</em></p>\n') markdown = self.r(r'*foo\**') ok(markdown).diff('<p><em>foo*</em></p>\n')
def test_image_src_rewriting(self): actual = render_rewrite('![](http:"foo")') expected = '<p><img src="//img_proxy/http%3A%22foo%22" /></p>\n' ok(actual).diff(expected)
def test_escape_html_slash(self): ok(escape_html('a&<>"\'/', True)) == 'a&<>"'/'
def test(): ok(render(supplied)).diff(expected)
def test_image_src_filtering_with_naughty_data(self): actual = render('![foo](javascript:foo)') expected = '<p>![foo](javascript:foo)</p>\n' ok(actual).diff(expected)
def test_bug_pyformat_in_content(self): # See: https://github.com/FSX/misaka/issues/66 actual = render('[![xxx](http://www.example.com/?v=%s)](http://www.example.com/])') expected = '<p><a href="http://www.example.com/]"><img src="http://www.example.com/?v=%s" alt="xxx" /></a></p>\n' ok(actual).diff(expected)
def test_from_int(self): expected = EXT_TABLES | EXT_FENCED_CODE | EXT_FOOTNOTES result = reduce_dict(extension_map, expected) ok(result) == expected
def test_ellipsis(self): ok(smartypants('...')) == '…' ok(smartypants('. . .')) == '…'
def test_dash(self): ok(smartypants('--')) == '–' ok(smartypants('---')) == '—'
def test_apostrophes(self): ok(smartypants('\'s')) == '’s' ok(smartypants('\'t')) == '’t' ok(smartypants('\'m')) == '’m' ok(smartypants('\'d')) == '’d' ok(smartypants('\'re')) == '’re' ok(smartypants('\'ll')) == '’ll' ok(smartypants('\'ve')) == '’ve'
def test_emphasis_in_autolink(self): markdown = self.render_with('https://example.com/_example_', extensions=EXT_AUTOLINK) ok(markdown).diff('<p><a href="https://example.com/_example_">https://example.com/_example_</a></p>\n') markdown = self.render_with('*****@*****.**', extensions=EXT_AUTOLINK) ok(markdown).diff('<p><em>example</em>@example.com</p>\n')
def test_link_rewriting(self): for url in ('http://a', 'https://b'): actual = render_rewrite("['foo](%s \"bar'\")" % url) expected = '<p><a href="%s" title="bar'">'foo</a></p>\n' % rewrite_url(url) ok(actual).diff(expected)
def test_int(self): expected = EXT_TABLES | EXT_FENCED_CODE | EXT_FOOTNOTES result = args_to_int(extension_map, expected) ok(result) == expected
def test_escape_html(self): ok(escape_html('a&<>"\'/')) == 'a&<>"'/'
def test_link_filtering_with_nice_data(self): for url in ('http://a', 'https://b'): actual = render("['foo](%s \"bar'\")" % url) expected = '<p><a href="{0}" title="bar'">'foo</a></p>\n'.format(url) ok(actual).diff(expected)
def test_link_filtering_with_naughty_data(self): supplied = '[foo](javascript:xss)' expected = '<p>%s</p>\n' % escape_html(supplied) ok(render(supplied)).diff(expected) html = render('[foo](unknown:bar)') expected = '<p>%s</p>\n' % escape_html(supplied) ok(render(supplied)).diff(expected) html = render('[" xss><xss>]("><xss>)') ok(html).not_contains('<xss>') ok(html).not_contains('" xss') html = render('[" xss><xss>](https:"><xss>)') ok(html).not_contains('<xss>') ok(html).not_contains('" xss')
def test_double_quotes(self): ok(smartypants('"Quotes"')) == '“Quotes”'