Skip to content

Commit

Permalink
Merge pull request #1475 from Jocs/cm-example57and40
Browse files Browse the repository at this point in the history
fix: failed commonmark examples 57 and 40
  • Loading branch information
styfle authored Apr 18, 2019
2 parents 9a6ca19 + 0ec9fa9 commit 5d727cb
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 85 deletions.
23 changes: 15 additions & 8 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var block = {
+ ')',
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
table: noop,
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
lheading: /^([^\n]+)\n {0,3}(=|-){2,} *(?:\n+|$)/,
paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading| {0,3}>|<\/?(?:tag)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)/,
text: /^[^\n]+/
};
Expand Down Expand Up @@ -215,14 +215,21 @@ Lexer.prototype.token = function(src, top) {

// code
if (cap = this.rules.code.exec(src)) {
const lastToken = this.tokens[this.tokens.length - 1];
src = src.substring(cap[0].length);
cap = cap[0].replace(/^ {4}/gm, '');
this.tokens.push({
type: 'code',
text: !this.options.pedantic
? rtrim(cap, '\n')
: cap
});
// An indented code block cannot interrupt a paragraph.
if (lastToken && lastToken.type === 'paragraph') {
lastToken.text += `\n${cap[0].trimRight()}`;
} else {
cap = cap[0].replace(/^ {4}/gm, '');
this.tokens.push({
type: 'code',
codeBlockStyle: 'indented',
text: !this.options.pedantic
? rtrim(cap, '\n')
: cap
});
}
continue;
}

Expand Down
Loading

0 comments on commit 5d727cb

Please sign in to comment.