When I saw "Pure CSS/HTML" I figured it was doing the highlighting in CSS. IIUC this is doing the highlighting in C# and generating an HTML page. Which wile useful is not novel, it is how probably most syntax highlights work like Pygments or Rouge.
It uses C# Compiler SDK (Roslyn) that allows to generate "something" even if the input is a mess
and then I use some heuristics to identify for example classes better, e.g by having popular classes names/substrings list and checking whether it is there - like Console, Controller, Service, DTO, Handler etc.
Of course it cannot be perfect because it has no access to the whole code, it uses just some fragment that may not even compile / be completed
but I think that you can achieve something reasonable and at worst you'll be able to tweak it manually.
The goal was bo be able to easily put C# code with VS/VSC colours on a web page and without having to use generic js colouring libs, so we can get something closer to real IDE
You can easily modify generated a few lines of CSS and have your own colours
I was also gonna mention Shiki. While it is JS, you can SSR/SSG, and:
- it uses VSCode grammars and themes, which is awesome.
- it’s got some really cool extensions like Shiki Twoslash[1], allowing VSCode-like type hovers and type error demos. I’ve heard this can work without client-side JS but haven’t had the opportunity to check that out just yet.
- with some effort, you can extract the inline styles to a stylesheet and support pure CSS dark mode (note to self: clean up and open source my implementation of this).
This is similar in aim to FSharp.Formatting[1], which has been used for a while to generate syntax highlighting and hover tooltips for code samples and API docs in the F# ecosystem. Very cool to see!