• 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 TestHorizontalRules(TestCase):
26
27    def test_hr_asterisks(self):
28        self.assertMarkdownRenders(
29            '***',
30
31            '<hr />'
32        )
33
34    def test_hr_asterisks_spaces(self):
35        self.assertMarkdownRenders(
36            '* * *',
37
38            '<hr />'
39        )
40
41    def test_hr_asterisks_long(self):
42        self.assertMarkdownRenders(
43            '*******',
44
45            '<hr />'
46        )
47
48    def test_hr_asterisks_spaces_long(self):
49        self.assertMarkdownRenders(
50            '* * * * * * *',
51
52            '<hr />'
53        )
54
55    def test_hr_asterisks_1_indent(self):
56        self.assertMarkdownRenders(
57            ' ***',
58
59            '<hr />'
60        )
61
62    def test_hr_asterisks_spaces_1_indent(self):
63        self.assertMarkdownRenders(
64            ' * * *',
65
66            '<hr />'
67        )
68
69    def test_hr_asterisks_2_indent(self):
70        self.assertMarkdownRenders(
71            '  ***',
72
73            '<hr />'
74        )
75
76    def test_hr_asterisks_spaces_2_indent(self):
77        self.assertMarkdownRenders(
78            '  * * *',
79
80            '<hr />'
81        )
82
83    def test_hr_asterisks_3_indent(self):
84        self.assertMarkdownRenders(
85            '   ***',
86
87            '<hr />'
88        )
89
90    def test_hr_asterisks_spaces_3_indent(self):
91        self.assertMarkdownRenders(
92            '   * * *',
93
94            '<hr />'
95        )
96
97    def test_hr_asterisks_trailing_space(self):
98        self.assertMarkdownRenders(
99            '*** ',
100
101            '<hr />'
102        )
103
104    def test_hr_asterisks_spaces_trailing_space(self):
105        self.assertMarkdownRenders(
106            '* * * ',
107
108            '<hr />'
109        )
110
111    def test_hr_hyphens(self):
112        self.assertMarkdownRenders(
113            '---',
114
115            '<hr />'
116        )
117
118    def test_hr_hyphens_spaces(self):
119        self.assertMarkdownRenders(
120            '- - -',
121
122            '<hr />'
123        )
124
125    def test_hr_hyphens_long(self):
126        self.assertMarkdownRenders(
127            '-------',
128
129            '<hr />'
130        )
131
132    def test_hr_hyphens_spaces_long(self):
133        self.assertMarkdownRenders(
134            '- - - - - - -',
135
136            '<hr />'
137        )
138
139    def test_hr_hyphens_1_indent(self):
140        self.assertMarkdownRenders(
141            ' ---',
142
143            '<hr />'
144        )
145
146    def test_hr_hyphens_spaces_1_indent(self):
147        self.assertMarkdownRenders(
148            ' - - -',
149
150            '<hr />'
151        )
152
153    def test_hr_hyphens_2_indent(self):
154        self.assertMarkdownRenders(
155            '  ---',
156
157            '<hr />'
158        )
159
160    def test_hr_hyphens_spaces_2_indent(self):
161        self.assertMarkdownRenders(
162            '  - - -',
163
164            '<hr />'
165        )
166
167    def test_hr_hyphens_3_indent(self):
168        self.assertMarkdownRenders(
169            '   ---',
170
171            '<hr />'
172        )
173
174    def test_hr_hyphens_spaces_3_indent(self):
175        self.assertMarkdownRenders(
176            '   - - -',
177
178            '<hr />'
179        )
180
181    def test_hr_hyphens_trailing_space(self):
182        self.assertMarkdownRenders(
183            '--- ',
184
185            '<hr />'
186        )
187
188    def test_hr_hyphens_spaces_trailing_space(self):
189        self.assertMarkdownRenders(
190            '- - - ',
191
192            '<hr />'
193        )
194
195    def test_hr_underscores(self):
196        self.assertMarkdownRenders(
197            '___',
198
199            '<hr />'
200        )
201
202    def test_hr_underscores_spaces(self):
203        self.assertMarkdownRenders(
204            '_ _ _',
205
206            '<hr />'
207        )
208
209    def test_hr_underscores_long(self):
210        self.assertMarkdownRenders(
211            '_______',
212
213            '<hr />'
214        )
215
216    def test_hr_underscores_spaces_long(self):
217        self.assertMarkdownRenders(
218            '_ _ _ _ _ _ _',
219
220            '<hr />'
221        )
222
223    def test_hr_underscores_1_indent(self):
224        self.assertMarkdownRenders(
225            ' ___',
226
227            '<hr />'
228        )
229
230    def test_hr_underscores_spaces_1_indent(self):
231        self.assertMarkdownRenders(
232            ' _ _ _',
233
234            '<hr />'
235        )
236
237    def test_hr_underscores_2_indent(self):
238        self.assertMarkdownRenders(
239            '  ___',
240
241            '<hr />'
242        )
243
244    def test_hr_underscores_spaces_2_indent(self):
245        self.assertMarkdownRenders(
246            '  _ _ _',
247
248            '<hr />'
249        )
250
251    def test_hr_underscores_3_indent(self):
252        self.assertMarkdownRenders(
253            '   ___',
254
255            '<hr />'
256        )
257
258    def test_hr_underscores_spaces_3_indent(self):
259        self.assertMarkdownRenders(
260            '   _ _ _',
261
262            '<hr />'
263        )
264
265    def test_hr_underscores_trailing_space(self):
266        self.assertMarkdownRenders(
267            '___ ',
268
269            '<hr />'
270        )
271
272    def test_hr_underscores_spaces_trailing_space(self):
273        self.assertMarkdownRenders(
274            '_ _ _ ',
275
276            '<hr />'
277        )
278
279    def test_hr_before_paragraph(self):
280        self.assertMarkdownRenders(
281            self.dedent(
282                """
283                ***
284                An HR followed by a paragraph with no blank line.
285                """
286            ),
287            self.dedent(
288                """
289                <hr />
290                <p>An HR followed by a paragraph with no blank line.</p>
291                """
292            )
293        )
294
295    def test_hr_after_paragraph(self):
296        self.assertMarkdownRenders(
297            self.dedent(
298                """
299                A paragraph followed by an HR with no blank line.
300                ***
301                """
302            ),
303            self.dedent(
304                """
305                <p>A paragraph followed by an HR with no blank line.</p>
306                <hr />
307                """
308            )
309        )
310
311    def test_hr_after_emstrong(self):
312        self.assertMarkdownRenders(
313            self.dedent(
314                """
315                ***text***
316                ***
317                """
318            ),
319            self.dedent(
320                """
321                <p><strong><em>text</em></strong></p>
322                <hr />
323                """
324            )
325        )
326
327    def test_not_hr_2_asterisks(self):
328        self.assertMarkdownRenders(
329            '**',
330
331            '<p>**</p>'
332        )
333
334    def test_not_hr_2_asterisks_spaces(self):
335        self.assertMarkdownRenders(
336            '* *',
337
338            self.dedent(
339                """
340                <ul>
341                <li>*</li>
342                </ul>
343                """
344            )
345        )
346
347    def test_not_hr_2_hyphens(self):
348        self.assertMarkdownRenders(
349            '--',
350
351            '<p>--</p>'
352        )
353
354    def test_not_hr_2_hyphens_spaces(self):
355        self.assertMarkdownRenders(
356            '- -',
357
358            self.dedent(
359                """
360                <ul>
361                <li>-</li>
362                </ul>
363                """
364            )
365        )
366
367    def test_not_hr_2_underscores(self):
368        self.assertMarkdownRenders(
369            '__',
370
371            '<p>__</p>'
372        )
373
374    def test_not_hr_2_underscores_spaces(self):
375        self.assertMarkdownRenders(
376            '_ _',
377
378            '<p>_ _</p>'
379        )
380
381    def test_2_consecutive_hr(self):
382        self.assertMarkdownRenders(
383            self.dedent(
384                """
385                - - -
386                - - -
387                """
388            ),
389            self.dedent(
390                """
391                <hr />
392                <hr />
393                """
394            )
395        )
396
397    def test_not_hr_end_in_char(self):
398        self.assertMarkdownRenders(
399            '--------------------------------------c',
400
401            '<p>--------------------------------------c</p>'
402        )
403