Debian Codegraph @

test/test_parsers/test_recommonmark/test_html_blocks.py

raw symbols SCIP
1 #! /usr/bin/env python3
2 # $Id: test_html_blocks.py 9425 2023-06-30 14:56:47Z milde $
3 # :Copyright: © 2020 Günter Milde.
4 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
5 #
6 # Copying and distribution of this file, with or without modification,
7 # are permitted in any medium without royalty provided the copyright
8 # notice and this notice are preserved.
9 # This file is offered as-is, without any warranty.
10 #
11 # .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
12 """
13 Tests for HTML blocks in CommonMark parsers
14 Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
15 """
16
17 from pathlib import Path
18 import sys
19 import unittest
20
21 if __name__ == '__main__':
22 # prepend the "docutils root" to the Python library path
23 # so we import the local `docutils` package.
24 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
25
26 from docutils.frontend import get_default_settings
27 from docutils.parsers.recommonmark_wrapper import Parser
28 from docutils.utils import new_document
29
30
31 class RecommonmarkParserTestCase(unittest.TestCase):
32 def test_parser(self):
33 parser = Parser()
34 settings = get_default_settings(Parser)
35 for name, cases in totest.items():
36 for casenum, (case_input, case_expected) in enumerate(cases):
37 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
38 document = new_document('test data', settings.copy())
39 parser.parse(case_input, document)
40 output = document.pformat()
41 self.assertEqual(case_expected, output)
42
43
44 totest = {}
45
46 totest['html_blocks'] = [
47 ["""\
48 A paragraph:
49
50 <p>A HTML block.</p>
51 """,
52 """\
53 <document source="test data">
54 <paragraph>
55 A paragraph:
56 <raw format="html" xml:space="preserve">
57 <p>A HTML block.</p>
58 """],
59 ["""\
60 <DIV CLASS="foo">
61
62 *Markdown*
63
64 </DIV>
65 """,
66 """\
67 <document source="test data">
68 <raw format="html" xml:space="preserve">
69 <DIV CLASS="foo">
70 <paragraph>
71 <emphasis>
72 Markdown
73 <raw format="html" xml:space="preserve">
74 </DIV>
75 """],
76 ["""\
77 <a href="foo">
78 *bar*
79 </a>
80 """,
81 """\
82 <document source="test data">
83 <raw format="html" xml:space="preserve">
84 <a href="foo">
85 *bar*
86 </a>
87 """],
88 # In recommonmark 0.7.0, some raw blocks at paragraph start make the
89 # paragraph a raw block :(
90 # ["""\
91 # <!-- foo -->*bar* (raw because of the comment tag at start of paragraph)
92 # *baz*
93 # """,
94 # """\
95 # <document source="test data">
96 # <paragraph>
97 # <raw format="html" xml:space="preserve">
98 # <!-- foo -->
99 # <emphasis>
100 # bar
101 # <paragraph>
102 # <emphasis>
103 # baz
104 # """],
105 ]
106
107
108 if __name__ == '__main__':
109 unittest.main()