-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 cases for JSX-like expressions in code blocks of headings #3502
Fix cases for JSX-like expressions in code blocks of headings #3502
Conversation
🦋 Changeset detectedLatest commit: fb69531 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
83c307a
to
45dbd17
Compare
45dbd17
to
1a42da6
Compare
I think that the way you are doing this but skipping any nodes where the parent is a code/pre entirely will cause there to be no id if there is only a codeblock and nothing else. To test this, create a test for: await renderMarkdown(`# \`{frontmatter.title}\``, {}) That should still render some id. In my branch that was making the id be "frontmattertitle". See https://github.com/withastro/astro/pull/3510/files Happy to go with your approach in general, just want to make sure we handle this case. |
visit(node, (child) => { | ||
if (child.type === 'element') { | ||
visit(node, (child, _, parent) => { | ||
if (child.type === 'element' || ['code', 'pre'].some((tag) => parent?.tagName === tag)) { |
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.
please use an object or Set here to avoid an unnecessary O(2) lookup.
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.
changed to use Set
to scan parent.tagName
in fb69531
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.
Looks great, thanks!
Changes
I fixed cases to render incorrectly JSX-like expressions in code blocks of headings.
See also #3491 for details.
Testing
Add test cases including JSX-like expressions in code blocks of headings like below.
Docs
N/A
Related