evilstreak / markdown-js

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

FIX: If the `firstBlock` is a string, don't throw an exception #204

Closed eviltrout closed 9 years ago

eviltrout commented 9 years ago

Sorry I don't have a test for this, because it's specific to something that Discourse adds in via our custom formatting.

Essentially the issue is firstBlock can be a String sometimes, and in that case we don't want to shift it, we just want to append it. All grunt tests pass and this fixes the issue in Discourse.

Thanks!

ashb commented 9 years ago

Can you give an example of what the input array looks like that triggers this case?

eviltrout commented 9 years ago

The difficult part with this PR is it depends on the Discourse extension shoving JsonML in there before it gets to this list parsing bit.

The Discourse check ends up putting a token in there that is a string, like "evil trout", where the list parsing expects an array. So the shift() ends up undefined. However without the shift, everything works as expected as the string is concated to the end of the list JsonML.

ashb commented 9 years ago

My concern here is that we're changing the already ugliest part of the code for a special case. Can Discourse put it in as ["evil trout"] instead of "evil trout"?

eviltrout commented 9 years ago

At first I thought that was impossible, but it seems I could do it entirely in Discourse's side. Sorry!