Browse Source

Fix smartquotes around softbreaks

close https://github.com/markdown-it/markdown-it/issues/430
pull/445/head
Alex Kocharin 6 years ago
parent
commit
04d36a3f1a
  1. 6
      lib/rules_core/smartquotes.js
  2. 28
      test/fixtures/markdown-it/smartquotes.txt

6
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;

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

@ -109,3 +109,31 @@ Quotes at the start/end of the tokens:
<p>“foo <em>bar</em>”</p>
<p>“<em>foo bar</em>”</p>
.
Should treat softbreak as a space:
.
"this"
and "that".
"this" and
"that".
.
<p>“this”
and “that”.</p>
<p>“this” and
“that”.</p>
.
Should treat hardbreak as a space:
.
"this"\
and "that".
"this" and\
"that".
.
<p>“this”<br>
and “that”.</p>
<p>“this” and<br>
“that”.</p>
.

Loading…
Cancel
Save