1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
from inspect import cleandoc
from creole.tests.utils.base_unittest import BaseCreoleTest
class MarkdownTests(BaseCreoleTest):
def test_code_block(self):
self.assert_html2markdown(
markdown_string=cleandoc(
'''
Two prints:
```python
print(1)
print(2)
```
Below the code block.
'''
),
html_string=cleandoc(
'''
<p>Two prints:</p>
<pre><code class="language-python">
print(1)
print(2)
</code></pre>
<p>Below the code block.</p>
'''
),
# debug=True,
)
def test_lists(self):
self.assert_html2markdown(
markdown_string=cleandoc(
'''
* one
* one-one
* one-two
* two
1. two-one
1. two-two
'''
),
html_string=cleandoc(
'''
<ul>
<li>one
<ul>
<li>one-one</li>
<li>one-two</li>
</ul>
</li>
<li>two
<ol>
<li>two-one</li>
<li>two-two</li>
</ol>
</li>
</ul>
'''
),
)
self.assert_html2markdown(
markdown_string=cleandoc(
'''
* "one" and "two"
* "three"
'''
),
html_string=cleandoc(
'''
<ul>
<li>"one" and "two"</li>
<li>"three"</li>
</ul>
'''
),
# debug=True,
)
self.assert_html2markdown(
markdown_string=cleandoc(
'''
* html2markdown
Here the `--help` output
'''
),
html_string=cleandoc(
'''
<ul>
<li>html2markdown</li>
</ul>
<p>Here the <code>--help</code> output</p>
'''
),
# debug=True,
)
def test_table(self):
self.assert_html2markdown(
markdown_string=cleandoc(
'''
| A1 | B1 |
| A2 | B2 |
'''
),
html_string=cleandoc(
'''
<table>
<tr><td>A1</td><td>B1</td></tr>
<tr><td>A2</td><td>B2</td></tr>
</table>
'''
),
# debug=True,
)
self.assert_html2markdown(
markdown_string=cleandoc(
'''
# A Table
| Foo | Bar |
| --- | --- |
| A1 | B1 |
| A2 | B2 |
Text after the table.
'''
),
html_string=cleandoc(
'''
<h1>A Table</h1>
<table>
<tr><th>Foo</th><th>Bar</th></tr>
<tr><td>A1</td><td>B1</td></tr>
<tr><td>A2</td><td>B2</td></tr>
</table>
<p>Text after the table.</p>
'''
),
# debug=True,
)
|