From 9dab0826c6040df081e130a27ed966f9cfe8a5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Tue, 15 Nov 2022 04:31:13 +0000 Subject: [PATCH] improve commonmark compliance --- src/subParsers/makehtml/encodeAmpsAndAngles.js | 3 +++ .../makehtml/escapeSpecialCharsWithinTagAttributes.js | 2 +- src/subParsers/makehtml/heading.js | 2 +- .../features/#320.github-compatible-generated-header-id.html | 4 +--- .../cases/features/rawHeaderId/with-prefixHeaderId.html | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/subParsers/makehtml/encodeAmpsAndAngles.js b/src/subParsers/makehtml/encodeAmpsAndAngles.js index f62ae0c..ca10eb7 100644 --- a/src/subParsers/makehtml/encodeAmpsAndAngles.js +++ b/src/subParsers/makehtml/encodeAmpsAndAngles.js @@ -33,6 +33,9 @@ showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, glob // Encode > text = text.replace(/>/g, '>'); + // encode " + text = text.replace(/"/g, '"'); + let afterEvent = new showdown.Event('makehtml.encodeAmpsAndAngles.onEnd', text); afterEvent .setOutput(text) diff --git a/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js b/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js index e2447c4..769f839 100644 --- a/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js +++ b/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js @@ -22,7 +22,7 @@ showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (t text = startEvent.output; // Build a regex to find HTML tags. - let tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi, + let tags = /<\/?[a-z\d_:-]+(?:\s+[\s\S]+?)?>/gi, comments = /-]|-[^>])([^-]|-[^-])*)--)>/gi; text = text.replace(tags, function (wholeMatch) { diff --git a/src/subParsers/makehtml/heading.js b/src/subParsers/makehtml/heading.js index d22ee42..8e8a3a9 100644 --- a/src/subParsers/makehtml/heading.js +++ b/src/subParsers/makehtml/heading.js @@ -309,7 +309,7 @@ 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 + '\n\n'; headingText = ''; } else { // the last line is something else... so let's look at the line before that diff --git a/test/functional/makehtml/cases/features/#320.github-compatible-generated-header-id.html b/test/functional/makehtml/cases/features/#320.github-compatible-generated-header-id.html index cea0af8..f0f4c2a 100644 --- a/test/functional/makehtml/cases/features/#320.github-compatible-generated-header-id.html +++ b/test/functional/makehtml/cases/features/#320.github-compatible-generated-header-id.html @@ -1,5 +1,3 @@

some header

- -

some header with &+$,/:;=?@\"#{}|^¨¿?:~[]`゠=…‥『』〝〟「」\*(){}()[]【】%.。,¡!!' chars

- +

some header with &+$,/:;=?@"#{}|^¨¿?:~[]`゠=…‥『』〝〟「」\*(){}()[]【】%.。,¡!!' chars

another header > with < chars

diff --git a/test/functional/makehtml/cases/features/rawHeaderId/with-prefixHeaderId.html b/test/functional/makehtml/cases/features/rawHeaderId/with-prefixHeaderId.html index 21ed9be..8145cc1 100644 --- a/test/functional/makehtml/cases/features/rawHeaderId/with-prefixHeaderId.html +++ b/test/functional/makehtml/cases/features/rawHeaderId/with-prefixHeaderId.html @@ -1,2 +1,2 @@

some header

-

another !"#$%&/()=?»@£§{[]}«' header

+

another !"#$%&/()=?»@£§{[]}«' header