diff --git a/src/Tokenizer.js b/src/Tokenizer.js index 564eb3015b..42064621b4 100644 --- a/src/Tokenizer.js +++ b/src/Tokenizer.js @@ -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 }; } } @@ -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', diff --git a/src/rules.js b/src/rules.js index 11bfbf4ef7..289c454304 100644 --- a/src/rules.js +++ b/src/rules.js @@ -25,7 +25,7 @@ export const block = { + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag + ')', - def: /^ {0,3}\[(label)\]: *(?:\n *)?]+)>?(?:(?: +(?:\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 diff --git a/test/specs/commonmark/commonmark.0.30.json b/test/specs/commonmark/commonmark.0.30.json index 261eb25c9e..b54bfb4edb 100644 --- a/test/specs/commonmark/commonmark.0.30.json +++ b/test/specs/commonmark/commonmark.0.30.json @@ -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", @@ -1605,8 +1604,7 @@ "example": 200, "start_line": 3283, "end_line": 3289, - "section": "Link reference definitions", - "shouldFail": true + "section": "Link reference definitions" }, { "markdown": "[foo]: (baz)\n\n[foo]\n", diff --git a/test/specs/gfm/commonmark.0.30.json b/test/specs/gfm/commonmark.0.30.json index 6cb2e60a50..1781c3fa05 100644 --- a/test/specs/gfm/commonmark.0.30.json +++ b/test/specs/gfm/commonmark.0.30.json @@ -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", @@ -1605,8 +1604,7 @@ "example": 200, "start_line": 3283, "end_line": 3289, - "section": "Link reference definitions", - "shouldFail": true + "section": "Link reference definitions" }, { "markdown": "[foo]: (baz)\n\n[foo]\n",