• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Python Markdown
3
4A Python implementation of John Gruber's Markdown.
5
6Documentation: https://python-markdown.github.io/
7GitHub: https://github.com/Python-Markdown/markdown/
8PyPI: https://pypi.org/project/Markdown/
9
10Started by Manfred Stienstra (http://www.dwerg.net/).
11Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
12Currently maintained by Waylan Limberg (https://github.com/waylan),
13Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).
14
15Copyright 2007-2018 The Python Markdown Project (v. 1.7 and later)
16Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
17Copyright 2004 Manfred Stienstra (the original version)
18
19License: BSD (see LICENSE.md for details).
20"""
21
22from markdown.test_tools import TestCase
23
24
25class TestAdvancedImages(TestCase):
26
27    def test_nested_square_brackets(self):
28        self.assertMarkdownRenders(
29            """![Text[[[[[[[]]]]]]][]](http://link.com/image.png) more text""",
30            """<p><img alt="Text[[[[[[[]]]]]]][]" src="http://link.com/image.png" /> more text</p>"""
31        )
32
33    def test_nested_round_brackets(self):
34        self.assertMarkdownRenders(
35            """![Text](http://link.com/(((((((()))))))()).png) more text""",
36            """<p><img alt="Text" src="http://link.com/(((((((()))))))()).png" /> more text</p>"""
37        )
38
39    def test_uneven_brackets_with_titles1(self):
40        self.assertMarkdownRenders(
41            """![Text](http://link.com/(.png"title") more text""",
42            """<p><img alt="Text" src="http://link.com/(.png" title="title" /> more text</p>"""
43        )
44
45    def test_uneven_brackets_with_titles2(self):
46        self.assertMarkdownRenders(
47            """![Text](http://link.com/('.png"title") more text""",
48            """<p><img alt="Text" src="http://link.com/('.png" title="title" /> more text</p>"""
49        )
50
51    def test_uneven_brackets_with_titles3(self):
52        self.assertMarkdownRenders(
53            """![Text](http://link.com/(.png"title)") more text""",
54            """<p><img alt="Text" src="http://link.com/(.png" title="title)" /> more text</p>"""
55        )
56
57    def test_uneven_brackets_with_titles4(self):
58        self.assertMarkdownRenders(
59            """![Text](http://link.com/(.png "title") more text""",
60            """<p><img alt="Text" src="http://link.com/(.png" title="title" /> more text</p>"""
61        )
62
63    def test_uneven_brackets_with_titles5(self):
64        self.assertMarkdownRenders(
65            """![Text](http://link.com/(.png "title)") more text""",
66            """<p><img alt="Text" src="http://link.com/(.png" title="title)" /> more text</p>"""
67        )
68
69    def test_mixed_title_quotes1(self):
70        self.assertMarkdownRenders(
71            """![Text](http://link.com/'.png"title") more text""",
72            """<p><img alt="Text" src="http://link.com/'.png" title="title" /> more text</p>"""
73        )
74
75    def test_mixed_title_quotes2(self):
76        self.assertMarkdownRenders(
77            """![Text](http://link.com/".png'title') more text""",
78            """<p><img alt="Text" src="http://link.com/&quot;.png" title="title" /> more text</p>"""
79        )
80
81    def test_mixed_title_quotes3(self):
82        self.assertMarkdownRenders(
83            """![Text](http://link.com/with spaces.png'"and quotes" 'and title') more text""",
84            """<p><img alt="Text" src="http://link.com/with spaces.png" title="&quot;and quotes&quot; 'and title" />"""
85            """ more text</p>"""
86        )
87
88    def test_mixed_title_quotes4(self):
89        self.assertMarkdownRenders(
90            """![Text](http://link.com/with spaces'.png"and quotes" 'and title") more text""",
91            """<p><img alt="Text" src="http://link.com/with spaces'.png" title="and quotes&quot; 'and title" />"""
92            """ more text</p>"""
93        )
94
95    def test_mixed_title_quotes5(self):
96        self.assertMarkdownRenders(
97            """![Text](http://link.com/with spaces .png'"and quotes" 'and title') more text""",
98            """<p><img alt="Text" src="http://link.com/with spaces .png" title="&quot;and quotes&quot;"""
99            """ 'and title" /> more text</p>"""
100        )
101
102    def test_mixed_title_quotes6(self):
103        self.assertMarkdownRenders(
104            """![Text](http://link.com/with spaces "and quotes".png 'and title') more text""",
105            """<p><img alt="Text" src="http://link.com/with spaces &quot;and quotes&quot;.png" title="and title" />"""
106            """ more text</p>"""
107        )
108
109    def test_single_quote(self):
110        self.assertMarkdownRenders(
111            """![test](link"notitle.png)""",
112            """<p><img alt="test" src="link&quot;notitle.png" /></p>"""
113        )
114
115    def test_angle_with_mixed_title_quotes(self):
116        self.assertMarkdownRenders(
117            """![Text](<http://link.com/with spaces '"and quotes".png> 'and title') more text""",
118            """<p><img alt="Text" src="http://link.com/with spaces '&quot;and quotes&quot;.png" title="and title" />"""
119            """ more text</p>"""
120        )
121
122    def test_misc(self):
123        self.assertMarkdownRenders(
124            """![Poster](http://humane_man.jpg "The most humane man.")""",
125            """<p><img alt="Poster" src="http://humane_man.jpg" title="The most humane man." /></p>"""
126        )
127
128    def test_misc_ref(self):
129        self.assertMarkdownRenders(
130            self.dedent(
131                """
132                ![Poster][]
133
134                [Poster]:http://humane_man.jpg "The most humane man."
135                """
136            ),
137            self.dedent(
138                """
139                <p><img alt="Poster" src="http://humane_man.jpg" title="The most humane man." /></p>
140                """
141            )
142        )
143
144    def test_misc_blank(self):
145        self.assertMarkdownRenders(
146            """![Blank]()""",
147            """<p><img alt="Blank" src="" /></p>"""
148        )
149
150    def test_misc_img_title(self):
151        self.assertMarkdownRenders(
152            """![Image](http://humane man.jpg "The most humane man.")""",
153            """<p><img alt="Image" src="http://humane man.jpg" title="The most humane man." /></p>"""
154        )
155
156    def test_misc_img(self):
157        self.assertMarkdownRenders(
158            """![Image](http://humane man.jpg)""",
159            """<p><img alt="Image" src="http://humane man.jpg" /></p>"""
160        )
161
162    def test_short_ref(self):
163        self.assertMarkdownRenders(
164            self.dedent(
165                """
166                ![ref]
167
168                [ref]: ./image.jpg
169                """
170            ),
171            '<p><img alt="ref" src="./image.jpg" /></p>'
172        )
173
174    def test_short_ref_in_link(self):
175        self.assertMarkdownRenders(
176            self.dedent(
177                """
178                [![img ref]](http://example.com/)
179
180                [img ref]: ./image.jpg
181                """
182            ),
183            '<p><a href="http://example.com/"><img alt="img ref" src="./image.jpg" /></a></p>'
184        )
185