Hacker News new | ask | show | jobs
by rahiel 3675 days ago
This is cool, but I prefer code highlighting without requiring visitors to run JavaScript. It seems unnecessary when tools like Pygments [1] do the highlighting once and output html/css.

[1]: http://pygments.org/

3 comments

The content might be dynamic not static. For example, an SO clone might allow users to type a comment including code in mark down and then need to preview it.
I was more of the opinion that syntax highlighting was purely presentational. Does that mean that it is more sensible to do it on the client?
Yup. Hilight it one time and serve it up vs hilight every time (client side).

I don't like waste for the sake of waste.

Surely highlighting it on the server is the waste in this case? The library is only 2174 bytes (not even gzipped).

Let's say you used the smallest markup possible for each highlighted token. Something like <i class="x">[token here]</i>. You'd only be able to serve up at most 120 server-highlighted tokens before this JS library becomes a smaller payload, and that's without even defining the CSS styling or considering tokens longer than 1 character.

120 isn't even enough tokens to highlight the tiny code snippet at the top of this demo page. The same tiny snippet highlighted with Pygments comes out to 5819 bytes of markup alone (no styling) – already more than 2.5 times the size of this whole library. Plus you can highlight any number and size of code snippets while just serving the library once... which one is wasteful again? :)