Skip to content

extension(typographer): don't treat the leading apostrophe in 'terrifying' as a contraction - #554

Open
c-tonneslan wants to merge 1 commit into
yuin:masterfrom
c-tonneslan:fix/typographer-quoted-tword
Open

extension(typographer): don't treat the leading apostrophe in 'terrifying' as a contraction#554
c-tonneslan wants to merge 1 commit into
yuin:masterfrom
c-tonneslan:fix/typographer-quoted-tword

Conversation

@c-tonneslan

Copy link
Copy Markdown

Closes #347.

The 'twas / 'em / 'net contraction rule fired on any apostrophe at a word boundary followed by t / e / n / l, so 'terrifying' rendered as ’terrifying’ instead of ‘terrifying’.

Skip the contraction shortcut when the rest of the line still has a single quote that looks like the closing half of a quoted phrase (followed by space, punct, or EOL). 'net in We're talking about the internet --- 'net for short. still resolves as a contraction because the remaining apostrophes there are mid-word.

Test 20 added to typographer.txt, existing cases still pass.

…' as a contraction

Closes yuin#347.

The 'twas/'em/'net contraction rule matched any apostrophe at a word
boundary followed by t/e/n/l, so 'terrifying' rendered as
’terrifying’ instead of ‘terrifying’. Skip
the contraction shortcut when the rest of the line still has a
single quote that looks like the closing half of a quoted phrase
(followed by space, punct, or EOL). 'net in 'We're talking about the
internet --- 'net for short.' still resolves as a contraction since
the remaining apostrophes there are mid-word.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@olafk

olafk commented Sep 6, 2026

Copy link
Copy Markdown

Thanks for picking this up — I ran into #347 on a bilingual site and tested this patch against v1.8.6 (stock vs. replaced with this branch). It fixes the reported case, but I think there are two gaps worth a look before it lands.

input v1.8.6 with this PR expected
'terrifying', 'turn' &rsquo;terrifying&rsquo;, &rsquo;turn&rsquo; &lsquo;terrifying&rsquo;, &lsquo;turn&rsquo; ✅ fixed
We know this as 'non-alcoholic fatty liver
disease'.
&rsquo;non-alcoholic &rsquo;non-alcoholic ❌ still broken
Let's rock 'n' roll! rock &rsquo;n&rsquo; roll rock &lsquo;n&rsquo; roll ⚠ regression
'twas 'the best' of times &rsquo;twas &rsquo;the best&rsquo; &lsquo;twas &lsquo;the best&rsquo; ⚠ each fixes one half, breaks the other
give 'em hell, that's 'it' give &rsquo;em hell give &lsquo;em hell ⚠ regression

1. Hard-wrapped source is not covered. hasClosingSingleQuote returns false at '\n', so a quoted phrase that wraps across source lines still misfires. Since the two lines are one paragraph, and hard-wrapping prose is very common in Markdown, I suspect this is a large share of the real-world occurrences:

We know this as 'non-alcoholic fatty liver
disease'.

2. A genuine elision followed by a quoted phrase on the same line now opens a quote. The lookahead cannot distinguish "the closing half of my quote" from "an unrelated quote later in the line", so the canonical rock 'n' roll regresses. This is not caught by the suite: the existing rock 'n roll case in _test/typographer.txt omits the closing apostrophe, so go test ./extension/ passes with the patch applied.

Both fall out of the same thing — the rule keys on one byte plus a fuzzy line scan, rather than on the elisions it is named after. Matching the actual set ('twas, 'tis, 'til, 'em, 'net, 'n') would sidestep the lookahead entirely: 'eat and 'terrifying would never match, hard-wrapping would be irrelevant, and rock 'n' roll would keep working. It also mirrors what the sibling 's/'m/'t/'d and 've/'ll/'re branches already do a few lines above, both of which require a word boundary after the contraction.

If it helps, the three rows above marked ⚠ plus the wrapped case would make reasonable additions to _test/typographer.txt regardless of which approach you take.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single quotes not opening before the letter 't'

2 participants