Skip to content

Commit 4aee878

Browse files
authoredNov 20, 2022
fix: fix multiline setext headings (#2655)
1 parent b7eea95 commit 4aee878

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed
 

‎src/rules.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const block = {
2727
+ ')',
2828
def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
2929
table: noopTest,
30-
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
30+
lheading: /^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
3131
// regex template, placeholders will be replaced according to different paragraph
3232
// interruption rules of commonmark and the original markdown spec:
3333
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
@@ -137,6 +137,7 @@ block.pedantic = merge({}, block.normal, {
137137
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
138138
heading: /^(#{1,6})(.*)(?:\n+|$)/,
139139
fences: noopTest, // fences not supported
140+
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
140141
paragraph: edit(block.normal._paragraph)
141142
.replace('hr', block.hr)
142143
.replace('heading', ' *#{1,6} *[^\n]')

‎test/specs/commonmark/commonmark.0.30.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,15 @@
647647
"example": 81,
648648
"start_line": 1365,
649649
"end_line": 1372,
650-
"section": "Setext headings",
651-
"shouldFail": true
650+
"section": "Setext headings"
652651
},
653652
{
654653
"markdown": " Foo *bar\nbaz*\t\n====\n",
655654
"html": "<h1>Foo <em>bar\nbaz</em></h1>\n",
656655
"example": 82,
657656
"start_line": 1379,
658657
"end_line": 1386,
659-
"section": "Setext headings",
660-
"shouldFail": true
658+
"section": "Setext headings"
661659
},
662660
{
663661
"markdown": "Foo\n-------------------------\n\nFoo\n=\n",
@@ -745,7 +743,8 @@
745743
"example": 93,
746744
"start_line": 1531,
747745
"end_line": 1541,
748-
"section": "Setext headings"
746+
"section": "Setext headings",
747+
"shouldFail": true
749748
},
750749
{
751750
"markdown": "- Foo\n---\n",
@@ -761,8 +760,7 @@
761760
"example": 95,
762761
"start_line": 1559,
763762
"end_line": 1566,
764-
"section": "Setext headings",
765-
"shouldFail": true
763+
"section": "Setext headings"
766764
},
767765
{
768766
"markdown": "---\nFoo\n---\nBar\n---\nBaz\n",

‎test/specs/gfm/commonmark.0.30.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,15 @@
647647
"example": 81,
648648
"start_line": 1365,
649649
"end_line": 1372,
650-
"section": "Setext headings",
651-
"shouldFail": true
650+
"section": "Setext headings"
652651
},
653652
{
654653
"markdown": " Foo *bar\nbaz*\t\n====\n",
655654
"html": "<h1>Foo <em>bar\nbaz</em></h1>\n",
656655
"example": 82,
657656
"start_line": 1379,
658657
"end_line": 1386,
659-
"section": "Setext headings",
660-
"shouldFail": true
658+
"section": "Setext headings"
661659
},
662660
{
663661
"markdown": "Foo\n-------------------------\n\nFoo\n=\n",
@@ -745,7 +743,8 @@
745743
"example": 93,
746744
"start_line": 1531,
747745
"end_line": 1541,
748-
"section": "Setext headings"
746+
"section": "Setext headings",
747+
"shouldFail": true
749748
},
750749
{
751750
"markdown": "- Foo\n---\n",
@@ -761,8 +760,7 @@
761760
"example": 95,
762761
"start_line": 1559,
763762
"end_line": 1566,
764-
"section": "Setext headings",
765-
"shouldFail": true
763+
"section": "Setext headings"
766764
},
767765
{
768766
"markdown": "---\nFoo\n---\nBar\n---\nBaz\n",

‎test/unit/Lexer-spec.js

-13
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,6 @@ a | b
358358
]
359359
});
360360
});
361-
362-
it('after line break does not consume raw \n', () => {
363-
expectTokens({
364-
md: 'T\nh\n---',
365-
tokens:
366-
jasmine.arrayContaining([
367-
jasmine.objectContaining({
368-
raw: 'T\nh\n'
369-
}),
370-
{ type: 'hr', raw: '---' }
371-
])
372-
});
373-
});
374361
});
375362

376363
describe('blockquote', () => {

1 commit comments

Comments
 (1)

vercel[bot] commented on Nov 20, 2022

@vercel[bot]
Please sign in to comment.