Last active
August 29, 2015 14:25
-
-
Save JavaScript-Packer/eb5112206f0622209add to your computer and use it in GitHub Desktop.
JavaScript source code syntax hi-lighter in less than 1KB of code! No CSS BS, easy to use, set up as a simple function, making it for http://www.scriptcompress.com/
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
| function get_hi(a) { | |
| function b(a, b) { | |
| return "<span style=color:#" + a + ">" + (b || "$1") + "</span>"; | |
| } | |
| for (e = document.body.children, c = e[1].text, e[0].value = c, x = [ /&/g, "&", /</g, "<", />/g, ">", /\\./g, function(a) { | |
| return "r" + p.push(a) + ">"; | |
| }, /([\[({=:+,]\s*)\/(?![\/\*])/g, "$1<h/", /(\/\*[\s|\S]*?\*\/|\/\/.*)|(<h\/.+?\/\w*)|".*?"|'.*?'/g, function(a, c, d) { | |
| return "r" + p.push(b(c ? "666" :d ? "6a0" :"719", a)) + ">"; | |
| }, /((&\w+;|[-\/+*=?:.,;()\[\]{}|%^!])+)/g, b("17b"), /\b(break|case|catch|continue|push|default|eval|delete|fromcharcode|charcodeat|do|else|false|finally|for|function|if|in|instanceof|new|return|switch|this|throw|true|try|typeof|var|void|while|with)\b/gi, b("f00"), /\b(0x[\da-f]+|\d+)\b/g, b("d83"), /r(\d+)>/g, function(a, b) { | |
| return p[b - 1].replace(x[18], x[19]); | |
| }, /<h/g, "" ], p = [], i = 0; 22 > i; ) a = a.replace(x[i++], x[i++]); | |
| document.write("<pre>" + a + "</pre>"); | |
| } | |
| /* | |
| //Example usage: | |
| get_hi('var y = new Array();\n y[0] = "http://www.WHAK.com";\n y[1] = "http://www.ScriptCompress.com";\n y[2] = "http://www.Trollize.com";\n y[3] = "http://www.Holy-Bibles.com";\n y[4] = "http://www.Make-A-Meme.com";\nalert(y[Math.floor(Math.random() * y.length)]);'); | |
| get_hi(document.getElementById('someID').value); | |
| */ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What the heck, here is a starter HTML page for ya (opens hilighted code in new window, content area is editable):