Skip to content

Commit

Permalink
fix: fix multiline setext headings (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Nov 20, 2022
1 parent b7eea95 commit 4aee878
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/rules.js
Expand Up @@ -27,7 +27,7 @@ export const block = {
+ ')',
def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
table: noopTest,
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
lheading: /^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
// regex template, placeholders will be replaced according to different paragraph
// interruption rules of commonmark and the original markdown spec:
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
Expand Down Expand Up @@ -137,6 +137,7 @@ block.pedantic = merge({}, block.normal, {
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
heading: /^(#{1,6})(.*)(?:\n+|$)/,
fences: noopTest, // fences not supported
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
paragraph: edit(block.normal._paragraph)
.replace('hr', block.hr)
.replace('heading', ' *#{1,6} *[^\n]')
Expand Down
12 changes: 5 additions & 7 deletions test/specs/commonmark/commonmark.0.30.json
Expand Up @@ -647,17 +647,15 @@
"example": 81,
"start_line": 1365,
"end_line": 1372,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": " Foo *bar\nbaz*\t\n====\n",
"html": "<h1>Foo <em>bar\nbaz</em></h1>\n",
"example": 82,
"start_line": 1379,
"end_line": 1386,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "Foo\n-------------------------\n\nFoo\n=\n",
Expand Down Expand Up @@ -745,7 +743,8 @@
"example": 93,
"start_line": 1531,
"end_line": 1541,
"section": "Setext headings"
"section": "Setext headings",
"shouldFail": true
},
{
"markdown": "- Foo\n---\n",
Expand All @@ -761,8 +760,7 @@
"example": 95,
"start_line": 1559,
"end_line": 1566,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "---\nFoo\n---\nBar\n---\nBaz\n",
Expand Down
12 changes: 5 additions & 7 deletions test/specs/gfm/commonmark.0.30.json
Expand Up @@ -647,17 +647,15 @@
"example": 81,
"start_line": 1365,
"end_line": 1372,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": " Foo *bar\nbaz*\t\n====\n",
"html": "<h1>Foo <em>bar\nbaz</em></h1>\n",
"example": 82,
"start_line": 1379,
"end_line": 1386,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "Foo\n-------------------------\n\nFoo\n=\n",
Expand Down Expand Up @@ -745,7 +743,8 @@
"example": 93,
"start_line": 1531,
"end_line": 1541,
"section": "Setext headings"
"section": "Setext headings",
"shouldFail": true
},
{
"markdown": "- Foo\n---\n",
Expand All @@ -761,8 +760,7 @@
"example": 95,
"start_line": 1559,
"end_line": 1566,
"section": "Setext headings",
"shouldFail": true
"section": "Setext headings"
},
{
"markdown": "---\nFoo\n---\nBar\n---\nBaz\n",
Expand Down
13 changes: 0 additions & 13 deletions test/unit/Lexer-spec.js
Expand Up @@ -358,19 +358,6 @@ a | b
]
});
});

it('after line break does not consume raw \n', () => {
expectTokens({
md: 'T\nh\n---',
tokens:
jasmine.arrayContaining([
jasmine.objectContaining({
raw: 'T\nh\n'
}),
{ type: 'hr', raw: '---' }
])
});
});
});

describe('blockquote', () => {
Expand Down

1 comment on commit 4aee878

@vercel
Copy link

@vercel vercel bot commented on 4aee878 Nov 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.