evilstreak / markdown-js

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

Triple Backtick Code Blocks Have Trouble with New Line #100

Closed techpines closed 11 years ago

techpines commented 11 years ago

I have a code block using the triple backtick syntax that looks like this:

bone = require('bone.io');

bone.set('io.options', {server: io;});

For some reason it outputs this:

<p><code></code>`
bone = require(&#39;bone.io&#39;);</p>

<p>bone.set(&#39;io.options&#39;, {server: io;});
<code></code>`</p>

But if I change my code block that is inside that triple backtick block to not have a new line:

bone = require('bone.io');
bone.set('io.options', {server: io;});

It's working just fine:

<p><code>
bone = require(&#39;bone.io&#39;);
bone.set(&#39;io.options&#39;, {server: io;});
</code></p>

I'm guessing it's a bug with the parser?

ashb commented 11 years ago

So the triple back tick method syntax is not part of the core Markdown syntax - it's an addition from the Github Flavoured Markdown.

I've made a start on supporting the GFM on the gfm branch: https://github.com/evilstreak/markdown-js/tree/gfm - this branch might be slightly out of date and need rebasing - we haven't touched it in a while (but should just be missing a few bug fixes if anything)

ashb commented 11 years ago

I think this is the problem - but can you update your example so it shows the exact input you are entering (i.e. make sure your input is indented by 4 spaces so it is markdown 'escaped')

techpines commented 11 years ago

I'm not indenting, I guess I'm trying to do gfm style markdown and the library does not really support it?

https://gist.github.com/techpines/5945812

Since the backtick stuff will cause issues in these github issue dialog boxes, I threw it in that gist above. Which is rendering it :), but you can still click to view it raw.

Right now, I'm just doing a workaround where after I compile with toHTML() I go through and replace all instances of "[NEWLINE]" with whitespace.

Also, I'd say that GFM is pretty cool/useful, and i guess I will throw out how I'm using your markdown library to get syntax highlighting.

There's a library called highlight.js, and it expects code blocks to be <pre><code>, so I'm actually adding the language type after the triple backtick like GFM, but then after it's compiled I'm converting something like this:

<p><code>javascript

To this:

<pre><code class="javascript">

Not sure if that is interesting to you or not, it seems like you are trying to stay true to the real markdown spec, but I wanted to throw it out there in case anyone else was trying to do something similar.

Cheers!

evilstreak commented 11 years ago

GFM support is being handled in #41