From e1f6e3b6f83fc5f5cca34cacb52deec1ebb04436 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Sun, 11 Jan 2015 16:04:59 +0300 Subject: [PATCH] Use new emphasis logic in strikethrough --- lib/rules_inline/emphasis.js | 3 ++- lib/rules_inline/strikethrough.js | 34 ++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/rules_inline/emphasis.js b/lib/rules_inline/emphasis.js index ceb687e..0fbfcbb 100644 --- a/lib/rules_inline/emphasis.js +++ b/lib/rules_inline/emphasis.js @@ -1,7 +1,8 @@ // Process *this* and _that_ - +// 'use strict'; + var isWhiteSpace = require('../common/utils').isWhiteSpace; var isPunctChar = require('../common/utils').isPunctChar; var isMdAsciiPunct = require('../common/utils').isMdAsciiPunct; diff --git a/lib/rules_inline/strikethrough.js b/lib/rules_inline/strikethrough.js index 13dad16..a7fd3e5 100644 --- a/lib/rules_inline/strikethrough.js +++ b/lib/rules_inline/strikethrough.js @@ -1,10 +1,19 @@ +// ~~strike through~~ +// 'use strict'; +var isWhiteSpace = require('../common/utils').isWhiteSpace; +var isPunctChar = require('../common/utils').isPunctChar; +var isMdAsciiPunct = require('../common/utils').isMdAsciiPunct; + + // parse sequence of markers, // "start" should point at a valid marker function scanDelims(state, start) { var pos = start, lastChar, nextChar, count, + isLastWhiteSpace, isLastPunctChar, + isNextWhiteSpace, isNextPunctChar, can_open = true, can_close = true, max = state.posMax, @@ -18,9 +27,28 @@ function scanDelims(state, start) { nextChar = pos < max ? state.src.charCodeAt(pos) : -1; - // check whitespace conditions - if (nextChar === 0x20 || nextChar === 0x0A) { can_open = false; } - if (lastChar === 0x20 || lastChar === 0x0A) { can_close = false; } + isLastPunctChar = lastChar >= 0 && + (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); + + if (isNextWhiteSpace) { + can_open = false; + } else if (isNextPunctChar) { + if (!(isLastWhiteSpace || isLastPunctChar || lastChar === -1)) { + can_open = false; + } + } + + if (isLastWhiteSpace) { + can_close = false; + } else if (isLastPunctChar) { + if (!(isNextWhiteSpace || isNextPunctChar || nextChar === -1)) { + can_close = false; + } + } return { can_open: can_open,