Skip to content

Instantly share code, notes, and snippets.

@vprimachenko
Created September 18, 2013 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vprimachenko/6610386 to your computer and use it in GitHub Desktop.
Save vprimachenko/6610386 to your computer and use it in GitHub Desktop.
use highlight.js in the cosole
var hljs = require('highlight.js');
var high = hljs.highlight('cpp', 'void main<>(){return true;}').value;
high = high.replace(/<\/span>/g,'\x1b[0m');
high = high.replace(/<span class="([a-z]+)">/g,function (match,p1) {
return {
'keyword':'\x1b[32m',
'types':'\x1b[34m',
'number':'\x1b[33m',
'consts':'\x1b[37m'
}[p1];
});
high = high.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
console.log(high);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment