showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.26k stars 1.56k forks source link

Code block invalid output with custom language input #856

Closed erictuvesson closed 2 years ago

erictuvesson commented 3 years ago

Markdown Input:

image

Expected Output:

<pre><code class="json language-json">{
    "custom": true
}
</code></pre>
<pre><code class="json language-json">{
    "custom": false
}
</code></pre>

Actual Output:

<p>```json custom data
{
    "custom": true
}</p>
<pre><code>
</code></pre>
<p>json
{
    "custom": false
}
```</p>

Extra

Removing custom data from the markdown will solve the issue, but it doesn't allow for code block extensions.

SyntaxRules commented 2 years ago

Good catch, this kind of metadata is allowable, at least in GFM: https://github.github.com/gfm/#example-113

tivie commented 2 years ago

yeah, showdown doesn't allow spaces after the code block delimiter.

tivie commented 2 years ago

Should be fixed in commit 6711425

Philmod commented 1 year ago

Hi! Was this change released?

I have the issue when there is a space after the language: "```python ". I'm using the 2.1.0 version of showdown.

yarn list --pattern showdown
yarn list v1.22.19
├─ @types/showdown@2.0.0
├─ showdown-highlight@3.1.0
└─ showdown@2.1.0

Edit: that commit change is indeed in your main branch: https://github.com/showdownjs/showdown/blob/master/dist/showdown.js#L3404

But not in the 2.1.0 release code.

Thanks!

Philmod commented 1 year ago

@tivie Any help on ^ ?