thephpleague / html-to-markdown

Convert HTML to Markdown with PHP
MIT License
1.77k stars 205 forks source link

Consecutive emphasis produces incorrect markdown #199

Closed markopy closed 3 years ago

markopy commented 3 years ago

If emphasis tags of the same type (em, i) or (strong, b) follow each other without space like this:

<em>foo</em><em>bar</em>

it produces the markdown

*foo**bar*

which is incorrect because it converts back to

<em>foo**bar</em>

per https://spec.commonmark.org/0.29/#example-411

The fix for this seems to be to merge consecutive emphasis tags if they will produce the same type of emphasis (* or **) in markdown. The correct output is simply:

*foobar*
markopy commented 3 years ago

This is fixed in version 5.0.