1. 15
    1. 25

      If not for “new” in the title, I’d assumed that this is about the Markdown console renderer named Glow: repo charm.sh

      1. 4

        Yeah, this is a really bad naming choice.

      2. 7

        How can it not “focus on language internals” and still be a syntax highlighter? Is the language parsing itself being offloaded to something like treesitter? It mentions how alternatives have massive grammar files, and Glow doesn’t, but then how can it be a syntax highlighter?

        1. 15

          I had the same questions but after looking at the source, it appears to be using fixed regular expressions for a fixed set of syntax elements—which answers your questions but raises quite a few more…

          1. 4

            I had a feeling this may be the case, honestly it makes sense. Most popular languages are C-like or Python-like and often use the same set of keywords like if, else and use brackets and braces. I can see the tradeoff in being not quite absolutely perfect but still making the reading experience good enough.

            Perhaps if you were using a weird language with odd syntax only supported by Prism it makes sense to use that, but I think this would be fine for throwing some JSON, JS, C, Go, etc into blog posts/documentation!

            1. 1

              Exactly the logic in there. Going to add language-specific keywords later on. On top of the if/else/for s.

            2. 4

              I was wondering how the clojurescript demo works, since ;; isn’t in the comment regex. Answer: it’s hardcoded on line 5.

              I can think of at least four languages I’ve used in the past week (TLA+, Raku, Picat, lua) that have comments this won’t highlight. And I’m reasonably sure it’ll comment out any lines that start with #, even when that’s actually a keyword (Alloy).

              1. 1

                Thanks, good point. I’ll make comments and keywords language-aware.

            3. 3

              Author here: Shortly, the bulk of highlighting work is something else than keywords.

              Glow understands basic programming language concepts like comments, strings, assignments, function calls/definitions, brackets, and other special characters. These all make the bulk of the grammar to be colored. For the keywords, Glow currently uses a hardcoded list of commonly used tokens. These together seem to work quite nicely for the 30+ different languages presented on the demo page. Having said that, the next version will have language-specific keyword lists.

          🇬🇧 The UK geoblock is lifted, hopefully permanently.