Browse Source

Update emphasis to match CommonMark 0.19

pull/104/head
Alex Kocharin 10 years ago
parent
commit
25fea504f6
  1. 27
      lib/rules_inline/emphasis.js

27
lib/rules_inline/emphasis.js

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

Loading…
Cancel
Save