From 9235131045a982dceca484d58c99a5488a7c6f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Mon, 9 May 2022 02:38:41 +0100 Subject: [PATCH] some more compliance stuff --- src/subParsers/makehtml/blockGamut.js | 12 +++++++--- src/subParsers/makehtml/blockquote.js | 1 - src/subParsers/makehtml/heading.js | 24 ++++++++++++++++--- .../makehtml/extra.testsuite.commonmark.js | 5 +--- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/subParsers/makehtml/blockGamut.js b/src/subParsers/makehtml/blockGamut.js index c972022..e858ad0 100644 --- a/src/subParsers/makehtml/blockGamut.js +++ b/src/subParsers/makehtml/blockGamut.js @@ -10,9 +10,11 @@ //// -showdown.subParser('makehtml.blockGamut', function (text, options, globals) { +showdown.subParser('makehtml.blockGamut', function (text, options, globals, skip) { 'use strict'; + skip = skip || false; + let startEvent = new showdown.Event('makehtml.blockGamut.onStart', text); startEvent .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 // 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: - 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.codeBlock')(text, options, globals); diff --git a/src/subParsers/makehtml/blockquote.js b/src/subParsers/makehtml/blockquote.js index 5982da9..92bddae 100644 --- a/src/subParsers/makehtml/blockquote.js +++ b/src/subParsers/makehtml/blockquote.js @@ -34,7 +34,6 @@ showdown.subParser('makehtml.blockquote', function (text, options, globals) { let otp, attributes = {}, wholeMatch = bq; - bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines diff --git a/src/subParsers/makehtml/heading.js b/src/subParsers/makehtml/heading.js index 99b9af1..5f81022 100644 --- a/src/subParsers/makehtml/heading.js +++ b/src/subParsers/makehtml/heading.js @@ -85,14 +85,29 @@ showdown.subParser('makehtml.heading', function (text, options, globals) { // now check if it's an unordered list if (line1.match(/^ {0,3}[-*+][ \t]/)) { - - prepend = showdown.subParser('makehtml.blockGamut')(line1, options, globals); + if (line4.trim().match(/^=+/)) { + line1 += line4; + } + prepend = showdown.subParser('makehtml.list')(line1, options, globals); if (prepend !== line1) { // it's an oneliner list 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 } else { let multilineText = ''; @@ -148,8 +163,11 @@ showdown.subParser('makehtml.heading', function (text, options, globals) { // all edge cases should be treated now 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); if (nPrepend !== multilineText) { // we found a block, so it should take precedence diff --git a/test/functional/makehtml/extra.testsuite.commonmark.js b/test/functional/makehtml/extra.testsuite.commonmark.js index c080f88..1194f63 100644 --- a/test/functional/makehtml/extra.testsuite.commonmark.js +++ b/test/functional/makehtml/extra.testsuite.commonmark.js @@ -21,12 +21,9 @@ describe('makeHtml() commonmark testsuite', function () { let name = testsuite[section][i].name; switch (name) { case 'ATX headings_79': // empty headings don't make sense - case 'Setext headings_92': // lazy continuation is needed for compatibility - case 'Setext headings_93': // lazy continuation is needed for compatibility - case 'Setext headings_94': // 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 'Thematic breaks_43': // malformed input of test case 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; 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, '"')