Skip to content

Commit 670ae4e

Browse files
authored
fix: single quotes for contractions (#241)
1 parent ef4ad35 commit 670ae4e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

workspace/aubade/src/artisan/example.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,22 @@ describe('libretto', ({ concurrent: it }) => {
767767
'<figure>\n<img src="img.png" alt="alt" />\n<figcaption>annotated <em>title</em> for caption</figcaption>\n</figure>',
768768
],
769769

770+
'quotes#escaped': ['\\"a b\\"', '<p>&quot;a b&quot;</p>'],
770771
'quotes#double/1': ['"hello"', '<p>“hello”</p>'],
771772
'quotes#double/2': ['"a *b* c"', '<p>“a <em>b</em> c”</p>'],
773+
'quotes#double/3': ['"(quote)"', '<p>“(quote)”</p>'],
772774
'quotes#single/1': ["'hello'", '<p>‘hello’</p>'],
773775
'quotes#single/2': ["'a 'b' c'", '<p>‘a ‘b’ c’</p>'],
776+
'quotes#single/3': ["don't", '<p>don’t</p>'],
777+
'quotes#prime/1': ['24" monitor', '<p>24″ monitor</p>'],
778+
'quotes#prime/2': [`5'5"`, '<p>5′5″</p>'],
774779
'quotes#mixed/1': [`"a 'b' c"`, '<p>“a ‘b’ c”</p>'],
775780
'quotes#mixed/2': [`'a "b" c'`, '<p>‘a “b” c’</p>'],
776781
'quotes#mixed/3': [`'a "b' c"`, '<p>‘a “b’ c”</p>'],
777782
'quotes#mixed/4': [`'"hello"'`, '<p>‘“hello”’</p>'],
778783
'quotes#mixed/5': [`"'hello'"`, '<p>“‘hello’”</p>'],
784+
'quotes#mixed/6': [`"i'm sure"`, '<p>“i’m sure”</p>'],
785+
'quotes#mixed/7': [`"13" laptop"`, '<p>“13″ laptop”</p>'],
779786

780787
'strike#single': ['~strike~', '<p>~strike~</p>'],
781788
'strike#normal': ['~~strike~~', '<p><del>strike</del></p>'],

workspace/aubade/src/artisan/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ export function typographic(token: Extract<Token, { type: 'inline:text' }>) {
3030
const prev = token.text[i - 1];
3131
const next = token.text[i + 1];
3232

33+
const prime = /\d/.test(prev);
3334
const left = util.is['left-flanking'](prev || ' ', next || ' ');
3435
const right = util.is['right-flanking'](prev || ' ', next || ' ');
3536

36-
const double = left ? '“' : right ? '”' : char;
37-
const single = left ? '‘' : right ? '' : char;
37+
const double = left ? '“' : right ? (prime ? '″' : '”') : char;
38+
const single = right ? (prime ? '′' : '’') : left ? '' : char;
3839

3940
result += char === '"' ? double : single;
4041
}

0 commit comments

Comments
 (0)