Browse Source

Fix smartquotes adjacent to code block

close https://github.com/markdown-it/markdown-it/issues/677
pull/713/head
Alex Kocharin 4 years ago
parent
commit
805c69528d
  1. 4
      lib/rules_core/smartquotes.js
  2. 20
      test/fixtures/markdown-it/smartquotes.txt

4
lib/rules_core/smartquotes.js

@ -60,7 +60,7 @@ function process_inlines(tokens, state) {
} else { } else {
for (j = i - 1; j >= 0; j--) { 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 === '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); lastChar = tokens[j].content.charCodeAt(tokens[j].content.length - 1);
break; break;
@ -77,7 +77,7 @@ function process_inlines(tokens, state) {
} else { } else {
for (j = i + 1; j < tokens.length; j++) { 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 === '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); nextChar = tokens[j].content.charCodeAt(0);
break; break;

20
test/fixtures/markdown-it/smartquotes.txt

@ -144,3 +144,23 @@ The dog---"'man's' best friend"
. .
<p>The dog—“‘man’s’ best friend”</p> <p>The dog—“‘man’s’ best friend”</p>
. .
Should parse quotes adjacent to code block, #677:
.
"test `code`"
"`code` test"
.
<p>“test <code>code</code>”</p>
<p>“<code>code</code> test”</p>
.
Should parse quotes adjacent to inline html, #677:
.
"test <br>"
"<br> test"
.
<p>“test <br>”</p>
<p>“<br> test”</p>
.

Loading…
Cancel
Save