Live data from Hacker News

Highlight.js – Syntax highlighting for the Web

highlightjs.org

71–72 of 72 posts

Re: Highlight.js – Syntax highlighting for the Web

#71

In my opinion it's irresponsible to use highlighters like these. At least when you use them like advertised. Why does no one bat an eyelid at letting the clients handle the highlighting? The highlighting (lexing) could (and should) be done ONCE at the server. Imagine some high traffic blogs with hundreds of millions of hits combined - all these clients downloading the highlighting libs + lexers for 50 different langu…

In my opinion it is irresponsible to post strongly worded opinions such as these, because you forget you may not be seeing the whole picture. Cons when the server do the lexing ONCE: - NOTHING You are assuming a specific use case, where static code originally exists on the server and the highlighted version is included in a page that is viewed many times. My use case for these libraries is different: users actually w…

That's an entirely different problem I'd say, and the perfect use case for these libraries on a client! If you'd do it server side it would be like a local IDE sending the code to be lexed remotely...

My rantiness (I apologize for that) targets programming blogs/static pages.

Re: Highlight.js – Syntax highlighting for the Web

#72

At one point I got really into the idea of ASTs for languages. I've used pygments, the python syntax highlighter, with the intention of parsing the meaning of code. These syntax highlighters are great but I think that underlie the lack of a defined and accessible AST parse definition for most languages. Highlight.js and others kind of just rely regexes-- https://github.com/isagalaev/highlight.js/blob/master/src/la...…

I believe CodeMirror does something like this. It uses restartable parsers (or it used to) to make parsing fast while editing. I experimented editing code using jQuery.Syntax. I used the match tree it generated to figure out where to restart parsing and it was pretty fast, it would only re-evaluate the current line in most cases.

CodeMirror still uses the restartable parsers. But they produce a flat sequence of styles, not a hierarchical AST. E.g. `foo bar* baz` in markdown becomes foo bar baz*. Also, most parsers reuse a small set of style names (that are covered by themes) without much regard to semantic appropriateness. E.g. markdown lists cycle through 'variable-2', 'variable-3', 'keyword'.
Post reply on HN