Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    def test_image_src_filtering_with_nice_data(self):
        actual = render('![](http:"foo")')
        expected = '<p><img src="http:&quot;foo&quot;" /></p>\n'
        ok(actual).diff(expected)

        actual = render('!["bar"](https://example.org/ "\'title\'")')
        expected = '<p><img src="https://example.org/" alt="&quot;bar&quot;" title="&#39;title&#39;" /></p>\n'
        ok(actual).diff(expected)
Beispiel #4
0
    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')
Beispiel #5
0
    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)
Beispiel #6
0
    def test_autolink_filtering_with_naughty_data(self):
        actual = render('<javascript:foo>')
        expected = '<p>&lt;javascript:foo&gt;</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)
Beispiel #7
0
    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')
Beispiel #8
0
    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)
Beispiel #9
0
        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():
            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)
Beispiel #11
0
    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')
Beispiel #12
0
    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'
        )
Beispiel #13
0
    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)
Beispiel #14
0
    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)')) == '&copy;'
     ok(smartypants('(r)')) == '&reg;'
     ok(smartypants('(tm)')) == '&trade;'
 def test_fractions(self):
     ok(smartypants('3/4ths')) == '&frac34;ths'
     ok(smartypants('3/4')) == '&frac34;'
     ok(smartypants('1/2')) == '&frac12;'
     ok(smartypants('1/4')) == '&frac14;'
Beispiel #17
0
    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')
Beispiel #18
0
 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)
Beispiel #19
0
    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')
Beispiel #20
0
 def test_escape_html_slash(self):
     ok(escape_html('a&<>"\'/', True)) == 'a&amp;&lt;&gt;&quot;&#39;&#47;'
Beispiel #21
0
 def test():
     ok(render(supplied)).diff(expected)
Beispiel #22
0
 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)
Beispiel #23
0
 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)
Beispiel #24
0
    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('...')) == '&hellip;'
     ok(smartypants('. . .')) == '&hellip;'
 def test_dash(self):
     ok(smartypants('--')) == '&ndash;'
     ok(smartypants('---')) == '&mdash;'
Beispiel #27
0
    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_apostrophes(self):
     ok(smartypants('\'s')) == '&rsquo;s'
     ok(smartypants('\'t')) == '&rsquo;t'
     ok(smartypants('\'m')) == '&rsquo;m'
     ok(smartypants('\'d')) == '&rsquo;d'
     ok(smartypants('\'re')) == '&rsquo;re'
     ok(smartypants('\'ll')) == '&rsquo;ll'
     ok(smartypants('\'ve')) == '&rsquo;ve'
Beispiel #29
0
    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')
Beispiel #30
0
 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&#39;">&#39;foo</a></p>\n' % rewrite_url(url)
         ok(actual).diff(expected)
Beispiel #31
0
    def test_int(self):
        expected = EXT_TABLES | EXT_FENCED_CODE | EXT_FOOTNOTES
        result = args_to_int(extension_map, expected)

        ok(result) == expected
Beispiel #32
0
 def test_escape_html(self):
     ok(escape_html('a&<>"\'/')) == 'a&amp;&lt;&gt;&quot;&#39;/'
Beispiel #33
0
 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&#39;">&#39;foo</a></p>\n'.format(url)
         ok(actual).diff(expected)
Beispiel #34
0
    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():
     ok(render(supplied)).diff(expected)
 def test_double_quotes(self):
     ok(smartypants('"Quotes"')) == '&ldquo;Quotes&rdquo;'