From 7f8d3ebe82a5538eed282bedd5682c54611621b9 Mon Sep 17 00:00:00 2001
From: Alex Kocharin
Date: Mon, 9 Mar 2015 18:58:51 +0300
Subject: [PATCH] Update strikethrough scanDelims to match emphasis
---
lib/rules_inline/strikethrough.js | 16 +++++++++++-----
test/fixtures/markdown-it/strikethrough.txt | 8 ++++++++
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/lib/rules_inline/strikethrough.js b/lib/rules_inline/strikethrough.js
index 4f613b4..f54adfe 100644
--- a/lib/rules_inline/strikethrough.js
+++ b/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;
}
}
diff --git a/test/fixtures/markdown-it/strikethrough.txt b/test/fixtures/markdown-it/strikethrough.txt
index 45765a6..299dc3a 100644
--- a/test/fixtures/markdown-it/strikethrough.txt
+++ b/test/fixtures/markdown-it/strikethrough.txt
@@ -95,3 +95,11 @@ test~~
test
~~
.
+
+From CommonMark test suite, replacing `**` with our marker:
+
+.
+a~~"foo"~~
+.
+a~~“foo”~~
+.