|
11 | 11 | import pytest |
12 | 12 | from .pytest_patcher import mark_class |
13 | 13 |
|
| 14 | +from markdown2 import __version_info__ as md2__version_info__ |
| 15 | + |
14 | 16 | if ReStructuredText: |
15 | 17 | skip_rst = lambda func, *args, **kwargs: func |
16 | 18 | else: |
@@ -774,51 +776,122 @@ def test_string_markdown(self): |
774 | 776 | self.assertEqual(p.markdown().strip(), u2s(u'<p>A string with <br> <em>embedded</em> \u00df</p>')) |
775 | 777 |
|
776 | 778 | def test_string_markdown_link(self): |
777 | | - p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A link <http://localhost>')) |
778 | | - self.assertEqual(p.markdown().strip(), u2s(u'<p>A link <a href="http://localhost">http://localhost</a></p>')) |
| 779 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 780 | + u2s(u'A link <http://localhost>')) |
| 781 | + m = p.markdown().strip() |
| 782 | + m = self.mangleMarkdown2(m) |
| 783 | + |
| 784 | + self.assertEqual( u2s(u'<p>A link <a href="http://localhost" rel="nofollow noopener">http://localhost</a></p>'), m) |
779 | 785 |
|
780 | 786 | def test_string_markdown_link_item(self): |
781 | 787 | """ The link formats for the different markdown engines changes. |
782 | 788 | Order of attributes, value for rel (noopener, nofollow etc) |
783 | 789 | is different. So most tests check for a substring that indicates |
784 | 790 | success rather than the entire returned string. |
785 | 791 | """ |
786 | | - p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An issue1 link')) |
| 792 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 793 | + u2s(u'An issue1 link')) |
787 | 794 | self.assertIn( u2s(u'href="issue1"'), p.markdown().strip()) |
788 | 795 | # just verify that plain linking is working |
789 | 796 | self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1)) |
790 | 797 |
|
791 | | - p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1](issue1) link')) |
| 798 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 799 | + u2s(u'An [issue1](issue1) link')) |
792 | 800 | self.assertIn( u2s(u'href="issue1"'), p.markdown().strip()) |
793 | 801 | # just verify that plain linking is working |
794 | 802 | self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1)) |
795 | 803 |
|
796 | | - p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1](https://example.com/issue1) link')) |
797 | | - self.assertIn( u2s(u'href="https://example.com/issue1"'), p.markdown().strip()) |
| 804 | + p = StringHTMLProperty( |
| 805 | + self.client, 'test', '1', None, 'test', |
| 806 | + u2s(u'An [issue1](https://example.com/issue1) link')) |
| 807 | + self.assertIn( u2s(u'href="https://example.com/issue1"'), |
| 808 | + p.markdown().strip()) |
| 809 | + |
| 810 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 811 | + u2s(u'An [issu1](#example) link')) |
| 812 | + self.assertIn( u2s(u'href="#example"'), p.markdown().strip()) |
| 813 | + |
| 814 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 815 | + u2s(u'An [issu1](/example) link')) |
| 816 | + self.assertIn( u2s(u'href="/example"'), p.markdown().strip()) |
| 817 | + |
| 818 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 819 | + u2s(u'An [issu1](./example) link')) |
| 820 | + self.assertIn( u2s(u'href="./example"'), p.markdown().strip()) |
798 | 821 |
|
799 | | - p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1] (https://example.com/issue1) link')) |
| 822 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 823 | + u2s(u'An [issu1](../example) link')) |
| 824 | + self.assertIn( u2s(u'href="../example"'), p.markdown().strip()) |
| 825 | + |
| 826 | + p = StringHTMLProperty( |
| 827 | + self.client, 'test', '1', None, 'test', |
| 828 | + u2s(u'A [wuarchive_ftp](ftp://www.wustl.gov/file) link')) |
| 829 | + self.assertIn( u2s(u'href="ftp://www.wustl.gov/file"'), |
| 830 | + p.markdown().strip()) |
| 831 | + |
| 832 | + p = StringHTMLProperty( |
| 833 | + self.client, 'test', '1', None, 'test', |
| 834 | + u2s(u'An [issue1] (https://example.com/issue1) link')) |
800 | 835 | self.assertIn( u2s(u'href="issue1"'), p.markdown().strip()) |
801 | 836 | if type(self) == MistuneTestCase: |
802 | 837 | # mistune makes the https url into a real link |
803 | | - self.assertIn( u2s(u'href="https://example.com/issue1"'), p.markdown().strip()) |
| 838 | + self.assertIn( u2s(u'href="https://example.com/issue1"'), |
| 839 | + p.markdown().strip()) |
804 | 840 | else: |
805 | 841 | # the other two engines leave the parenthesized url as is. |
806 | | - self.assertIn( u2s(u' (https://example.com/issue1) link'), p.markdown().strip()) |
| 842 | + self.assertIn( u2s(u' (https://example.com/issue1) link'), |
| 843 | + p.markdown().strip()) |
807 | 844 |
|
808 | | - def test_string_markdown_link(self): |
| 845 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 846 | + u2s(u'An [issu1](.../example) link')) |
| 847 | + if (isinstance(self, Markdown2TestCase) and |
| 848 | + md2__version_info__ > (2, 4, 9)): |
| 849 | + # markdown2 > 2.4.9 handles this differently |
| 850 | + self.assertIn( u2s(u'href="#"'), p.markdown().strip()) |
| 851 | + else: |
| 852 | + self.assertIn( u2s(u'href=".../example"'), p.markdown().strip()) |
| 853 | + |
| 854 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 855 | + u2s(u'A [phone](tel:0016175555555) link')) |
| 856 | + if (isinstance(self, Markdown2TestCase) and |
| 857 | + md2__version_info__ > (2, 4, 9)): |
| 858 | + self.assertIn(u2s(u'href="#"'), p.markdown().strip()) |
| 859 | + else: |
| 860 | + self.assertIn( u2s(u'href="tel:0016175555555"'), |
| 861 | + p.markdown().strip()) |
| 862 | + |
| 863 | + def test_string_email_markdown_link(self): |
809 | 864 | # markdown2 and markdown escape the email address |
810 | 865 | try: |
811 | 866 | from html import unescape as html_unescape |
812 | 867 | except ImportError: |
813 | 868 | from HTMLParser import HTMLParser |
814 | 869 | html_unescape = HTMLParser().unescape |
815 | 870 |
|
816 | | - p = StringHTMLProperty( self. client, 'test', '1', None, 'test', u2s( u'A link <[email protected]>')) |
| 871 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 872 | + u2s( u'A link <[email protected]>')) |
817 | 873 | m = html_unescape(p.markdown().strip()) |
818 | 874 | m = self.mangleMarkdown2(m) |
819 | 875 |
|
820 | 876 | self. assertEqual( m, u2s( u'<p>A link <a href="mailto:[email protected]">[email protected]</a></p>')) |
821 | 877 |
|
| 878 | + p = StringHTMLProperty( |
| 879 | + self.client, 'test', '1', None, 'test', |
| 880 | + u2s( u'An bare email [email protected] link')) |
| 881 | + m = self.mangleMarkdown2(html_unescape(p.markdown().strip())) |
| 882 | + self. assertIn( u2s( u'href="mailto:[email protected]"'), |
| 883 | + m) |
| 884 | + |
| 885 | + p = StringHTMLProperty( |
| 886 | + self.client, 'test', '1', None, 'test', |
| 887 | + u2s( u'An [email_url](mailto:[email protected]) link')) |
| 888 | + m = self.mangleMarkdown2(html_unescape(p.markdown().strip())) |
| 889 | + |
| 890 | + if isinstance(self, MistuneTestCase): |
| 891 | + self. assertIn( '<a href="mailto:[email protected]" rel="nofollow noopener">email_url</a>', m) |
| 892 | + else: |
| 893 | + self. assertIn( '<a href="mailto:[email protected]">email_url</a>', m) |
| 894 | + |
822 | 895 | def test_string_markdown_javascript_link(self): |
823 | 896 | # make sure we don't get a "javascript:" link |
824 | 897 | p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<javascript:alert(1)>')) |
@@ -866,7 +939,7 @@ def test_string_markdown_code_block_attribute(self): |
866 | 939 | if type(self) == MistuneTestCase: |
867 | 940 | self.assertEqual(m, parser.normalize('<p>embedded code block <pre></p>\n<pre><code class="lang-python">line 1\nline 2\n</code></pre>\n<p>new </pre> paragraph</p>')) |
868 | 941 | elif type(self) == MarkdownTestCase: |
869 | | - self.assertEqual(m, parser.normalize('<p>embedded code block <pre></p>\n<pre><code class="language-python">line 1\nline 2\n</code></pre>\n<p>new </pre> paragraph</p>')) |
| 942 | + self.assertEqual(m.replace('class="python"','class="language-python"'), parser.normalize('<p>embedded code block <pre></p>\n<pre><code class="language-python">line 1\nline 2\n</code></pre>\n<p>new </pre> paragraph</p>')) |
870 | 943 | else: |
871 | 944 | expected_result = parser.normalize('<p>embedded code block <pre></p>\n<div class="codehilite"><pre><span></span><code><span class="n">line</span> <span class="mi">1</span>\n<span class="n">line</span> <span class="mi">2</span>\n</code></pre></div>\n<p>new </pre> paragraph</p>') |
872 | 945 | self.assertEqual(m, expected_result) |
|
0 commit comments