Skip to content

Commit

Permalink
remove leading whitespace in paragraphs
Browse files Browse the repository at this point in the history
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 943d995
whose root cause was paragraph rendering not up to spec.
  • Loading branch information
davisjam committed Apr 27, 2018
1 parent 4d5cfc7 commit dd26af8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 7 additions & 3 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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](?:[\\<!\[`*]|\b_| \n|$)/;
inline.text = /[\s\S](?:[\\<!\[`*]|\b_| {2}\n|$)/;
}

inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
Expand Down Expand Up @@ -961,7 +961,12 @@ Renderer.prototype.listitem = function(text) {
};

Renderer.prototype.paragraph = function(text) {
return '<p>' + text + '</p>\n';
var lines = text.split(/\n/);
lines = lines.map(function(l) {
return l.replace(/^ +/, '');
});

return '<p>' + lines.join('\n') + '</p>\n';
};

Renderer.prototype.table = function(header, body) {
Expand Down Expand Up @@ -1390,7 +1395,6 @@ function rtrim(str, c, allButC) {
return str.substr(0, curr);
}


/**
* Marked
*/
Expand Down
16 changes: 6 additions & 10 deletions test/specs/commonmark/commonmark-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ 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 willNotBeAttemptedByCoreTeam = [];

Expand All @@ -109,8 +108,7 @@ 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 willNotBeAttemptedByCoreTeam = [];

Expand Down Expand Up @@ -139,8 +137,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 = [];

Expand Down Expand Up @@ -198,8 +195,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 = [];

Expand Down Expand Up @@ -319,7 +315,7 @@ describe('CommonMark 0.28 Code spans', function() {
var section = 'Code spans';

// var shouldPassButFails = [];
var shouldPassButFails = [330, 316, 328, 320, 323, 322];
var shouldPassButFails = [330, 316, 318, 328, 320, 323, 322];

var willNotBeAttemptedByCoreTeam = [];

Expand Down Expand Up @@ -349,7 +345,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 = [];

Expand Down

0 comments on commit dd26af8

Please sign in to comment.