Open yucongo opened 6 years ago
@yucongo The tage <b>
is an inline tag which should be in a block tag. I wonder when using tag <b>
outside a block tag like <p>
or <div>
.
I worked it out using pyquery, for my need at least:
from pyquery import PyQuery as pq
from tomd import MARKDOWN
html = '''
<h1>h1</h1>
<h2>h2</h2><h3>h3</h3>
<h4>h4</h4>
<del>del</del>
<b>bold</b>
<i>italic</i>
<b><i>bold italic</i></b>'''
doc = pq(html)
for elm, val in MARKDOWN.items():
for item in doc(elm).items():
item.replace_with(val[0] + item.html() + val[1])
print(doc.text())
Output
# h1
## h2
### h3
#### h4
~~del~~
**bold**
*italic*
***bold italic***
@yucongo okay.
maybe pyquery can be useful, something like this: