From 04d36a3f1aceffc3290f777929af82540b9577a4 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Tue, 6 Feb 2018 12:59:12 +0000 Subject: [PATCH] Fix smartquotes around softbreaks close https://github.com/markdown-it/markdown-it/issues/430 --- lib/rules_core/smartquotes.js | 6 +++-- test/fixtures/markdown-it/smartquotes.txt | 28 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/rules_core/smartquotes.js b/lib/rules_core/smartquotes.js index e599990ee..bff7ef76b 100644 --- a/lib/rules_core/smartquotes.js +++ b/lib/rules_core/smartquotes.js @@ -59,7 +59,8 @@ function process_inlines(tokens, state) { lastChar = text.charCodeAt(t.index - 1); } else { for (j = i - 1; j >= 0; j--) { - if (tokens[j].type !== 'text') { continue; } + if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // lastChar defaults to 0x20 + if (tokens[j].type !== 'text') continue; lastChar = tokens[j].content.charCodeAt(tokens[j].content.length - 1); break; @@ -75,7 +76,8 @@ function process_inlines(tokens, state) { nextChar = text.charCodeAt(pos); } else { for (j = i + 1; j < tokens.length; j++) { - if (tokens[j].type !== 'text') { continue; } + if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // nextChar defaults to 0x20 + if (tokens[j].type !== 'text') continue; nextChar = tokens[j].content.charCodeAt(0); break; diff --git a/test/fixtures/markdown-it/smartquotes.txt b/test/fixtures/markdown-it/smartquotes.txt index 7b62307ec..9763333a2 100644 --- a/test/fixtures/markdown-it/smartquotes.txt +++ b/test/fixtures/markdown-it/smartquotes.txt @@ -109,3 +109,31 @@ Quotes at the start/end of the tokens:

“foo bar

foo bar

. + +Should treat softbreak as a space: +. +"this" +and "that". + +"this" and +"that". +. +

“this” +and “that”.

+

“this” and +“that”.

+. + +Should treat hardbreak as a space: +. +"this"\ +and "that". + +"this" and\ +"that". +. +

“this”
+and “that”.

+

“this” and
+“that”.

+.