Skip to content
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

Merged
merged 5 commits into from
Jul 8, 2024
Merged

Fix smart quotes at the start of paragraphs #87

merged 5 commits into from
Jul 8, 2024

Conversation

rwblickhan
Copy link
Contributor

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

  • Three new unit tests are introduced which fail without this change and succeed with it.
  • All existing unit tests pass.

"`);
});

it("at end before another paragraph", async () => {
Copy link
Contributor Author

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 {}
Copy link
Contributor Author

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[].

Copy link
Owner

@silvenon silvenon left a 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.

@silvenon silvenon merged commit 0ed7519 into silvenon:main Jul 8, 2024
2 checks passed
@silvenon
Copy link
Owner

silvenon commented Jul 8, 2024

Released in v3.0.2 🚀

@rwblickhan rwblickhan deleted the rwblickhan-fix-blockquotes branch July 8, 2024 20:03
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.

2 participants