Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[commonmark] make code fences compliant (+ fix 1058) #1387

Merged
merged 5 commits into from Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/marked.js
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+|$)|$)/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no more vulnerable than it previously was.

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) {
styfle marked this conversation as resolved.
Show resolved Hide resolved
var lang = (infostring || '').match(/\S*/)[0];
styfle marked this conversation as resolved.
Show resolved Hide resolved
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
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
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
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