jbt / markdown-editor

Live (Github-flavored) Markdown Editor
http://jbt.github.com/markdown-editor
ISC License
2.83k stars 644 forks source link

Inside a table, backticked pipe character is not ignored #20

Closed josdejong closed 9 years ago

josdejong commented 9 years ago

Thanks for this great, simple editor.

I encountered a small bug: Try the following markdown code in the editor:

# Operators

Operator | Description
-------- | -----------
`&`      | Bitwise and
`|`      | Bitwise or
`^`      | Bitwise xor

In this table, the line line with "bitwise or" is wrongly parsed as having three columns: The pipe character inside backticks | is not ignored but interpreted as a column separator.

jbt commented 9 years ago

It looks like this is an issue with marked, the markdown parser this project uses internally. I'm actually planning on swapping marked out for markdown-it at some point, which is much better-maintained and should improve some of the weirder parsing quirks. However, it looks like it exhibits the same issue - I have to say I'm not completely familiar with the precedence rules in markdown but if both parsers treat it the same then it may be possible that that's the correct behaviour. I'll dig deeper and see what it's supposed to do.

josdejong commented 9 years ago

Thanks!

jbrooksuk commented 9 years ago

FWIW this issue isn't fixed by the change to markdown-it.

josdejong commented 9 years ago

Hm. Too bad. Is it a known issue at markdown-it?

jbrooksuk commented 9 years ago

Without backticks it works with a single \ escape character:

# Operators

Operator | Description
-------- | -----------
`&`      | Bitwise and
\|    | Bitwise or
`^`      | Bitwise xor
josdejong commented 9 years ago

As a workaround I just write it as HTML:

# Operators

Operator | Description
-------- | -----------
`&`      | Bitwise and
<code>&#124;</code> | Bitwise or
`^`      | Bitwise xor
jbrooksuk commented 9 years ago

For me this returns:

https://cloudup.com/cV8r0FYBHaT

jbt commented 9 years ago

Yeah I've been trying to read around this and I can't quite figure out what the desired behaviour should be - best I can find is in GitHub's GFM description but that's annoyingly light on the detail of what kind of precedence order there should be.

It's kind of odd that both marked and markdown-it treat the | as higher-precedence than the backticks but GitHub doesn't.

jbt commented 9 years ago

This is the corresponding issue in marked btw: https://github.com/chjj/marked/issues/285

Not sure if there's something over on markdown-it, if not I might open one

jbt commented 9 years ago

Righty my PR over on markdown-it is merged now so this should just be a matter of bumping markdown-it and it'll suddenly start working. I'll get that done sometime today

josdejong commented 9 years ago

Nice, thanks!

jbt commented 9 years ago

Updated and it looks like it works, hurrah!

http://jbt.github.io/markdown-editor/#8y9ILUosyS9SqFFwSS1OLsosKMnMz+PShQKgsC4CcCWoJSiAQY2CU2ZJeWZxqkJiXgpXQg2GcH4RV0IchmhFfhEA

josdejong commented 9 years ago

Thanks again! It's these little details that make or brake an app :)