evilstreak / markdown-js

A Markdown parser for javascript
7.69k stars 863 forks source link

Fix for #258 "Mixing italic and Link Markdown destroyes the link." #271

Open HuFlungDu opened 8 years ago

HuFlungDu commented 8 years ago

This commit changes the link parser to handle it's text parsing in a new strong_state/em_state context, as well as ensuring that it will only parse the text in between the [] for the link text.

Before, the parser em state would break when you put _ in a link, and it would cause broken HTML when you would do something like this:

[some_link](http://link_address)

That would output:

<p>[some<em>link](http://link</em>address)</p>

Which is hot nonsense. The same thing would also happen if you wanted to emphasize an entire link, but wanted _ or * in your link text/address or also put emphasis on link text (Not usual, but possible if you are using this for user input).

This now more closely resembles the original markdown.pl (it still is different because this one will allow emphasis on the entire link while having underscores in the link text, while the original markdown.pl would output something like <p><em><a href="http://link_address">some</em>link</a>_</p>. This library never output that anyway, so this is closer than it used to be).

I also updated the package.json to use grunt-node-tap 1.0.0 , because I was otherwise unable to run the tests, and it doesn't seem to break anything. If that's a problem, I can remove that from the commit and merge that.