fix(gfmCodeBlocks): allow the info string in gfmCodeBlocks to contain spaces

The line with the opening code fence may optionally contain some text following the code fence (the info string); this is trimmed of leading and trailing whitespace and can contain multiple words (but not newlines).

Closes #856
This commit is contained in:
Estevao Soares dos Santos 2022-02-24 01:22:11 +00:00
parent 5a84b1cdf0
commit 67114255ad
7 changed files with 24 additions and 1 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -20,9 +20,13 @@ showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals
text += '¨0';
text = text.replace(/(?:^|\n)(?: {0,3})(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n(?: {0,3})\1/g, function (wholeMatch, delim, language, codeblock) {
text = text.replace(/(?:^|\n) {0,3}(```+|~~~+) *([^\n\t`~]*)\n([\s\S]*?)\n {0,3}\1/g, function (wholeMatch, delim, language, codeblock) {
var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
// if the language has spaces followed by some other chars, according to the spec we should just ignore everything
// after the first space
language = language.trim().split(' ')[0];
// First parse the github code block
codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals);
codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals);

View File

@ -0,0 +1,8 @@
<pre><code class="json language-json">{
"custom": true
}
</code></pre>
<pre><code class="json language-json">{
"custom": false
}
</code></pre>

View File

@ -0,0 +1,11 @@
```json custom data
{
"custom": true
}
```
```json custom data
{
"custom": false
}
```