Browse Source

Improved reference scan efficiency, related to #54

pull/58/head
Vitaly Puzrin 10 years ago
parent
commit
43780be419
  1. 13
      lib/rules_block/reference.js

13
lib/rules_block/reference.js

@ -24,11 +24,22 @@ module.exports = function reference(state, startLine, _endLine, silent) {
title, title,
lines = 0, lines = 0,
pos = state.bMarks[startLine] + state.tShift[startLine], pos = state.bMarks[startLine] + state.tShift[startLine],
max, max = state.eMarks[startLine],
nextLine = startLine + 1; nextLine = startLine + 1;
if (state.src.charCodeAt(pos) !== 0x5B/* [ */) { return false; } if (state.src.charCodeAt(pos) !== 0x5B/* [ */) { return false; }
// Simple check to quickly interrupt scan on [link](url) at the start of line.
// Can be useful on practice: https://github.com/markdown-it/markdown-it/issues/54
while (++pos < max) {
if (state.src.charCodeAt(pos) === 0x5D /* ] */ &&
state.src.charCodeAt(pos - 1) !== 0x5C/* \ */) {
if (pos + 1 === max) { return false; }
if (state.src.charCodeAt(pos + 1) !== 0x3A/* : */) { return false; }
break;
}
}
endLine = state.lineMax; endLine = state.lineMax;
// jump line-by-line until empty one or EOF // jump line-by-line until empty one or EOF

Loading…
Cancel
Save