Skip to content

Commit dd26af8

Browse files
committed
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 943d995 whose root cause was paragraph rendering not up to spec.
1 parent 4d5cfc7 commit dd26af8

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/marked.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ if (NEW_TEXT) {
534534
// we break the definition of GFM inline.breaks further down (affects the gfm_break test).
535535
// Furthermore, we still have trouble with the email pattern substituted in: /|[...]+@/, which
536536
// is vulnerable to REDOS just like /| {2,}\n/ was
537-
inline.text = /[\s\S](?:[\\<!\[`*]|\b_| \n|$)/;
537+
inline.text = /[\s\S](?:[\\<!\[`*]|\b_| {2}\n|$)/;
538538
}
539539

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

963963
Renderer.prototype.paragraph = function(text) {
964-
return '<p>' + text + '</p>\n';
964+
var lines = text.split(/\n/);
965+
lines = lines.map(function(l) {
966+
return l.replace(/^ +/, '');
967+
});
968+
969+
return '<p>' + lines.join('\n') + '</p>\n';
965970
};
966971

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

1393-
13941398
/**
13951399
* Marked
13961400
*/

test/specs/commonmark/commonmark-spec.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ describe('CommonMark 0.28 Precedence', function() {
9494
describe('CommonMark 0.28 Thematic breaks', function() {
9595
var section = 'Thematic breaks';
9696

97-
// var shouldPassButFails = [];
98-
var shouldPassButFails = [19];
97+
var shouldPassButFails = [];
9998

10099
var willNotBeAttemptedByCoreTeam = [];
101100

@@ -109,8 +108,7 @@ describe('CommonMark 0.28 Thematic breaks', function() {
109108
describe('CommonMark 0.28 ATX headings', function() {
110109
var section = 'ATX headings';
111110

112-
// var shouldPassButFails = [];
113-
var shouldPassButFails = [40];
111+
var shouldPassButFails = [];
114112

115113
var willNotBeAttemptedByCoreTeam = [];
116114

@@ -139,8 +137,7 @@ describe('CommonMark 0.28 Setext headings', function() {
139137
describe('CommonMark 0.28 Indented code blocks', function() {
140138
var section = 'Indented code blocks';
141139

142-
// var shouldPassButFails = [];
143-
var shouldPassButFails = [82];
140+
var shouldPassButFails = [];
144141

145142
var willNotBeAttemptedByCoreTeam = [];
146143

@@ -198,8 +195,7 @@ describe('CommonMark 0.28 Link reference definitions', function() {
198195
describe('CommonMark 0.28 Paragraphs', function() {
199196
var section = 'Paragraphs';
200197

201-
// var shouldPassButFails = [];
202-
var shouldPassButFails = [185, 186];
198+
var shouldPassButFails = [];
203199

204200
var willNotBeAttemptedByCoreTeam = [];
205201

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

321317
// var shouldPassButFails = [];
322-
var shouldPassButFails = [330, 316, 328, 320, 323, 322];
318+
var shouldPassButFails = [330, 316, 318, 328, 320, 323, 322];
323319

324320
var willNotBeAttemptedByCoreTeam = [];
325321

@@ -349,7 +345,7 @@ describe('CommonMark 0.28 Links', function() {
349345
var section = 'Links';
350346

351347
// var shouldPassButFails = [];
352-
var shouldPassButFails = [468, 474, 478, 483, 489, 490, 491, 492, 495, 496, 497, 499, 503, 504, 505, 507, 508, 509, 523, 535];
348+
var shouldPassButFails = [468, 474, 478, 483, 489, 490, 491, 492, 495, 496, 497, 499, 503, 504, 505, 507, 508, 509, 535];
353349

354350
var willNotBeAttemptedByCoreTeam = [];
355351

0 commit comments

Comments
 (0)