I've always wondered if it wasn't intentional. Things running on the client means they don't have to run on the server, and you can save money this way.
The same logic could be applied to those client application technologies, too.
Give up, do some super hacky unmaintainable css mess, or suck it up and use js...
That is, JS can be used to do everything but it is not optimal, or even near optimal (or even remotely close to) for many use cases. In terms of runtime or simplicity. But because it is capable and available, it has encroached into every niche (of html/css) until like any invasive species, it consumes and shreds through all available resources, collapses the whole ecosystem, and all complex creatures give way to a fresh start with new fairly rudimentary biology (wasm) trying to evolve towards and find a new stability point — hopefully one that does not invite a similar destructive species, but we’ll see how it goes
How do you plan to style it with javascript without CSS? Rendering directly to canvas?
If you take this approach to the extreme, you should render to png on the server for display, and provide plain text for accessibility only.
At the very least, this kind of article is informative for that crowd.
I have a hunch that there are a lot of web professionals out there these days who genuinely don't know how to build a web application without JavaScript - POST forms, cookies and the like.
Then you'll end up having a project with highlighting logic in css and js. That's less than optimal
In https://documentation.page/ I'm using `markdown-it` with `prismjs` to generate the code snippets (see example on e.g. https://react-test.dev/). It's in fact a default helper, so you don't even need hacks:
import MarkdownIt from "markdown-it";
import Prism from "prismjs";
function highlight(str, lang) {
if (!lang || !Prism.languages[lang]) return;
return Prism.highlight(str, Prism.languages[lang], lang);
}
const md = new MarkdownIt({ highlight }).use(...So basically the script renders the JS-needed website, execute the JS as a build step and spit out the highlighted site. Pretty cool!
If you highlight on the server:
pros: no javascript, can cache
cons: might be a way to inject scripts into everyone's browser, since the client has to trust the html from the server
--
If you write it on the client:
pros: server can't distribute injected scripts, server stores less things
cons: more javascript, every client has to do work
--
All software choices are weighing the pros and cons. Do the thing that lets you work quickly and safely.
BTW: the markup grows substantially. It's worth having a simplification step. Also the old-school <tt> element is shorter and cooler than <span>.