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 The Adds a Reviewed by Cursor Bugbot for commit 04608ab. 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?
There was a problem hiding this comment.
Done, switched the helper to 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); | ||
| \`\`\` | ||
| `) | ||
| ); |
There was a problem hiding this comment.
Done, used dedent for the markdown fixture.
|
Bump @lizuju |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #879 +/- ##
==========================================
+ Coverage 84.99% 85.09% +0.10%
==========================================
Files 179 180 +1
Lines 16407 16555 +148
Branches 1483 1507 +24
==========================================
+ Hits 13945 14088 +143
- Misses 2452 2457 +5
Partials 10 10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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".