|
|
@ -11,11 +11,11 @@ var isMdAsciiPunct = require('../common/utils').isMdAsciiPunct; |
|
|
|
// parse sequence of emphasis markers,
|
|
|
|
// "start" should point at a valid marker
|
|
|
|
function scanDelims(state, start) { |
|
|
|
var pos = start, lastChar, nextChar, count, |
|
|
|
var pos = start, lastChar, nextChar, count, can_open, can_close, |
|
|
|
isLastWhiteSpace, isLastPunctChar, |
|
|
|
isNextWhiteSpace, isNextPunctChar, |
|
|
|
can_open = true, |
|
|
|
can_close = true, |
|
|
|
left_flanking = true, |
|
|
|
right_flanking = true, |
|
|
|
max = state.posMax, |
|
|
|
marker = state.src.charCodeAt(start); |
|
|
|
|
|
|
@ -24,10 +24,6 @@ function scanDelims(state, start) { |
|
|
|
|
|
|
|
while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; } |
|
|
|
|
|
|
|
if (pos >= max) { |
|
|
|
can_open = false; |
|
|
|
} |
|
|
|
|
|
|
|
count = pos - start; |
|
|
|
|
|
|
|
// treat end of the line as a whitespace
|
|
|
@ -40,27 +36,28 @@ function scanDelims(state, start) { |
|
|
|
isNextWhiteSpace = isWhiteSpace(nextChar); |
|
|
|
|
|
|
|
if (isNextWhiteSpace) { |
|
|
|
can_open = false; |
|
|
|
left_flanking = false; |
|
|
|
} else if (isNextPunctChar) { |
|
|
|
if (!(isLastWhiteSpace || isLastPunctChar)) { |
|
|
|
can_open = false; |
|
|
|
left_flanking = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isLastWhiteSpace) { |
|
|
|
can_close = false; |
|
|
|
right_flanking = false; |
|
|
|
} else if (isLastPunctChar) { |
|
|
|
if (!(isNextWhiteSpace || isNextPunctChar)) { |
|
|
|
can_close = false; |
|
|
|
right_flanking = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (marker === 0x5F /* _ */) { |
|
|
|
if (can_open && can_close) { |
|
|
|
// "_" inside a word can neither open nor close an emphasis
|
|
|
|
can_open = false; |
|
|
|
can_close = isNextPunctChar; |
|
|
|
} |
|
|
|
// "_" inside a word can neither open nor close an emphasis
|
|
|
|
can_open = left_flanking && (!right_flanking || isLastPunctChar); |
|
|
|
can_close = right_flanking && (!left_flanking || isNextPunctChar); |
|
|
|
} else { |
|
|
|
can_open = left_flanking; |
|
|
|
can_close = right_flanking; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|