silvenon / remark-smartypants

remark plugin to implement SmartyPants
MIT License
54 stars 3 forks source link

Fix smart quotes at the start of paragraphs #87

Closed rwblickhan closed 3 months ago

rwblickhan commented 3 months ago

Summary

v2.1.0 fixed smart quotes around links and inline code by concatenating all text into one string (allText) and converting that with retext-smartypants.

That introduced a small regression. Quotes at the start of a paragraph may be merged with another paragraph, which retext-smartypants will no longer recognize as opening quotes. For instance:

Hi there

"Some quote"

is incorrectly converted to:

Hi there

”Some quote”

where the first quote on "Some quote" is being treated as a closing quote.

This PR fixes that by inserting a space into allText every time we see a paragraph node, then skipping over the inserted spaces when we need to keep track of indexes. That feels slightly clumsy, but it's a targeted way to fix this bug without changing the other behavior of this plugin.

Test Plan

silvenon commented 3 months ago

Released in v3.0.2 🚀