-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix smart quotes at the start of paragraphs #87
Conversation
"`); | ||
}); | ||
|
||
it("at end before another paragraph", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ending quotes actually work fine without this change, but we might as well test them while we're at it!
@@ -78,4 +89,10 @@ function isLiteral(node: Node): node is Literal { | |||
return "value" in node && typeof node.value === "string"; | |||
} | |||
|
|||
interface Paragraph extends Node {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface doesn't feel strictly necessary, but it is nice to use the type nodes: (Literal | Paragraph)[]
above instead of broadening it to nodes: Node[]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, you're a pretty cool dude 💯 I'll go release this.
Released in v3.0.2 🚀 |
Summary
v2.1.0 fixed smart quotes around links and inline code by concatenating all text into one string (
allText
) and converting that withretext-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:is incorrectly converted to:
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 aparagraph
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