Live data from Hacker News

Syntax Highlighting in a Webpage Without JavaScript

fctorial.github.io

11–20 of 44 posts

Re: Syntax Highlighting in a Webpage Without JavaScript

#12
This is not new, but it's nice to spread awareness since it seems everyone loads it in the front-end nowadays and I've noticed that it also avoids the page moving around too much.

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(...

Re: Syntax Highlighting in a Webpage Without JavaScript

#13
post #3

What is so special about this? This is the way websites have been doing syntax highlighting before people started using javascript libraries.

There's a increasingly larger amount of web developers who are only "trained in React/Angular/Vue" and are unable to understand how to use or the trade-offs of regular websites using just HTML+CSS with only a little or no JS (that goes for both templated or fully static sites), and a surprising number of them even thinking they are some kind of "legacy technology".

At the very least, this kind of article is informative for that crowd.

Re: Syntax Highlighting in a Webpage Without JavaScript

#15
post #3

What is so special about this? This is the way websites have been doing syntax highlighting before people started using javascript libraries.

There's a increasingly larger amount of web developers who are only "trained in React/Angular/Vue" and are unable to understand how to use or the trade-offs of regular websites using just HTML+CSS with only a little or no JS (that goes for both templated or fully static sites), and a surprising number of them even thinking they are some kind of "legacy technology". At the very least, this kind of article is informati…

I'm fascinated by this. It seems that for any developer with less than five years of industry experience there's a reasonable chance that they've almost exclusively worked in an SPA, JavaScript-for-everything environment.

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.

Re: Syntax Highlighting in a Webpage Without JavaScript

#16
post #7

...By running the same JS on the server or in a build step.

Although at that point one could also make use of the excellent pygments library from Python, to truly have no JS, if that was the point. It is used from inside many other languages' tools as well.

Re: Syntax Highlighting in a Webpage Without JavaScript

#19
In Go we have https://github.com/alecthomas/chroma, and I implemented the lexer that the Caddy docs use for syntax highlighting the Caddyfile (see https://caddyserver.com/docs/caddyfile/concepts for example). What's cool about this is Caddy is serving the site from markdown files rendered via Go templates, with Chroma for code blocks. So Caddy can highlight its own config.

Re: Syntax Highlighting in a Webpage Without JavaScript

#20
post #15

Earlier quoted context omitted.

There's a increasingly larger amount of web developers who are only "trained in React/Angular/Vue" and are unable to understand how to use or the trade-offs of regular websites using just HTML+CSS with only a little or no JS (that goes for both templated or fully static sites), and a surprising number of them even thinking they are some kind of "legacy technology". At the very least, this kind of article is informati…

I'm fascinated by this. It seems that for any developer with less than five years of industry experience there's a reasonable chance that they've almost exclusively worked in an SPA, JavaScript-for-everything environment. 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.

You should make a video with a rebranded Django as “Reinhardt, the Multi Page Application” and see how it goes. Just do the original Rails “blog in ten minutes” demo to show it goes beyond todo lists.
Post reply on HN