Skip to content

Commit

Permalink
fix: fix link reference definitions specs (#2654)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Nov 20, 2022
1 parent 36a2b63 commit b7eea95
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
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 @@ -1562,8 +1562,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 @@ -1603,8 +1602,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 @@ -1562,8 +1562,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 @@ -1603,8 +1602,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

1 comment on commit b7eea95

@vercel
Copy link

@vercel vercel bot commented on b7eea95 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.