Skip to content

fix(docs): allow hyphens in fenced codeblock language (#2437)#2524

Open
MukundaKatta wants to merge 1 commit intonpmx-dev:mainfrom
MukundaKatta:fix/2437-hyphenated-codeblock-language
Open

fix(docs): allow hyphens in fenced codeblock language (#2437)#2524
MukundaKatta wants to merge 1 commit intonpmx-dev:mainfrom
MukundaKatta:fix/2437-hyphenated-codeblock-language

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

Fixes #2437.

The fenced-codeblock language regexes in server/utils/docs/render.ts and server/utils/docs/text.ts matched \w, which doesn't include -. For Shiki languages with hyphens (glimmer-ts, vue-html, objective-c, etc.), the -suffix was dropped from the captured language and leaked into the top of the code body — the code block rendered with broken highlighting and a stray -ts at the start.

Swaps \w for [\w-] in the three affected regexes:

  • render.ts — the two regexes that extract lang and strip the fence from example.doc
  • text.ts — the fenced-block extraction in renderMarkdown

Test plan

  • Added regression test in test/unit/server/utils/docs/text.spec.ts for glimmer-ts covering both sides of the bug: the -ts suffix no longer leaks into the body, and highlighting kicks in.
  • CI (lint + existing test suite)

🤖 Generated with Claude Code

The fenced-codeblock language regexes in render.ts and text.ts matched
\w which excludes `-`, so languages like `glimmer-ts`, `vue-html`, and
`objective-c` were truncated: the `-ts` suffix was stripped off the
language and leaked into the top of the code body, breaking Shiki
highlighting.

Swap `\w` for `[\w-]` in the three affected regexes and add a
regression test covering `glimmer-ts`.

Fixes npmx-dev#2437
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

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

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Apr 14, 2026 7:22pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Apr 14, 2026 7:22pm
npmx-lunaria Ignored Ignored Apr 14, 2026 7:22pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Fixed documentation code block rendering for language identifiers containing hyphens (such as glimmer-ts). Code blocks with hyphenated language tags now display correctly without content truncation or formatting issues.

Walkthrough

Updated regex patterns in documentation parsing utilities to support hyphenated language identifiers (e.g. glimmer-ts) in fenced code blocks, preventing language suffix characters from appearing in rendered code content.

Changes

Cohort / File(s) Summary
Regex pattern updates for hyphenated language support
server/utils/docs/render.ts, server/utils/docs/text.ts
Modified JSDoc example code fence and markdown code block extraction regexes to accept hyphens in language identifiers by changing capture patterns from \w or (\w*) to [\w-] or ([\w-]*) respectively.
Test coverage
test/unit/server/utils/docs/text.spec.ts
Added unit test for renderMarkdown validating correct handling of fenced code blocks with hyphenated language identifiers, ensuring the truncated suffix does not leak into the code body.

Suggested reviewers

  • danielroe
  • ghostdevv
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Hello! Thank you for opening your first PR to npmx, @MukundaKatta! 🚀

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any issues you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Vercel

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
server/utils/docs/render.ts (1)

194-196: Add a dedicated regression test for the @example parsing branch.

These regex updates are in the renderJsDocTags path; please add a direct test that an @example fenced block with glimmer-ts does not leak -ts into the code body.

As per coding guidelines "**/*.{test,spec}.{ts,tsx}: Write unit tests for core functionality using vitest".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/utils/docs/render.ts` around lines 194 - 196, Add a vitest unit test
(file matching **/*.{test,spec}.{ts,tsx}) that exercises the
renderJsDocTags/example parsing branch in server/utils/docs/render.ts: construct
a JSDoc with an `@example` fenced block using the language tag "glimmer-ts" and
call the same parser path (the code that computes langMatch/lang/code around
example.doc) or renderJsDocTags directly, then assert the returned lang remains
"glimmer-ts" but the extracted code string does NOT contain the "-ts" suffix
(i.e., the code should not include the language suffix); keep the test focused
and titled to document the regression for "glimmer-ts" example parsing.
test/unit/server/utils/docs/text.spec.ts (1)

296-305: Strengthen this regression by asserting the highlight path explicitly.

Add a positive check for Shiki output so this test also guarantees glimmer-ts is parsed and highlighted, not just that leakage is gone.

Suggested test tweak
   expect(result).not.toContain('-ts')
+  expect(result).toContain('shiki')
   expect(result).toContain('const')
   expect(result).not.toContain('```')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/unit/server/utils/docs/text.spec.ts` around lines 296 - 305, The test
currently only checks that the "-ts" suffix doesn't leak into the code body;
update the regression test that calls renderMarkdown(input, emptyLookup) to also
assert that the Shiki highlight path was used by checking for Shiki-specific
output (e.g. a language class or highlighted token spans) tied to the original
fence language; in practice, after calling renderMarkdown in the 'should handle
fenced code blocks with hyphenated language (e.g. glimmer-ts)' test, add a
positive expect that the result contains the highlighting marker for glimmer-ts
(for example a class attribute including "glimmer-ts" or Shiki token span
markup) so you validate that renderMarkdown actually parsed and highlighted
"glimmer-ts" rather than merely stripping the suffix.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/utils/docs/render.ts`:
- Around line 194-196: Add a vitest unit test (file matching
**/*.{test,spec}.{ts,tsx}) that exercises the renderJsDocTags/example parsing
branch in server/utils/docs/render.ts: construct a JSDoc with an `@example` fenced
block using the language tag "glimmer-ts" and call the same parser path (the
code that computes langMatch/lang/code around example.doc) or renderJsDocTags
directly, then assert the returned lang remains "glimmer-ts" but the extracted
code string does NOT contain the "-ts" suffix (i.e., the code should not include
the language suffix); keep the test focused and titled to document the
regression for "glimmer-ts" example parsing.

In `@test/unit/server/utils/docs/text.spec.ts`:
- Around line 296-305: The test currently only checks that the "-ts" suffix
doesn't leak into the code body; update the regression test that calls
renderMarkdown(input, emptyLookup) to also assert that the Shiki highlight path
was used by checking for Shiki-specific output (e.g. a language class or
highlighted token spans) tied to the original fence language; in practice, after
calling renderMarkdown in the 'should handle fenced code blocks with hyphenated
language (e.g. glimmer-ts)' test, add a positive expect that the result contains
the highlighting marker for glimmer-ts (for example a class attribute including
"glimmer-ts" or Shiki token span markup) so you validate that renderMarkdown
actually parsed and highlighted "glimmer-ts" rather than merely stripping the
suffix.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a4b62273-e81c-410a-8552-fa1a09573193

📥 Commits

Reviewing files that changed from the base of the PR and between e331d86 and 7740aaa.

📒 Files selected for processing (3)
  • server/utils/docs/render.ts
  • server/utils/docs/text.ts
  • test/unit/server/utils/docs/text.spec.ts

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.

docs feature codeblock hyphenated lang regex

1 participant