match setext headings just before paragraphs, then only paragraph continuations are matched inside blockquotes (see http://spec.commonmark.org/0.28/#example-197)

This commit is contained in:
Federico Soave 2018-01-10 01:52:33 +01:00
parent 1a71ae06bf
commit f45dc385d9

View File

@ -18,12 +18,12 @@ var block = {
hr: /^( *[-*_]){3,} *(?:\n+|$)/, hr: /^( *[-*_]){3,} *(?:\n+|$)/,
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
nptable: noop, nptable: noop,
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/, html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
table: noop, table: noop,
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
paragraph: /^([^\n]+(?:\n?(?!hr|heading|lheading| {0,3}>|tag)[^\n]+)+)/, paragraph: /^([^\n]+(?:\n?(?!hr|heading|lheading| {0,3}>|tag)[^\n]+)+)/,
text: /^[^\n]+/ text: /^[^\n]+/
}; };
@ -244,17 +244,6 @@ Lexer.prototype.token = function(src, top) {
continue; continue;
} }
// lheading
if (cap = this.rules.lheading.exec(src)) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'heading',
depth: cap[2] === '=' ? 1 : 2,
text: cap[1]
});
continue;
}
// hr // hr
if (cap = this.rules.hr.exec(src)) { if (cap = this.rules.hr.exec(src)) {
src = src.substring(cap[0].length); src = src.substring(cap[0].length);
@ -422,6 +411,17 @@ Lexer.prototype.token = function(src, top) {
continue; continue;
} }
// lheading
if (cap = this.rules.lheading.exec(src)) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'heading',
depth: cap[2] === '=' ? 1 : 2,
text: cap[1]
});
continue;
}
// top-level paragraph // top-level paragraph
if (top && (cap = this.rules.paragraph.exec(src))) { if (top && (cap = this.rules.paragraph.exec(src))) {
src = src.substring(cap[0].length); src = src.substring(cap[0].length);