From 805c69528d068e7db83a539c224b6a565e78f9de Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Thu, 10 Sep 2020 20:52:08 +0300 Subject: [PATCH] Fix smartquotes adjacent to code block close https://github.com/markdown-it/markdown-it/issues/677 --- lib/rules_core/smartquotes.js | 4 ++-- test/fixtures/markdown-it/smartquotes.txt | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/rules_core/smartquotes.js b/lib/rules_core/smartquotes.js index 155e7a614..e96fc7182 100644 --- a/lib/rules_core/smartquotes.js +++ b/lib/rules_core/smartquotes.js @@ -60,7 +60,7 @@ function process_inlines(tokens, state) { } else { for (j = i - 1; j >= 0; j--) { if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // lastChar defaults to 0x20 - if (tokens[j].type !== 'text') continue; + if (!tokens[j].content) continue; // should skip all tokens except 'text', 'html_inline' or 'code_inline' lastChar = tokens[j].content.charCodeAt(tokens[j].content.length - 1); break; @@ -77,7 +77,7 @@ function process_inlines(tokens, state) { } else { for (j = i + 1; j < tokens.length; j++) { if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // nextChar defaults to 0x20 - if (tokens[j].type !== 'text') continue; + if (!tokens[j].content) continue; // should skip all tokens except 'text', 'html_inline' or 'code_inline' nextChar = tokens[j].content.charCodeAt(0); break; diff --git a/test/fixtures/markdown-it/smartquotes.txt b/test/fixtures/markdown-it/smartquotes.txt index b7a563122..fdeb883ba 100644 --- a/test/fixtures/markdown-it/smartquotes.txt +++ b/test/fixtures/markdown-it/smartquotes.txt @@ -144,3 +144,23 @@ The dog---"'man's' best friend" .

The dog—“‘man’s’ best friend”

. + +Should parse quotes adjacent to code block, #677: +. +"test `code`" + +"`code` test" +. +

“test code

+

code test”

+. + +Should parse quotes adjacent to inline html, #677: +. +"test
" + +"
test" +. +

“test

+


test”

+.