Skip to content

Highlight C#, shell, PowerShell and HTTP code blocks - #2781

Merged
bradystroud merged 2 commits into
SSWConsulting:mainfrom
jernejk:jk/code-highlighting-csharp-shell
Nov 11, 2026
Merged

bradystroud merged 2 commits into
SSWConsulting:mainfrom
jernejk:jk/code-highlighting-csharp-shell

Conversation

@jernejk

@jernejk jernejk commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

✅

  • TinaCMS's rich-text Prism wrapper uses prism-react-renderer, whose bundled language set has no csharp / cs, bash / shell / sh, powershell or http grammars.
  • Hundreds of SSW Rules are tagged with those languages (about 560 with csharp/cs alone) and render monochrome on https://www.ssw.com.au. Example: Aspire — YAML is coloured, C# is not (token plain only).
  • This PR uses prism-react-renderer's documented custom-language approach: assign the vendored Prism to globalThis, then load upstream prismjs/components (prism-csharp, prism-bash, prism-powershell, prism-http) so they register onto that same instance. Aliases: cs/dotnet → csharp, sh/shell → bash.
  • No custom grammars. Dotenv is not covered (PrismJS has no dotenv component; left out of scope).
  • One side-effect import from components/typography-components.tsx. Direct deps: prism-react-renderer@2.4.1, prismjs@1.30.0, @types/prismjs@1.26.6 (lockfile regenerated with pnpm).
  • Unit test: __tests__/lib/prismGrammars.test.ts (csharp/cs/dotnet, bash/sh/shell, powershell, http).

Prepared with AI assistance.

Screenshot (optional)

✅

Captured from the local Jackdaw preview of centralise-local-dev-config-and-secrets-in-apphost with the import removed, then restored.

Before (C# block — 1 computed token colour)

Before: monochrome C#

After (same C# block — 4 computed token colours)

After: highlighted C#

C# source block on that rule Token colours before Token colours after
Client registration 1 4
AppHost 1 6
Web Program.cs 1 5
JSON blocks (control) 3 3 (unchanged)

Full-page before/after (optional): before · after

Verification

  • pnpm exec biome lint on the touched files — pass
  • pnpm exec tsc --noEmit — pass
  • pnpm exec jest __tests__/lib/prismGrammars.test.ts — 4/4 pass

TinaCMS's prism-react-renderer bundle omits csharp/bash/powershell/http/dotenv,
so hundreds of SSW Rules tagged with those languages render monochrome.

Register the missing PrismJS grammars into the shared prism-react-renderer
registry (with cs→csharp and shell→bash aliases) and cover them with a unit test.

Prepared with AI assistance.
Drop the custom dotenv grammar and PowerShell flag tweak. Load csharp,
bash, powershell and http from prismjs/components onto prism-react-renderer's
Prism (documented custom-language approach), with cs/dotnet->csharp and
sh/shell->bash aliases.

Prepared with AI assistance.
@jernejk jernejk changed the title Highlight C#, shell, PowerShell, HTTP and .env code blocks Highlight C#, shell, PowerShell and HTTP code blocks Nov 6, 2026
@jernejk
jernejk marked this pull request as ready for review November 8, 2026 23:59
Copilot AI balanced review requested due to automatic review settings November 8, 2026 23:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified for the added syntax-highlighting support.

No open issues 🎉

1 file not reviewed
  • pnpm-lock.yaml: Generated file
What changed in this PR

Adds syntax highlighting for C#, shell, PowerShell, and HTTP code blocks in SSW.Rules by registering upstream Prism grammars with the renderer used by TinaCMS.

Changes:

  • Registers four grammars and common C# and shell language aliases.
  • Loads the grammars through the shared typography components.
  • Adds pinned dependencies and unit tests for grammar registration and tokenization.
File Description
pnpm-lock.yaml Locks the added Prism dependencies.
package.json Declares Prism renderer, grammar, and type dependencies.
lib/​prism-grammars.ts Registers upstream grammars and language aliases.
components/​typography-components.tsx Imports grammar registration for code-block rendering.
__tests__/​lib/​prismGrammars.test.ts Tests tokenization for the added languages and aliases.

Review effort: Balanced

@bradystroud bradystroud left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed and tested locally: frozen install, new prism grammar tests pass (4/4), biome clean, Turbopack compile build succeeds. Confirmed globalThis.Prism is set before the grammar require()s in both client and SSR chunks, and tinacms resolves the same prism-react-renderer 2.4.1, so the grammars register where Tina's Highlight reads them.

Non-blocking follow-up: if a future tinacms bump pulls a second prism-react-renderer copy, highlighting would silently go back to monochrome while this test still passes. A pnpm override or a test through tinacms/dist/rich-text/prism would guard that.

@bradystroud
bradystroud merged commit 80ba4dc into SSWConsulting:main Nov 11, 2026
bradystroud added a commit that referenced this pull request Nov 12, 2026
…e admin starts again (#2807)

Since #2781, the Tina admin stops at load with "Dynamic require of
"prismjs/components/prism-csharp" is not supported", and it then shows
"Failed loading TinaCMS assets". The admin is a browser ES module bundle,
and lib/prism-grammars.ts used require calls.

- The grammars load as static imports on the prismjs core instance, and the
  module copies them to the Prism instance of prism-react-renderer.
- A form that sets the global Prism from an ES module does not work: the
  bundler runs the grammar code first, and the admin stops with "Prism is not
  defined" (tested).
- PrismJS.manual is true, so the prismjs core does not highlight the code
  blocks that React renders.

Tested: production admin and a local admin build in headless Chromium. Before,
the asset error. After, the admin loads. The grammar tests pass (one new test).


Claude-Session: https://claude.ai/code/session_01UTtNDpWnuaUUQ2winSSgMb

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@adamcogan

Copy link
Copy Markdown
Member

Hey @bradystroud

FYI would have preferred JK choose to use YakShaver - it's a nicer way to see and hear the context.

Agree?

-a

This branch had an error being deployed

1 failed deployment
staging — 42452176 Deployed Nov 11, 2026 by bradystroud via Delete PR Slot #177
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.

4 participants