html2md icon indicating copy to clipboard operation
html2md copied to clipboard

  breaks emphasis syntax

Open J-Dark opened this issue 1 year ago • 3 comments

  is breaking emphasis syntax in markdown results.

e.g.: <strong>Text&nbsp;</strong> becomes **Text ** instead of **Text**

The workaround is to html2md.convert(html.replaceAll('&nbsp;', ' '))

J-Dark avatar Oct 08 '24 12:10 J-Dark

Although the most common, nbsp; isn't the only one. Both the number and name variant of these symbols seem to break it. I tried like a dozen other random characters, but only space characters seem to trigger this.

Character HTML number HTML name Description
  &#160; &nbsp; non-breaking space
&#8194; &ensp; en space
&#8195; &emsp; em space
&#8201; &thinsp; thin space

I've seen it break <em>, <strong>,<del>, but there could be others.

It seems to happen when it is at the start or end of the tag, but also if it is padded by normal spaces <strong>Text&nbsp;</strong> - breaks <trong>Text&nbsp; </strong> - breaks <strong>Text&nbsp; Text</strong> - works <strong>&nbsp;Text</strong> - breaks <strong> &nbsp;Text</strong> - breaks

(tested by rendering using flutter_markdown.

timbotimbo avatar May 12 '25 14:05 timbotimbo

@timbotimbo This workaround fixes everything here? html2md.convert(html.replaceAll(' ', ' '))

Jakuzeisme avatar May 21 '25 11:05 Jakuzeisme

It should work if you replace all the symbols in that table that you suspect might show up in your input.

timbotimbo avatar May 22 '25 20:05 timbotimbo