Skip to content

Commit 2342586

Browse files
committed
fix: also drop a leading tab after a hard line break
The rule only consumed spaces, so a continuation line indented with a tab kept it. Both the reference implementation and markdown-it drop tabs there as well.
1 parent 1142dbb commit 2342586

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎src/rules.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ const blockPedantic: Record<BlockKeys, RegExp> = {
282282

283283
const escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
284284
const inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
285-
const br = /^( {2,}|\\)\n(?!\s*$) */;
285+
const br = /^( {2,}|\\)\n(?!\s*$)[ \t]*/;
286286
const inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
287287

288288
// list of unicode punctuation marks, plus any missing characters from CommonMark spec

‎test/unit/marked.test.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ describe('marked unit', () => {
3131
assert.strictEqual(marked.parse('foo\\\n bar\n'), '<p>foo<br>bar</p>\n');
3232
});
3333

34+
it('should drop a leading tab as well', () => {
35+
assert.strictEqual(marked.parse('foo \n\tbar\n'), '<p>foo<br>bar</p>\n');
36+
});
37+
38+
it('should drop a mix of spaces and tabs', () => {
39+
assert.strictEqual(marked.parse('foo \n \t bar\n'), '<p>foo<br>bar</p>\n');
40+
});
41+
42+
it('should keep the leading tab of a soft break', () => {
43+
assert.strictEqual(marked.parse('foo\n\tbar\n'), '<p>foo\n\tbar</p>\n');
44+
});
45+
3446
it('should keep a soft break unchanged', () => {
3547
assert.strictEqual(marked.parse('foo\nbar\n'), '<p>foo\nbar</p>\n');
3648
});

0 commit comments

Comments
 (0)