Skip to content

Show the full language name on a code block - #97

Merged
rociiu merged 1 commit into
rociiu:mainfrom
rudycelekli:fix/code-language-label
Oct 26, 2026
Merged

rociiu merged 1 commit into
rociiu:mainfrom
rudycelekli:fix/code-language-label

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Bug

The language label on a code block in chat replies and note previews is cut short for common languages. A ```c++ or ```c# block is labelled C, and ```objective-c is labelled OBJECTIVE.

CodeBlock reads the language from the language-… class with /language-(\w+)/. \w stops at +, # and -.

Fix

/language-(\S+)/ takes the whole class token. remark puts the first word of the fence's info string there, so the label now matches what was written after the backticks. Blocks with a plain language name such as js look the same as before.

Test

apps/web/test/markdown-code.test.ts renders Markdown with react-dom/server and reads the label for c++, c#, objective-c and js.

cd apps/web && npx vitest run test/markdown-code.test.ts

  • Before the fix (current main): fails, expected 'c' to be 'c++'.
  • After the fix: passes. The full web suite passes (5 files, 21 tests), and npm run typecheck and biome are clean in apps/web.

The label read the language from the code element's class with \w+, so it stopped at the first character outside [A-Za-z0-9_]: a c++ or c# block was labelled C and an objective-c block OBJECTIVE. It now takes everything up to the next space.
@rociiu

rociiu commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thanks @rudycelekli — clear write-up and a solid regression test. Merging!

@rociiu
rociiu merged commit 6a5eb7b into rociiu:main Oct 26, 2026
1 check passed
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