|
|
@ -24,21 +24,16 @@ function scanDelims(state, start) { |
|
|
|
if (pos >= max) { can_open = false; } |
|
|
|
count = pos - start; |
|
|
|
|
|
|
|
if (count >= 4) { |
|
|
|
// sequence of four or more unescaped markers can't start/end an emphasis
|
|
|
|
can_open = can_close = false; |
|
|
|
} else { |
|
|
|
nextChar = pos < max ? state.src.charCodeAt(pos) : -1; |
|
|
|
|
|
|
|
// check whitespace conditions
|
|
|
|
if (nextChar === 0x20 || nextChar === 0x0A) { can_open = false; } |
|
|
|
if (lastChar === 0x20 || lastChar === 0x0A) { can_close = false; } |
|
|
|
|
|
|
|
if (marker === 0x5F /* _ */) { |
|
|
|
// check if we aren't inside the word
|
|
|
|
if (isAlphaNum(lastChar)) { can_open = false; } |
|
|
|
if (isAlphaNum(nextChar)) { can_close = false; } |
|
|
|
} |
|
|
|
nextChar = pos < max ? state.src.charCodeAt(pos) : -1; |
|
|
|
|
|
|
|
// check whitespace conditions
|
|
|
|
if (nextChar === 0x20 || nextChar === 0x0A) { can_open = false; } |
|
|
|
if (lastChar === 0x20 || lastChar === 0x0A) { can_close = false; } |
|
|
|
|
|
|
|
if (marker === 0x5F /* _ */) { |
|
|
|
// check if we aren't inside the word
|
|
|
|
if (isAlphaNum(lastChar)) { can_open = false; } |
|
|
|
if (isAlphaNum(nextChar)) { can_close = false; } |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
@ -126,19 +121,17 @@ module.exports = function emphasis(state, silent) { |
|
|
|
state.pos = start + startCount; |
|
|
|
|
|
|
|
if (!silent) { |
|
|
|
if (startCount === 2 || startCount === 3) { |
|
|
|
// we have `startCount` starting and ending markers,
|
|
|
|
// now trying to serialize them into tokens
|
|
|
|
for (count = startCount; count > 1; count -= 2) { |
|
|
|
state.push({ type: 'strong_open', level: state.level++ }); |
|
|
|
} |
|
|
|
if (startCount === 1 || startCount === 3) { |
|
|
|
state.push({ type: 'em_open', level: state.level++ }); |
|
|
|
} |
|
|
|
if (count % 2) { state.push({ type: 'em_open', level: state.level++ }); } |
|
|
|
|
|
|
|
state.parser.tokenize(state); |
|
|
|
|
|
|
|
if (startCount === 1 || startCount === 3) { |
|
|
|
state.push({ type: 'em_close', level: --state.level }); |
|
|
|
} |
|
|
|
if (startCount === 2 || startCount === 3) { |
|
|
|
if (count % 2) { state.push({ type: 'em_close', level: --state.level }); } |
|
|
|
for (count = startCount; count > 1; count -= 2) { |
|
|
|
state.push({ type: 'strong_close', level: --state.level }); |
|
|
|
} |
|
|
|
} |
|
|
|