Skip to content

Commit

Permalink
Merge pull request #1387 from Feder1co5oave/fix-1058
Browse files Browse the repository at this point in the history
[commonmark] make code fences compliant (+ fix 1058)
  • Loading branch information
styfle authored Dec 10, 2018
2 parents 86214bb + ca52d38 commit 76d3733
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ block.normal = merge({}, block);
*/

block.gfm = merge({}, block.normal, {
fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\n? *\1 *(?:\n+|$)/,
fences: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
paragraph: /^/,
heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
});
Expand Down Expand Up @@ -231,7 +231,7 @@ Lexer.prototype.token = function(src, top) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'code',
lang: cap[2],
lang: cap[2] ? cap[2].trim() : cap[2],
text: cap[3] || ''
});
continue;
Expand Down Expand Up @@ -920,7 +920,8 @@ function Renderer(options) {
this.options = options || marked.defaults;
}

Renderer.prototype.code = function(code, lang, escaped) {
Renderer.prototype.code = function(code, infostring, escaped) {
var lang = (infostring || '').match(/\S*/)[0];
if (this.options.highlight) {
var out = this.options.highlight(code, lang);
if (out != null && out !== code) {
Expand Down
5 changes: 5 additions & 0 deletions test/new/gfm_code.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@


</code></pre>

<p>Closing fences must lay on a new line:</p>
<pre><code>hello()
^```
&quot;this should still be in the code block!&quot;</code></pre>
8 changes: 8 additions & 0 deletions test/new/gfm_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ ciao
```

Closing fences must lay on a new line:

```
hello()
^```
"this should still be in the code block!"
```
3 changes: 1 addition & 2 deletions test/specs/commonmark/commonmark-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ describe('CommonMark 0.28 Indented code blocks', function() {
describe('CommonMark 0.28 Fenced code blocks', function() {
var section = 'Fenced code blocks';

// var shouldPassButFails = [];
var shouldPassButFails = [93, 95, 96, 97, 106, 108, 112];
var shouldPassButFails = [];

var willNotBeAttemptedByCoreTeam = [];

Expand Down

0 comments on commit 76d3733

Please sign in to comment.