Skip to content

Commit

Permalink
Don't try to parse link title if link wasn't found
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Nov 23, 2020
1 parent 77cccb8 commit 537ab89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- `[](<foo<bar>)` 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.


Expand Down
38 changes: 18 additions & 20 deletions lib/rules_inline/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -60,31 +60,29 @@ module.exports = function link(state, silent) {
} else {
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" )
// ^^ 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]( <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/* ) */) {
Expand Down

0 comments on commit 537ab89

Please sign in to comment.