node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »


eshighlight Build Status

JavaScript code highlighter based on esprima.


npm install eshighlight


Takes a JavaScript string, returns an html string.

var highlight = require('eshighlight');
highlight('var x = 42');

which returns:

<span class="keyword">var</span> <span class="identifier">x</span> = <span class="numeric">42</span>

Prior Art

Before writing this, I looked at these solutions:

The main motivation for this library was so I can make my blog to look like sublime. None of the highlighters I looked at let you color parameters. I want that nice orange on my params yo.

I didn't like that they all only tokenized rather than doing a proper parse. I think the parse tree approach might be interesting.

Compared to highlight.js and google-code-prettify, eshighlight has the drawbacks that it does not support languages besides JavaScript and only works in node.