A new Blazor component called Prismizor highlights code in pure C#, so prerendered and static SSR pages arrive with colored code instead of flashing plain text. It is a port of Prism.js.
Key points
- Prismizor is a Blazor component that highlights code in C#, so prerendered and static SSR HTML arrives already colored.
- It is a close port of Prism.js 1.30.0: 288 languages, eight bundled themes and the same token HTML.
- Each language is a separate static property such as PrismizorLanguages.CSharp, keeping unused grammars out of IL trimming.
- The full library is 1.59 MB; a C#-only app ships 79,637 bytes, or 8,987 bytes after Brotli.
- 328 tests diff Prismizor output against real Prism.js byte by byte on .NET 10 and .NET 11.
- Prism.js plugins (Line Numbers, Show Language, Autoloader) are unsupported, and \b and \s follow .NET Regex rules.
Why it matters
For anyone shipping documentation, a blog or a tutorial site with Blazor, this targets a real annoyance: code that only turns colored after the runtime boots. Highlighting inside the component also works where there is no OnAfterRenderAsync, meaning static SSR and enhanced navigation, and it drops a JavaScript dependency that the JS-wrapper libraries still carry.
The trade-offs are concrete. Prism.js plugins are out, so line numbers and labels need your own markup, and regex differences may shift results on non-ASCII code. Watch bundle size: 8,987 bytes is a C#-only app, and every grammar you add counts. If Prism theme CSS is already in place, migrating is mostly swapping the component.
Real-world use
- A Blazor WebAssembly site prerendered on the server where code samples must already be colored on first paint.
- Static SSR pages with enhanced navigation that need highlighted code without JavaScript hooks.
- A documentation or blog site that serves light and dark code themes purely through CSS media attributes.
- A project that already has Prism.js theme CSS and wants to keep it after moving highlighting server-side.
This summary was generated by the agent from the original post on DEV Community: #blazor. The full text and all rights belong to its author and publisher. Go to original