Browse Source

Fix: "\*" isn't a part of a emphasis marker sequence

pull/14/head
Alex Kocharin 10 years ago
parent
commit
3afaf55344
  1. 34
      lib/lexer_inline/emphasis.js

34
lib/lexer_inline/emphasis.js

@ -9,8 +9,11 @@ function isAlphaNum(code) {
(code >= 0x61 /* a */ && code <= 0x7A /* z */);
}
// returns the amount of markers (1, 2, 3), or -1 on failure;
// returns the amount of markers (1, 2, 3, 4+), or -1 on failure;
// "start" should point at a valid marker
//
// note: in case if 4+ markers it is still not a valid emphasis,
// should be treated as a special case
function parseStart(state, start) {
var pos = start, lastChar, count,
max = Math.min(state.posMax, pos + 4),
@ -35,7 +38,7 @@ function parseStart(state, start) {
if (count >= 4) {
// check condition 1
// sequence of four or more unescaped markers can't start an emphasis
return -1;
return count;
}
// check condition 2, marker followed by whitespace
@ -50,8 +53,11 @@ function parseStart(state, start) {
return count;
}
// returns the amount of markers (1, 2, 3), or -1 on failure;
// returns the amount of markers (1, 2, 3, 4+), or -1 on failure;
// "start" should point at a valid marker
//
// note: in case if 4+ markers it is still not a valid emphasis,
// should be treated as a special case
function parseEnd(state, start) {
var pos = start, lastChar, count,
max = Math.min(state.posMax, pos + 4),
@ -59,8 +65,6 @@ function parseEnd(state, start) {
lastChar = state.pending.length !== 0 ? state.pending.charCodeAt(state.pending.length - 1) : -1;
if (lastChar === marker) { return -1; }
while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; }
count = pos - start;
@ -74,7 +78,7 @@ function parseEnd(state, start) {
if (count >= 4) {
// check condition 1
// sequence of four or more unescaped markers can't start an emphasis
return -1;
return count;
}
// check condition 2, marker preceded by whitespace
@ -104,12 +108,18 @@ module.exports = function emphasis(state/*, silent*/) {
breakOutOfOuterLoop,
max = state.posMax,
start = state.pos,
haveLiteralAsterisk,
marker = state.src.charCodeAt(start);
if (marker !== 0x5F/* _ */ && marker !== 0x2A /* * */) { return false; }
startCount = parseStart(state, start);
if (startCount < 0) { return false; }
if (startCount >= 4) {
state.pos += startCount;
state.pending += state.src.slice(start, startCount);
return true;
}
oldLength = state.tokens.length;
oldPending = state.pending;
@ -120,9 +130,9 @@ module.exports = function emphasis(state/*, silent*/) {
len = rules.length;
while (state.pos < max) {
if (state.src.charCodeAt(state.pos) === marker) {
if (state.src.charCodeAt(state.pos) === marker && !haveLiteralAsterisk) {
count = parseEnd(state, state.pos);
if (count >= 1) {
if (count >= 1 && count < 4) {
oldCount = stack.pop();
newCount = count;
@ -176,7 +186,13 @@ module.exports = function emphasis(state/*, silent*/) {
if (ok) { break; }
}
if (!ok) { state.pending += state.src[state.pos++]; }
if (ok) {
haveLiteralAsterisk = false;
} else {
haveLiteralAsterisk = state.src.charCodeAt(state.pos) === marker;
state.pending += state.src[state.pos];
state.pos++;
}
}
// restore old state

Loading…
Cancel
Save