evilstreak / markdown-js

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

wrong output #162

Open tallesl opened 10 years ago

tallesl commented 10 years ago

I'm getting the following wrong output:

> require('markdown').parse('[github.com/languages](https://github.com/languages) now redirects to [github.com/trending](https://github.com/trending "Trending repositories on GitHub today")')
'<p><a href="https://github.com/languages) now redirects to [github.com/trending](https://github.com/trending" title="Trending repositories on GitHub today">github.com/languages</a></p>'

Dunno what it is. The input syntax seems to be fine.

With version 0.5.0.

evilstreak commented 10 years ago

Looks like we have an overly greedy regex. This is reproducible in the latest code.

progrape commented 9 years ago

I'm also getting a wrong output like this:

var markdown = require( "markdown" ).markdown;
console.log( markdown.toHTML( "[http://github.com/aa_bb](http://github.com/aa_bb)" ) );

I want to output html like <p><a href="http://github.com/aa_bb">http://github.com/aa_bb</a></p>, but actually output <p>[http://github.com/aa<em>bb](http://github.com/aa</em>bb)</p>

dhimmel commented 8 years ago

I believe @jspauld tracked down the origin of this bug and found a fix. See the discussion on Thinklab.

jspauld commented 8 years ago

Yes I will submit a pull request here

jspauld commented 8 years ago

This bug no longer appears on Discourse which is based on markdown-js. I checked their code and they seem to have updated this line:

var m = text.match( /^\s*\([ \t]*([^"']*)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/ );

to this:

var m = text.match( /^\s*\([ \t]*([^"'\s]*)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/ );

I tried marking this change on this repo but the spaces_in_url test fails if I do so. I'll leave it to others to figure out the appropriate solution.