leeoniya / reMarked.js

client-side HTML > markdown
http://leeoniya.github.io/reMarked.js/
396 stars 97 forks source link

Whitespace in <strong> and <em> #32

Closed ghost closed 10 years ago

ghost commented 10 years ago

If a <strong> and <em> has trailing whitespace in the beginning or in the end of its text, the trailing space is preserved when converting it to markdown. At glance, this may sound like something we want but this causes the converted markdown to be invalid.

For example, the following HTML:

<strong>  this text contains two spaces in the beginning and in the end.  </strong>

gets converted to the following markdown which doesn't render properly (copy this markdown into a markdown editor and preview it).

**  this text contains two spaces in the beginning and in the end.  **

Can the trailing white space be moved out of the surrounding \ so that the trailing whitespace can be preserved and a markdown editor can properly render the text bold?

For example: this is what i think is the desirable outcome

  **this text contains two spaces in the beginning and in the end.**  
leeoniya commented 10 years ago

nice catch. i'll patch this later today.

leeoniya commented 10 years ago

while technically it should, this regex won't catch things like

<strong>   foo bar
baz
</strong>

supporting this would be an easy tweak (just adding a /gm flag to the regex), so open a new issue if you run into it.

ghost commented 10 years ago

Hm.. I ran into a some similar issue. The regex isn't treating &nbsp; characters as whitespace characters.

So maybe the following HTML

<strong>&nbsp;word &nbsp;</strong>

should be converted as such:

\u00A0;**word** \u00A0

Want me to open this as a new issue?

ghost commented 10 years ago

Thanks for your continued support. I would buy you a beer if I could :).

The following HTML

first <em><strong>second</strong> </em>third

gets converted to

first _**second**_third

But I believe the expected result should be:

first _**second**_ third
leeoniya commented 10 years ago

fixed in https://github.com/leeoniya/reMarked.js/commit/f7ef061f29a0eb3baf4df05157c13d8a8f0d78b7