Skip to content

fix: assign display names to same-language code tabs#730

Closed
shivxmsharma wants to merge 1 commit intonodejs:mainfrom
shivxmsharma:fix/prevent-same-lang-code-tab-merge
Closed

fix: assign display names to same-language code tabs#730
shivxmsharma wants to merge 1 commit intonodejs:mainfrom
shivxmsharma:fix/prevent-same-lang-code-tab-merge

Conversation

@shivxmsharma
Copy link
Copy Markdown
Contributor

Description

When two or more consecutive code blocks share the same language (e.g. two js blocks back to back), @node-core/rehype-shiki groups them into a CodeTabs component. The problem is both tabs end up labelled identically — "JS | JS" — which doesn't help the reader distinguish between them.

This PR adds a small rehype plugin (src/utils/code-tabs.mjs) that runs before @node-core/rehype-shiki in the getRemarkRecma pipeline. It scans consecutive code blocks either language appears more than once in a group, it injects displayName metadata onto each duplicate so the tabs render as "(1)", "(2)" instead. Blocks with different languages are left untouched.

Validation

  • All 363 existing + new tests pass (npm test).
  • Lint and formatting are clean (npm run lint, npm run format:check).
  • Manually verified with a test markdown containing two consecutive js blocks — confirmed displayName="(1)" and displayName="(2)" are injected into data.meta.

Related Issues

Addresses #596

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@shivxmsharma shivxmsharma requested a review from a team as a code owner March 30, 2026 15:15
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Mar 30, 2026 3:15pm

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 95.67568% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.63%. Comparing base (7e3f5d2) to head (bb0429e).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/code-tabs.mjs 93.39% 7 Missing ⚠️
src/utils/remark.mjs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #730      +/-   ##
==========================================
+ Coverage   76.15%   76.63%   +0.47%     
==========================================
  Files         151      157       +6     
  Lines       13641    13951     +310     
  Branches     1066     1125      +59     
==========================================
+ Hits        10388    10691     +303     
- Misses       3248     3255       +7     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@avivkeller avivkeller left a comment

Choose a reason for hiding this comment

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

I think this bug was already solved

@avivkeller
Copy link
Copy Markdown
Member

Indeed it is: https://openjs-foundation.slack.com/archives/C09EXEEHFKP/p1774740421197399

Please double-check this sort of thing.

@avivkeller avivkeller closed this Mar 30, 2026
@shivxmsharma
Copy link
Copy Markdown
Contributor Author

Indeed it is: https://openjs-foundation.slack.com/archives/C09EXEEHFKP/p1774740421197399

Please double-check this sort of thing.

I am unable to login to this.

@avivkeller
Copy link
Copy Markdown
Member

I am unable to login to this.

To access our Slack, see https://slack-invite.openjsf.org/

To "double-check this sort of thing", you can test local deployments before spending time on a change. It'll save lots of time :)

@shivxmsharma
Copy link
Copy Markdown
Contributor Author

I am unable to login to this.

To access our Slack, see https://slack-invite.openjsf.org/

To "double-check this sort of thing", you can test local deployments before spending time on a change. It'll save lots of time :)

Thank you for your feedback, it'll really help. I'll take more care next time before raising a PR:)

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