|
@ -9,9 +9,28 @@ function processDelimiters(state, delimiters) { |
|
|
openersBottom = {}, |
|
|
openersBottom = {}, |
|
|
max = delimiters.length; |
|
|
max = delimiters.length; |
|
|
|
|
|
|
|
|
|
|
|
if (!max) return; |
|
|
|
|
|
|
|
|
|
|
|
// headerIdx is the first delimiter of the current (where closer is) delimiter run
|
|
|
|
|
|
var headerIdx = 0; |
|
|
|
|
|
var lastTokenIdx = -2; // needs any value lower than -1
|
|
|
|
|
|
var jumps = []; |
|
|
|
|
|
|
|
|
for (closerIdx = 0; closerIdx < max; closerIdx++) { |
|
|
for (closerIdx = 0; closerIdx < max; closerIdx++) { |
|
|
closer = delimiters[closerIdx]; |
|
|
closer = delimiters[closerIdx]; |
|
|
|
|
|
|
|
|
|
|
|
jumps.push(0); |
|
|
|
|
|
|
|
|
|
|
|
// markers belong to same delimiter run if:
|
|
|
|
|
|
// - they have adjacent tokens
|
|
|
|
|
|
// - AND markers are the same
|
|
|
|
|
|
//
|
|
|
|
|
|
if (delimiters[headerIdx].marker !== closer.marker || lastTokenIdx !== closer.token - 1) { |
|
|
|
|
|
headerIdx = closerIdx; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lastTokenIdx = closer.token; |
|
|
|
|
|
|
|
|
// Length is only used for emphasis-specific "rule of 3",
|
|
|
// Length is only used for emphasis-specific "rule of 3",
|
|
|
// if it's not defined (in strikethrough or 3rd party plugins),
|
|
|
// if it's not defined (in strikethrough or 3rd party plugins),
|
|
|
// we can default it to 0 to disable those checks.
|
|
|
// we can default it to 0 to disable those checks.
|
|
@ -30,14 +49,11 @@ function processDelimiters(state, delimiters) { |
|
|
|
|
|
|
|
|
minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + (closer.length % 3)]; |
|
|
minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + (closer.length % 3)]; |
|
|
|
|
|
|
|
|
openerIdx = closerIdx - closer.jump - 1; |
|
|
openerIdx = headerIdx - jumps[headerIdx] - 1; |
|
|
|
|
|
|
|
|
// avoid crash if `closer.jump` is pointing outside of the array, see #742
|
|
|
|
|
|
if (openerIdx < -1) openerIdx = -1; |
|
|
|
|
|
|
|
|
|
|
|
newMinOpenerIdx = openerIdx; |
|
|
newMinOpenerIdx = openerIdx; |
|
|
|
|
|
|
|
|
for (; openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) { |
|
|
for (; openerIdx > minOpenerIdx; openerIdx -= jumps[openerIdx] + 1) { |
|
|
opener = delimiters[openerIdx]; |
|
|
opener = delimiters[openerIdx]; |
|
|
|
|
|
|
|
|
if (opener.marker !== closer.marker) continue; |
|
|
if (opener.marker !== closer.marker) continue; |
|
@ -67,15 +83,19 @@ function processDelimiters(state, delimiters) { |
|
|
// sure algorithm has linear complexity (see *_*_*_*_*_... case).
|
|
|
// sure algorithm has linear complexity (see *_*_*_*_*_... case).
|
|
|
//
|
|
|
//
|
|
|
lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ? |
|
|
lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ? |
|
|
delimiters[openerIdx - 1].jump + 1 : |
|
|
jumps[openerIdx - 1] + 1 : |
|
|
0; |
|
|
0; |
|
|
|
|
|
|
|
|
closer.jump = closerIdx - openerIdx + lastJump; |
|
|
jumps[closerIdx] = closerIdx - openerIdx + lastJump; |
|
|
|
|
|
jumps[openerIdx] = lastJump; |
|
|
|
|
|
|
|
|
closer.open = false; |
|
|
closer.open = false; |
|
|
opener.end = closerIdx; |
|
|
opener.end = closerIdx; |
|
|
opener.jump = lastJump; |
|
|
|
|
|
opener.close = false; |
|
|
opener.close = false; |
|
|
newMinOpenerIdx = -1; |
|
|
newMinOpenerIdx = -1; |
|
|
|
|
|
// treat next token as start of run,
|
|
|
|
|
|
// it optimizes skips in **<...>**a**<...>** pathological case
|
|
|
|
|
|
lastTokenIdx = -2; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|