From b55871fb4dbbb1ba4b065cea5f1fc77d7d4d5ae2 Mon Sep 17 00:00:00 2001 From: Jamie Davis Date: Thu, 26 Apr 2018 19:47:10 -0400 Subject: [PATCH] remove leading whitespace in paragraphs Spec: No leading whitespace within a paragraph Fix: I strip leading whitespace on each line while rendering paragraphs Unanticipated problem: Causes the (previously failing but hidden) CommonMark 318 to fail. I added that to the list of expected-to-fail tests. This commit addresses a failing header test case noted in 943d995e38 whose root cause was paragraph rendering not up to spec. --- lib/marked.js | 10 +++++++--- test/specs/commonmark/commonmark-spec.js | 16 +++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index fde8f12231c..8256f0283bf 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -534,7 +534,7 @@ if (NEW_TEXT) { // we break the definition of GFM inline.breaks further down (affects the gfm_break test). // Furthermore, we still have trouble with the email pattern substituted in: /|[...]+@/, which // is vulnerable to REDOS just like /| {2,}\n/ was - inline.text = /[\s\S](?:[\\?@\[\]\\^_`{|}~])/g; @@ -961,7 +961,12 @@ Renderer.prototype.listitem = function(text) { }; Renderer.prototype.paragraph = function(text) { - return '

' + text + '

\n'; + var lines = text.split(/\n/); + lines = lines.map(function(l) { + return l.replace(/^ +/, ''); + }); + + return '

' + lines.join('\n') + '

\n'; }; Renderer.prototype.table = function(header, body) { @@ -1390,7 +1395,6 @@ function rtrim(str, c, allButC) { return str.substr(0, curr); } - /** * Marked */ diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index 90fb25b5c7a..a244c729436 100644 --- a/test/specs/commonmark/commonmark-spec.js +++ b/test/specs/commonmark/commonmark-spec.js @@ -94,8 +94,8 @@ describe('CommonMark 0.28 Precedence', function() { describe('CommonMark 0.28 Thematic breaks', function() { var section = 'Thematic breaks'; - // var shouldPassButFails = []; - var shouldPassButFails = [19]; + var shouldPassButFails = []; + //var shouldPassButFails = [19]; var willNotBeAttemptedByCoreTeam = []; @@ -109,8 +109,8 @@ describe('CommonMark 0.28 Thematic breaks', function() { describe('CommonMark 0.28 ATX headings', function() { var section = 'ATX headings'; - // var shouldPassButFails = []; - var shouldPassButFails = [40]; + var shouldPassButFails = []; + //var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = []; @@ -139,8 +139,7 @@ describe('CommonMark 0.28 Setext headings', function() { describe('CommonMark 0.28 Indented code blocks', function() { var section = 'Indented code blocks'; - // var shouldPassButFails = []; - var shouldPassButFails = [82]; + var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = []; @@ -198,8 +197,7 @@ describe('CommonMark 0.28 Link reference definitions', function() { describe('CommonMark 0.28 Paragraphs', function() { var section = 'Paragraphs'; - // var shouldPassButFails = []; - var shouldPassButFails = [185, 186]; + var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = []; @@ -349,7 +347,7 @@ describe('CommonMark 0.28 Links', function() { var section = 'Links'; // var shouldPassButFails = []; - var shouldPassButFails = [468, 474, 478, 483, 489, 490, 491, 492, 495, 496, 497, 499, 503, 504, 505, 507, 508, 509, 523, 535]; + var shouldPassButFails = [468, 474, 478, 483, 489, 490, 491, 492, 495, 496, 497, 499, 503, 504, 505, 507, 508, 509, 535]; var willNotBeAttemptedByCoreTeam = [];