Debian Codegraph @

tests/test_syntax/extensions/test_attr_list.py

raw
1 """
2 Python Markdown
3
4 A Python implementation of John Gruber's Markdown.
5
6 Documentation: https://python-markdown.github.io/
7 GitHub: https://github.com/Python-Markdown/markdown/
8 PyPI: https://pypi.org/project/Markdown/
9
10 Started by Manfred Stienstra (http://www.dwerg.net/).
11 Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
12 Currently maintained by Waylan Limberg (https://github.com/waylan),
13 Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).
14
15 Copyright 2007-2023 The Python Markdown Project (v. 1.7 and later)
16 Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
17 Copyright 2004 Manfred Stienstra (the original version)
18
19 License: BSD (see LICENSE.md for details).
20 """
21
22 from markdown.test_tools import TestCase
23
24
25 class TestAttrList(TestCase):
26 maxDiff = None
27 default_kwargs = {'extensions': ['attr_list']}
28
29 # TODO: Move the rest of the `attr_list` tests here.
30
31 def test_empty_attr_list(self):
32 self.assertMarkdownRenders(
33 '*foo*{ }',
34 '<p><em>foo</em>{ }</p>'
35 )
36
37 def test_curly_after_inline(self):
38 self.assertMarkdownRenders(
39 '*inline*{.a} } *text*{.a }}',
40 '<p><em class="a">inline</em> } <em class="a">text</em>}</p>'
41 )
42
43 def test_extra_eq_gets_ignored_inside_curly_inline(self):
44 # Undesired behavior but kept for historic compatibility.
45 self.assertMarkdownRenders(
46 '*inline*{data-test="x" =a} *text*',
47 '<p><em data-test="x">inline</em> <em>text</em></p>'
48 )
49
50 def test_curly_after_block(self):
51 self.assertMarkdownRenders(
52 '# Heading {.a} }',
53 '<h1>Heading {.a} }</h1>'
54 )
55
56 def test_curly_in_single_quote(self):
57 self.assertMarkdownRenders(
58 "# Heading {data-test='{}'}",
59 '<h1 data-test="{}">Heading</h1>'
60 )
61
62 def test_curly_in_double_quote(self):
63 self.assertMarkdownRenders(
64 '# Heading {data-test="{}"}',
65 '<h1 data-test="{}">Heading</h1>'
66 )
67
68 def test_unclosed_quote_ignored(self):
69 # Undesired behavior but kept for historic compatibility.
70 self.assertMarkdownRenders(
71 '# Heading {foo="bar}',
72 '<h1 foo="&quot;bar">Heading</h1>'
73 )
74
75 def test_backslash_escape_value(self):
76 self.assertMarkdownRenders(
77 '# `*Foo*` { id="\\*Foo\\*" }',
78 '<h1 id="*Foo*"><code>*Foo*</code></h1>'
79 )
80
81 def test_table_td(self):
82 self.assertMarkdownRenders(
83 self.dedent(
84 """
85 | A { .foo } | *B*{ .foo } | C { } | D{ .foo } | E { .foo } F |
86 |-------------|-------------|-------|---------------|--------------|
87 | a { .foo } | *b*{ .foo } | c { } | d{ .foo } | e { .foo } f |
88 | valid on td | inline | empty | missing space | not at end |
89 """
90 ),
91 self.dedent(
92 """
93 <table>
94 <thead>
95 <tr>
96 <th class="foo">A</th>
97 <th><em class="foo">B</em></th>
98 <th>C { }</th>
99 <th>D{ .foo }</th>
100 <th>E { .foo } F</th>
101 </tr>
102 </thead>
103 <tbody>
104 <tr>
105 <td class="foo">a</td>
106 <td><em class="foo">b</em></td>
107 <td>c { }</td>
108 <td>d{ .foo }</td>
109 <td>e { .foo } f</td>
110 </tr>
111 <tr>
112 <td>valid on td</td>
113 <td>inline</td>
114 <td>empty</td>
115 <td>missing space</td>
116 <td>not at end</td>
117 </tr>
118 </tbody>
119 </table>
120 """
121 ),
122 extensions=['attr_list', 'tables']
123 )