improve setext heading compliance

This commit is contained in:
Estevão Soares dos Santos 2022-11-15 03:55:16 +00:00
parent 42959b78c1
commit d080d30011

View File

@ -236,7 +236,6 @@
prepend = showdown.subParser('makehtml.blockquote')(line1, options, globals); prepend = showdown.subParser('makehtml.blockquote')(line1, options, globals);
if (prepend !== line1) { if (prepend !== line1) {
// it's an oneliner blockquote // it's an oneliner blockquote
return prepend.trim() + '\n' + line4; return prepend.trim() + '\n' + line4;
} }
} }
@ -302,11 +301,27 @@
nPrepend = showdown.subParser('makehtml.blockGamut')(multilineText, options, globals, 'makehtml.heading.setext'); nPrepend = showdown.subParser('makehtml.blockGamut')(multilineText, options, globals, 'makehtml.heading.setext');
if (nPrepend !== multilineText) { if (nPrepend !== multilineText) {
// we found a block, so it should take precedence // we found one or more blocks, so we need to reparse (blocks should take precendence though)
nPrepend = showdown.helper.trimEnd(nPrepend);
// let's check if the last line is a parsed block
let newLines = nPrepend.trim().split('\n');
let nLastLine = newLines.pop().toString();
if (/^¨K\d+K$/.test(nLastLine) || /^\s*$/gm.test(nLastLine)) {
// everything before --- or === is a block or empty line, so it's a false positive
prepend += nPrepend; prepend += nPrepend;
headingText = ''; headingText = '';
} else {
// the last line is something else... so let's look at the line before that
let toHeading = nLastLine;
nLastLine = newLines.pop().toString();
if (/^¨K\d+K$/.test(nLastLine) === false && /^\s*$/gm.test(nLastLine) === false) {
toHeading = nLastLine + '\n' + toHeading;
}
headingText = toHeading;
prepend = newLines.join('\n').trim();
}
} }
console.log(prepend);
} }
// trim stuff // trim stuff