some more compliance stuff

This commit is contained in:
Estevão Soares dos Santos 2022-05-09 02:38:41 +01:00
parent aa12eabf1d
commit 9235131045
4 changed files with 31 additions and 11 deletions

View File

@ -10,9 +10,11 @@
//// ////
showdown.subParser('makehtml.blockGamut', function (text, options, globals) { showdown.subParser('makehtml.blockGamut', function (text, options, globals, skip) {
'use strict'; 'use strict';
skip = skip || false;
let startEvent = new showdown.Event('makehtml.blockGamut.onStart', text); let startEvent = new showdown.Event('makehtml.blockGamut.onStart', text);
startEvent startEvent
.setOutput(text) .setOutput(text)
@ -23,10 +25,14 @@ showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
// we parse blockquotes first so that we can have headings and hrs // we parse blockquotes first so that we can have headings and hrs
// inside blockquotes // inside blockquotes
text = showdown.subParser('makehtml.heading')(text, options, globals); if (skip !== 'makehtml.heading') {
text = showdown.subParser('makehtml.heading')(text, options, globals);
}
// Do Horizontal Rules: // Do Horizontal Rules:
text = showdown.subParser('makehtml.horizontalRule')(text, options, globals); if (skip !== 'makehtml.horizontalRule') {
text = showdown.subParser('makehtml.horizontalRule')(text, options, globals);
}
text = showdown.subParser('makehtml.list')(text, options, globals); text = showdown.subParser('makehtml.list')(text, options, globals);
text = showdown.subParser('makehtml.codeBlock')(text, options, globals); text = showdown.subParser('makehtml.codeBlock')(text, options, globals);

View File

@ -34,7 +34,6 @@ showdown.subParser('makehtml.blockquote', function (text, options, globals) {
let otp, let otp,
attributes = {}, attributes = {},
wholeMatch = bq; wholeMatch = bq;
bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting
bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines

View File

@ -85,14 +85,29 @@ showdown.subParser('makehtml.heading', function (text, options, globals) {
// now check if it's an unordered list // now check if it's an unordered list
if (line1.match(/^ {0,3}[-*+][ \t]/)) { if (line1.match(/^ {0,3}[-*+][ \t]/)) {
if (line4.trim().match(/^=+/)) {
prepend = showdown.subParser('makehtml.blockGamut')(line1, options, globals); line1 += line4;
}
prepend = showdown.subParser('makehtml.list')(line1, options, globals);
if (prepend !== line1) { if (prepend !== line1) {
// it's an oneliner list // it's an oneliner list
return prepend.trim() + '\n' + line4; return prepend.trim() + '\n' + line4;
} }
} }
// check if it's a blockquote
if (line1.match(/^ {0,3}>[ \t]?[^ \t]/)) {
if (line4.trim().match(/^=+/)) {
line1 += line4;
}
prepend = showdown.subParser('makehtml.blockquote')(line1, options, globals);
if (prepend !== line1) {
// it's an oneliner blockquote
return prepend.trim() + '\n' + line4;
}
}
// no edge case let's proceed as usual // no edge case let's proceed as usual
} else { } else {
let multilineText = ''; let multilineText = '';
@ -148,8 +163,11 @@ showdown.subParser('makehtml.heading', function (text, options, globals) {
// all edge cases should be treated now // all edge cases should be treated now
multilineText = line1 + line2 + ((line3) ? line3 : ''); multilineText = line1 + line2 + ((line3) ? line3 : '');
if (line4.trim().match(/^=+/)) {
multilineText += line4;
}
nPrepend = showdown.subParser('makehtml.blockGamut')(multilineText, options, globals); nPrepend = showdown.subParser('makehtml.blockGamut')(multilineText, options, globals, 'makehtml.heading');
//console.log(nPrepend); //console.log(nPrepend);
if (nPrepend !== multilineText) { if (nPrepend !== multilineText) {
// we found a block, so it should take precedence // we found a block, so it should take precedence

View File

@ -21,12 +21,9 @@ describe('makeHtml() commonmark testsuite', function () {
let name = testsuite[section][i].name; let name = testsuite[section][i].name;
switch (name) { switch (name) {
case 'ATX headings_79': // empty headings don't make sense case 'ATX headings_79': // empty headings don't make sense
case 'Setext headings_92': // lazy continuation is needed for compatibility case 'Setext headings_93': // spec says it cannot be lazy continuation but then proceeds to make it a lazy continuation.
case 'Setext headings_93': // lazy continuation is needed for compatibility
case 'Setext headings_94': // lazy continuation is needed for compatibility
case 'Thematic breaks_43': // malformed input of test case case 'Thematic breaks_43': // malformed input of test case
case 'Thematic breaks_61': // hr inside lists does not make sense case 'Thematic breaks_61': // hr inside lists does not make sense
//case 'Setext headings_101': // does not make sense because it's inconsistent with own spec. But I dunno?!? this one is weird
continue; continue;
case 'Setext headings_91': //it's failing because the testcase converts " to " even though it's not supposed to case 'Setext headings_91': //it's failing because the testcase converts " to " even though it's not supposed to
testsuite[section][i].expected = testsuite[section][i].expected.replace(/"/g, '"') testsuite[section][i].expected = testsuite[section][i].expected.replace(/"/g, '"')