Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Fix bug in rehype-hljs-var #506

Merged
merged 1 commit into from
Nov 18, 2024
Merged

Fix bug in rehype-hljs-var #506

merged 1 commit into from
Nov 18, 2024

Conversation

ptgott
Copy link
Contributor

@ptgott ptgott commented Nov 18, 2024

Sometimes, hljs generates text nodes that are direct descendents of a code element, without being the children of a span. rehype-hljs-var expects all text nodes to be the sole children of an element node.

This change edits rehype-hljs-var to accommodate text nodes. It also refactors the plugin to clean up the logic for splitting text nodes with Var component placeholders.

Sometimes, hljs generates text nodes that are direct descendents of a
`code` element, without being the children of a `span`. rehype-hljs-var
expects all text nodes to be the sole children of an element node.

This change edits rehype-hljs-var to accommodate text nodes. It also
refactors the plugin to clean up the logic for splitting text nodes with
Var component placeholders.
@ptgott ptgott requested a review from avatus as a code owner November 18, 2024 18:50
Copy link

vercel bot commented Nov 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 18, 2024 7:09pm

return placeholder;
}
);
return [CONTINUE];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a weird pattern to return a const like that in an array lol, never seen anyhting like it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a tuple to control AST traversal: https://www.npmjs.com/package/unist-util-visit#visittree-test-visitor-reverse

Yeah, pretty odd!

@ptgott ptgott merged commit 3d636a9 into main Nov 18, 2024
5 of 6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants