Browse Source

Bring emphasis up to spec

pull/82/head
Alex Kocharin 10 years ago
parent
commit
ecd010c020
  1. 23
      lib/rules_inline/emphasis.js

23
lib/rules_inline/emphasis.js

@ -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) {
@ -37,13 +31,15 @@ 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;
}
}
@ -51,15 +47,16 @@ function scanDelims(state, start) {
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 {

Loading…
Cancel
Save