diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb505a..decb77c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `[]()` is no longer a valid link. - `[](url (xxx())` is no longer a valid link. -- Fix performance issues when parsing links, #732. +- Fix performance issues when parsing links, #732, #734. - Fix performance issues when parsing backticks, #733. diff --git a/lib/rules_inline/link.js b/lib/rules_inline/link.js index 7c9834c..1d242bf 100644 --- a/lib/rules_inline/link.js +++ b/lib/rules_inline/link.js @@ -15,9 +15,9 @@ module.exports = function link(state, silent) { pos, res, ref, - title, token, href = '', + title = '', oldPos = state.pos, max = state.posMax, start = state.pos, @@ -60,31 +60,29 @@ module.exports = function link(state, silent) { } else { href = ''; } - } - - // [link]( "title" ) - // ^^ skipping these spaces - start = pos; - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos); - if (!isSpace(code) && code !== 0x0A) { break; } - } - - // [link]( "title" ) - // ^^^^^^^ parsing link title - res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); - if (pos < max && start !== pos && res.ok) { - title = res.str; - pos = res.pos; // [link]( "title" ) - // ^^ skipping these spaces + // ^^ skipping these spaces + start = pos; for (; pos < max; pos++) { code = state.src.charCodeAt(pos); if (!isSpace(code) && code !== 0x0A) { break; } } - } else { - title = ''; + + // [link]( "title" ) + // ^^^^^^^ parsing link title + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); + if (pos < max && start !== pos && res.ok) { + title = res.str; + pos = res.pos; + + // [link]( "title" ) + // ^^ skipping these spaces + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { break; } + } + } } if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) {