fix(remark): preserve code display names through raw HTML#879
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview
A regression test runs the full processor with a raw Reviewed by Cursor Bugbot for commit 0b56135. Bugbot is set up for automated code reviews on this repo. Configure here. |
| const visit = node => { | ||
| if (!node || typeof node !== 'object') { | ||
| return; | ||
| } | ||
|
|
||
| if (node.type === 'JSXOpeningElement' && node.name?.name === 'CodeTabs') { | ||
| attributes.push( | ||
| Object.fromEntries( | ||
| node.attributes.map(attribute => [ | ||
| attribute.name.name, | ||
| attribute.value?.value, | ||
| ]) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| Object.values(node).forEach(value => { | ||
| if (Array.isArray(value)) { | ||
| value.forEach(visit); | ||
| } else { | ||
| visit(value); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| visit(tree); |
There was a problem hiding this comment.
Can you use unist-util-visit?
| processor.parse(` | ||
| <div class="note">raw html</div> | ||
|
|
||
| \`\`\`cjs displayName="main.js" | ||
| console.log(1); | ||
| \`\`\` | ||
|
|
||
| \`\`\`cjs displayName="main.test.js" | ||
| console.log(2); | ||
| \`\`\` | ||
| `) | ||
| ); |
|
Bump @lizuju |
Summary
rehypeRawin thegetRemarkRecmapipelinedisplayNamereachesCodeTabsFixes #732
Verification
node --test --experimental-test-module-mocks src/utils/__tests__/remark.test.mjsnpm testnpm run lint(passes; existing warnings remain insrc/generators/web/ui/hooks/useOrama.mjs)npm run format:checkgit diff --checknodejs/learn/pages/test-runner/collecting-code-coverage.mdwithnode bin/cli.mjs generate -t web ...; the generatedcollecting-code-coverage.htmlnow renders the first tabs asmain.jsandmain.test.js, and the bundle containsdisplayNames: "main.js|main.test.js".