Last active
August 10, 2017 09:12
-
-
Save lsongdev/abebd23e80f4ea1d53173ad0be0ad084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
commented
Aug 10, 2017
Author

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