Browse Source

Don't try to parse link title if link wasn't found

pull/745/head
Alex Kocharin 4 years ago
parent
commit
537ab89d7c
  1. 2
      CHANGELOG.md
  2. 38
      lib/rules_inline/link.js

2
CHANGELOG.md

@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- `[](<foo<bar>)` is no longer a valid link. - `[](<foo<bar>)` is no longer a valid link.
- `[](url (xxx())` 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. - Fix performance issues when parsing backticks, #733.

38
lib/rules_inline/link.js

@ -15,9 +15,9 @@ module.exports = function link(state, silent) {
pos, pos,
res, res,
ref, ref,
title,
token, token,
href = '', href = '',
title = '',
oldPos = state.pos, oldPos = state.pos,
max = state.posMax, max = state.posMax,
start = state.pos, start = state.pos,
@ -60,31 +60,29 @@ module.exports = function link(state, silent) {
} else { } else {
href = ''; href = '';
} }
}
// [link]( <href> "title" )
// ^^ skipping these spaces
start = pos;
for (; pos < max; pos++) {
code = state.src.charCodeAt(pos);
if (!isSpace(code) && code !== 0x0A) { break; }
}
// [link]( <href> "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]( <href> "title" ) // [link]( <href> "title" )
// ^^ skipping these spaces // ^^ skipping these spaces
start = pos;
for (; pos < max; pos++) { for (; pos < max; pos++) {
code = state.src.charCodeAt(pos); code = state.src.charCodeAt(pos);
if (!isSpace(code) && code !== 0x0A) { break; } if (!isSpace(code) && code !== 0x0A) { break; }
} }
} else {
title = ''; // [link]( <href> "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]( <href> "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/* ) */) { if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) {

Loading…
Cancel
Save