Skip to content

Commit

Permalink
Fix smartquotes around softbreaks
Browse files Browse the repository at this point in the history
close #430
  • Loading branch information
rlidwka committed Feb 6, 2018
1 parent d57c83a commit 04d36a3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rules_core/smartquotes.js
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions test/fixtures/markdown-it/smartquotes.txt
Expand Up @@ -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>
.

0 comments on commit 04d36a3

Please sign in to comment.