diff --git a/lib/helpers/parse_link_destination.js b/lib/helpers/parse_link_destination.js index bbaa74fdf..e9d575d95 100644 --- a/lib/helpers/parse_link_destination.js +++ b/lib/helpers/parse_link_destination.js @@ -3,7 +3,8 @@ 'use strict'; -var unescapeAll = require('../common/utils').unescapeAll; +var isSpace = require('../common/utils').isSpace; +var unescapeAll = require('../common/utils').unescapeAll; module.exports = function parseLinkDestination(str, pos, max) { @@ -21,7 +22,7 @@ module.exports = function parseLinkDestination(str, pos, max) { pos++; while (pos < max) { code = str.charCodeAt(pos); - if (code === 0x0A /* \n */) { return result; } + if (code === 0x0A /* \n */ || isSpace(code)) { return result; } if (code === 0x3E /* > */) { result.pos = pos + 1; result.str = unescapeAll(str.slice(start + 1, pos)); diff --git a/lib/rules_inline/image.js b/lib/rules_inline/image.js index e189d51ed..8d5c7a3ec 100644 --- a/lib/rules_inline/image.js +++ b/lib/rules_inline/image.js @@ -100,13 +100,6 @@ module.exports = function image(state, silent) { // if (typeof state.env.references === 'undefined') { return false; } - // [foo] [bar] - // ^^ optional whitespace (can include newlines) - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos); - if (!isSpace(code) && code !== 0x0A) { break; } - } - if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { start = pos + 1; pos = parseLinkLabel(state, pos); diff --git a/lib/rules_inline/link.js b/lib/rules_inline/link.js index b4a8808c1..e7fd35d71 100644 --- a/lib/rules_inline/link.js +++ b/lib/rules_inline/link.js @@ -97,13 +97,6 @@ module.exports = function link(state, silent) { // if (typeof state.env.references === 'undefined') { return false; } - // [foo] [bar] - // ^^ optional whitespace (can include newlines) - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos); - if (!isSpace(code) && code !== 0x0A) { break; } - } - if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { start = pos + 1; pos = parseLinkLabel(state, pos); diff --git a/test/fixtures/commonmark/bad.txt b/test/fixtures/commonmark/bad.txt index 2fe2705f2..94b7097d4 100644 --- a/test/fixtures/commonmark/bad.txt +++ b/test/fixtures/commonmark/bad.txt @@ -55,90 +55,6 @@ error: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 7098 - -. -[link]() -. -

[link](</my uri>)

-. - -error: - -

link

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 7614 - -. -[foo] [bar] - -[bar]: /url "title" -. -

[foo] bar

-. - -error: - -

foo

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 7623 - -. -[foo] -[bar] - -[bar]: /url "title" -. -

[foo] -bar

-. - -error: - -

foo

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 7809 - -. -[foo] -[] - -[foo]: /url "title" -. -

foo -[]

-. - -error: - -

foo

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 8111 - -. -![foo] -[] - -[foo]: /url "title" -. -

foo -[]

-. - -error: - -

foo

- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 8248 diff --git a/test/fixtures/commonmark/good.txt b/test/fixtures/commonmark/good.txt index b0965dffa..cb96b727a 100644 --- a/test/fixtures/commonmark/good.txt +++ b/test/fixtures/commonmark/good.txt @@ -5746,6 +5746,15 @@ src line: 7091

[link](/my uri)

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 7098 + +. +[link]() +. +

[link](</my uri>)

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 7105 @@ -6224,6 +6233,30 @@ src line: 7601

Baz

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 7614 + +. +[foo] [bar] + +[bar]: /url "title" +. +

[foo] bar

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 7623 + +. +[foo] +[bar] + +[bar]: /url "title" +. +

[foo] +bar

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 7664 @@ -6367,6 +6400,19 @@ src line: 7796

Foo

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 7809 + +. +[foo] +[] + +[foo]: /url "title" +. +

foo +[]

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 7829 @@ -6653,6 +6699,19 @@ src line: 8099

Foo

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 8111 + +. +![foo] +[] + +[foo]: /url "title" +. +

foo +[]

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 8124