Skip to content

Commit

Permalink
Bring emphasis up to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Mar 2, 2015
1 parent 8da8eff commit ecd010c
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/rules_inline/emphasis.js
Expand Up @@ -8,12 +8,6 @@ var isPunctChar = require('../common/utils').isPunctChar;
var isMdAsciiPunct = require('../common/utils').isMdAsciiPunct;


function isAlphaNum(code) {
return (code >= 0x30 /* 0 */ && code <= 0x39 /* 9 */) ||
(code >= 0x41 /* A */ && code <= 0x5A /* Z */) ||
(code >= 0x61 /* a */ && code <= 0x7A /* z */);
}

// parse sequence of emphasis markers,
// "start" should point at a valid marker
function scanDelims(state, start) {
Expand All @@ -37,29 +31,32 @@ function scanDelims(state, start) {
(isMdAsciiPunct(lastChar) || isPunctChar(String.fromCharCode(lastChar)));
isNextPunctChar = nextChar >= 0 &&
(isMdAsciiPunct(nextChar) || isPunctChar(String.fromCharCode(nextChar)));
isLastWhiteSpace = lastChar >= 0 && isWhiteSpace(lastChar);
isNextWhiteSpace = nextChar >= 0 && isWhiteSpace(nextChar);

// begin/end of the line counts as a whitespace too
isLastWhiteSpace = lastChar < 0 || isWhiteSpace(lastChar);
isNextWhiteSpace = nextChar < 0 || isWhiteSpace(nextChar);

if (isNextWhiteSpace) {
can_open = false;
} else if (isNextPunctChar) {
if (!(isLastWhiteSpace || isLastPunctChar || lastChar === -1)) {
if (!(isLastWhiteSpace || isLastPunctChar)) {
can_open = false;
}
}

if (isLastWhiteSpace) {
can_close = false;
} else if (isLastPunctChar) {
if (!(isNextWhiteSpace || isNextPunctChar || nextChar === -1)) {
if (!(isNextWhiteSpace || isNextPunctChar)) {
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; }
if (can_open && can_close) {
// "_" inside a word can neither open nor close an emphasis
can_open = can_close = false;
}
}

return {
Expand Down

0 comments on commit ecd010c

Please sign in to comment.