Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Last active August 10, 2017 09:12
Show Gist options
  • Select an option

  • Save lsongdev/abebd23e80f4ea1d53173ad0be0ad084 to your computer and use it in GitHub Desktop.

Select an option

Save lsongdev/abebd23e80f4ea1d53173ad0be0ad084 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const highlight = (src, theme) => {
theme = theme || {
'const' : 35,
'throw' : 35,
'new' : 33,
'var' : 33,
'if' : 36,
'else' : 36,
'=' : 33,
'true' : 32,
'false' : 31,
'console' : 33,
'function': 35,
'return' : 35,
'Object' : 33,
'Number' : 33,
'String' : 33,
'Array' : 33,
};
const color = (str, c) => "\x1b[" + c + "m" + str + "\x1b[0m";
Object.keys(theme).forEach((keyword, i) => {
src = src.replace(new RegExp(keyword, 'g'), (m ,k) => {
return color(m, theme[keyword]);
});
});
return src;
}
console.log(highlight(fs.readFileSync('highlight.js', 'utf8')));
@lsongdev

Copy link
Copy Markdown
Author

screen shot 2017-08-10 at 4 29 31 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment