Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,14 @@ const tag = edit(
.replace('attribute', /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/)
.getRegex();

const _inlineLabel = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
// One matched pair of brackets, holding no bracket of its own.
const _inlineLabelBrackets = /\[(?:\\[\s\S]|[^\[\]\\])*\]/;
// CommonMark lets the brackets in a link label nest to any depth, which a regex
// cannot follow, so it stops at a fixed one. Two levels is what the spec suite
// asks for: a third and a fourth flip no further example.
const _inlineLabel = edit(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/)
.replace('brackets', _inlineLabelBrackets)
.getRegex();

const link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/)
.replace('label', _inlineLabel)
Expand Down
9 changes: 3 additions & 6 deletions test/specs/commonmark/commonmark.0.31.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4096,8 +4096,7 @@
"example": 512,
"start_line": 7840,
"end_line": 7844,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link] bar](/uri)\n",
Expand Down Expand Up @@ -4161,8 +4160,7 @@
"example": 520,
"start_line": 7900,
"end_line": 7904,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "*[foo*](/uri)\n",
Expand Down Expand Up @@ -4228,8 +4226,7 @@
"example": 528,
"start_line": 8004,
"end_line": 8010,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link \\[bar][ref]\n\n[ref]: /uri\n",
Expand Down
9 changes: 3 additions & 6 deletions test/specs/gfm/commonmark.0.31.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4096,8 +4096,7 @@
"example": 512,
"start_line": 7840,
"end_line": 7844,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link] bar](/uri)\n",
Expand Down Expand Up @@ -4161,8 +4160,7 @@
"example": 520,
"start_line": 7900,
"end_line": 7904,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "*[foo*](/uri)\n",
Expand Down Expand Up @@ -4228,8 +4226,7 @@
"example": 528,
"start_line": 8004,
"end_line": 8010,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link \\[bar][ref]\n\n[ref]: /uri\n",
Expand Down