gettalong / kramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
http://kramdown.gettalong.org
Other
1.72k stars 271 forks source link

code blocks rendering following common mark #394

Closed bertBruynooghe closed 7 years ago

bertBruynooghe commented 7 years ago

Recently, I had an issue with reveal-ck where I thought it would be a good idea to use kramdown as rendering engine instead of redcarpet. However, it turned out we we had one important issue with code blocks rendering as <p><code></code></p> iso. <pre><code></code></pre> as required by the underlying reveal.js framework.

Since this is also the result as specified in the (preliminary) CommonMark syntax, it might be a good idea to have kramdown also rendering it this way (by default or based on some config).

Is this something you would consider? (I might be creating a PR if I have some spare time.)

gettalong commented 7 years ago

Please provide an example that doesn't render correctly as I don't understand the problem. Also: what do you mean by "iso."?

bertBruynooghe commented 7 years ago

Rendering:

```test```

renders into:

<p><code>test</code></p>

(as we can see from http://kramdown.herokuapp.com)

While we need it to be:

<pre><code>test</code></pre>

for reveal.js to consider it as a valid code block and render the slides correctly. This is also the expected behaviour according to CommonMark, so it might be good if there was at least an option to render the html that way using kramdown.

gettalong commented 7 years ago

A fenced codeblock consists of two separator lines between which the content is placed:

~~~
test
~~~

What you provided as an example doesn't have any separator line and therefore can't be a codeblock. But since backticks are used for inline code, your example is interpreted as a paragraph with a single code element, as it should be.

Can you provide the link to the CommonMark spec where it says otherwise? I could find anything and your first link was to the normal codeblock syntax (i.e. indented lines).

bertBruynooghe commented 7 years ago

You are probably right, I was getting confused between different implementations of markdown. http://spec.commonmark.org/0.27/#fenced-code-blocks

That being said,

~~~
test
~~~

does render as expected, so we can use that as a workaround, but:

```
test
```

still does not.

gettalong commented 7 years ago

Using backticks is not supported by kramdown but if you use the GFM parser it supports tildes as well as backticks (tildes should work everywhere though).

bertBruynooghe commented 7 years ago

Thanks for clearing this up for me!

wiktor-k commented 11 months ago

Using backticks is not supported by kramdown but if you use the GFM parser it supports tildes as well as backticks (tildes should work everywhere though).

Hi @gettalong! I'm working on a file and was surprised that backticks didn't work for fenced blocks in kramdown (I'm using kramdown-rfc to write a spec) and found this issue.

Is this by design or something that could be changed? (e.g. by submitting a PR that'd implement backticks support). I'm fine either way but I would like to clarify (I'm asking only for fenced code blocks using backticks in addition to tildes).

Thanks for your time! :wave:

gettalong commented 11 months ago

@wiktor-k Fenced code blocks with the kramdown parser will only work with tildes and this won't be changed. If you need backticks you either need to extend the parser yourself or use the GFM parser.

wiktor-k commented 11 months ago

Understood. Thanks!