Browse Source

Update strikethrough scanDelims to match emphasis

pull/82/head
Alex Kocharin 10 years ago
parent
commit
7f8d3ebe82
  1. 16
      lib/rules_inline/strikethrough.js
  2. 8
      test/fixtures/markdown-it/strikethrough.txt

16
lib/rules_inline/strikethrough.js

@ -22,7 +22,11 @@ function scanDelims(state, start) {
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; }
if (pos >= max) { can_open = false; }
if (pos >= max) {
can_open = false;
}
count = pos - start;
nextChar = pos < max ? state.src.charCodeAt(pos) : -1;
@ -31,13 +35,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;
}
}
@ -45,7 +51,7 @@ function scanDelims(state, start) {
if (isLastWhiteSpace) {
can_close = false;
} else if (isLastPunctChar) {
if (!(isNextWhiteSpace || isNextPunctChar || nextChar === -1)) {
if (!(isNextWhiteSpace || isNextPunctChar)) {
can_close = false;
}
}

8
test/fixtures/markdown-it/strikethrough.txt

@ -95,3 +95,11 @@ test~~</p>
test
~~</p>
.
From CommonMark test suite, replacing `**` with our marker:
.
a~~"foo"~~
.
<p>a~~“foo”~~</p>
.

Loading…
Cancel
Save