In 2.0 how do we get hard_wrap=False or parse_block_html=True
Closed this issue · 3 comments
I'm looking to upgrade from 0.8.4 to 2.0 and I used to invoke mistune like this:
renderer = mistune.Renderer(escape=False, hard_wrap=False, parse_block_html=True)
markdown = mistune.Markdown(renderer=renderer)
Now I see that escape
is still an option but the others are gone:
markdown = mistune.create_markdown(escape=False)
How do I get similar behavior to what I had in 0.8.4?
@samtstern It can be done with a custom inline parser. Since it is a common feature, I've added it back onto InlineParser. You can learn how to use it with the tests in test_misc
.
For parse_block_html
, we don't have this feature anymore. You can only subclass BlockParser
and rewrite the parse_block_html
function to get your goal.
@lepture thank you for the quick response and the new support in InlineParser
! I'm not quite familiar enough with the library to be able to subclass BlockParser
but maybe after I use it some more I'll understand and maybe even submit a Pull Request with the feature.
@samtstern I think it is parse_block_html=True
is already supported with escape=False
. But there are some tricks:
For example:
<div>
## h2 text
</div>
Will be converted into:
<div>
<h2>h2 text</h2>
</div>
But below won't:
<div>
## h2 text
</div>