| 1 |
|
| 2 |
|
| 3 |
e. |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 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 |
|
| 23 |
|
| 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 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
] |
| 106 |
|
| 107 |
|
| 108 |
if __name__ == '__main__': |
| 109 |
unittest.main() |