Skip to content

feat(html-report): baked-in C# syntax highlighting on Source tab#6132

Merged
thomhurst merged 1 commit into
thomhurst:mainfrom
slang25:slang25/csharp-syntax-highlighter
May 31, 2026
Merged

feat(html-report): baked-in C# syntax highlighting on Source tab#6132
thomhurst merged 1 commit into
thomhurst:mainfrom
slang25:slang25/csharp-syntax-highlighter

Conversation

@slang25
Copy link
Copy Markdown
Contributor

@slang25 slang25 commented May 31, 2026

What

Adds a small, zero-dependency C# syntax highlighter to the HTML test report's Source tab. Previously the fetched source was rendered as plain, uncolored text.

How

  • A hand-rolled tokenizer (highlightCSharpLines) classifies comments (line/block/XML-doc), strings (regular, verbatim @"…", interpolated $"…", raw """…""" including multi-line), char and numeric literals (hex/binary/float suffixes/digit separators), keywords, method calls (ident() and PascalCase types.
  • It tokenizes the whole snippet so multi-line constructs render correctly, then splits into per-line HTML. All output is HTML-escaped via the existing esc().
  • Token colors are driven by --syn-* CSS custom properties defined per theme, so highlighting follows the existing light/dark toggle instantly with no JS re-render.
  • The palette mirrors the docs site's Prism themes: github for light, dracula for dark.
  • Non-.cs files fall back to plain escaped text.

All changes live in the embedded TestReport.template.html resource, outside the SAMPLE_DATA markers and __REPORT_DATA__ placeholder, so report generation is unaffected. No C# changes, no new dependencies.

Preview

Light (github) / Dark (dracula), switching with the theme toggle:

Light Dark
keywords #00009f, types #6f42c1, strings #e3116c, comments #999988 italic, numbers #36acaa, calls #d73a49 keywords #bd93f9, types #8be9fd, strings #ff79c6, comments #6272a4, numbers #bd93f9, calls #50fa7b

Notes

  • The tokenizer deliberately trades edge-case accuracy for a tiny footprint. Contextual keywords that are commonly ordinary identifiers (value, LINQ query words, etc.) are intentionally excluded to avoid miscoloring.
  • Verified that token line counts always equal source line counts (line numbers stay aligned), and visually checked rendering in both themes.

🤖 Generated with Claude Code

Add a small, zero-dependency C# syntax highlighter to the HTML test
report's Source tab. A hand-rolled tokenizer classifies comments,
strings (regular/verbatim/interpolated/raw), char and numeric literals,
keywords, method calls and PascalCase types, emitting theme-aware token
spans.

Token colors are driven by --syn-* CSS custom properties defined per
theme, so highlighting follows the existing light/dark toggle with no
re-render. The palette matches the docs site's Prism themes (github for
light, dracula for dark). Non-.cs files fall back to plain escaped text.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@slang25
Copy link
Copy Markdown
Contributor Author

slang25 commented May 31, 2026

The alternative is something like highlight.js and we reference that, this would be more accurate in terms of highlighting

@thomhurst
Copy link
Copy Markdown
Owner

Nice! 😄

@thomhurst thomhurst merged commit cd2189d into thomhurst:main May 31, 2026
8 of 10 checks passed
@claude claude Bot mentioned this pull request May 31, 2026
1 task
This was referenced Jun 1, 2026
This was referenced Jun 4, 2026
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