Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<b> bold </b> only works inside <p> </p> #12

Open
yucongo opened this issue Jan 1, 2018 · 3 comments
Open

<b> bold </b> only works inside <p> </p> #12

yucongo opened this issue Jan 1, 2018 · 3 comments

Comments

@yucongo
Copy link

yucongo commented Jan 1, 2018

tomd.convert('<p><b> bold </b></p>')  # '\n** bold **\n',   works
tomd.convert('<b> bold </b>')  # "", does not work 

maybe pyquery can be useful, something like this:

from pyquery import Pyquery as pq
from tomd import MARKDOWN

html = "<b> bold </b>"
doc = pq(html)
for elm, val in MARKDOWN.items():
    # for item in doc(elm): replace item.html() with val[0] + pq(item).text() + val[1]
@elliotgao2
Copy link
Owner

@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>.

@yucongo
Copy link
Author

yucongo commented Jan 1, 2018

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***

@elliotgao2
Copy link
Owner

@yucongo okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants