Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix link reference definitions specs #2654

Merged
merged 1 commit into from Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Tokenizer.js
Expand Up @@ -365,14 +365,15 @@ export class Tokenizer {
def(src) {
const cap = this.rules.block.def.exec(src);
if (cap) {
if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
const href = cap[2] ? cap[2].replace(/^<(.*)>$/, '$1').replace(this.rules.inline._escapes, '$1') : '';
const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline._escapes, '$1') : cap[3];
return {
type: 'def',
tag,
raw: cap[0],
href: cap[2] ? cap[2].replace(this.rules.inline._escapes, '$1') : cap[2],
title: cap[3] ? cap[3].replace(this.rules.inline._escapes, '$1') : cap[3]
href,
title
};
}
}
Expand Down Expand Up @@ -574,7 +575,7 @@ export class Tokenizer {
|| (cap = this.rules.inline.nolink.exec(src))) {
let link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
link = links[link.toLowerCase()];
if (!link || !link.href) {
if (!link) {
const text = cap[0].charAt(0);
return {
type: 'text',
Expand Down
2 changes: 1 addition & 1 deletion src/rules.js
Expand Up @@ -25,7 +25,7 @@ export const block = {
+ '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
+ '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
+ ')',
def: /^ {0,3}\[(label)\]: *(?:\n *)?<?([^\s>]+)>?(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
table: noopTest,
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
// regex template, placeholders will be replaced according to different paragraph
Expand Down
6 changes: 2 additions & 4 deletions test/specs/commonmark/commonmark.0.30.json
Expand Up @@ -1564,8 +1564,7 @@
"example": 195,
"start_line": 3212,
"end_line": 3220,
"section": "Link reference definitions",
"shouldFail": true
"section": "Link reference definitions"
},
{
"markdown": "[foo]: /url '\ntitle\nline1\nline2\n'\n\n[foo]\n",
Expand Down Expand Up @@ -1605,8 +1604,7 @@
"example": 200,
"start_line": 3283,
"end_line": 3289,
"section": "Link reference definitions",
"shouldFail": true
"section": "Link reference definitions"
},
{
"markdown": "[foo]: <bar>(baz)\n\n[foo]\n",
Expand Down
6 changes: 2 additions & 4 deletions test/specs/gfm/commonmark.0.30.json
Expand Up @@ -1564,8 +1564,7 @@
"example": 195,
"start_line": 3212,
"end_line": 3220,
"section": "Link reference definitions",
"shouldFail": true
"section": "Link reference definitions"
},
{
"markdown": "[foo]: /url '\ntitle\nline1\nline2\n'\n\n[foo]\n",
Expand Down Expand Up @@ -1605,8 +1604,7 @@
"example": 200,
"start_line": 3283,
"end_line": 3289,
"section": "Link reference definitions",
"shouldFail": true
"section": "Link reference definitions"
},
{
"markdown": "[foo]: <bar>(baz)\n\n[foo]\n",
Expand Down