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
Author
Add these to the "pre" tags to make it editable:
<pre contenteditable="" designmode="" autocorrect="false" spellcheck="false">
Author
What the heck, here is a starter HTML page for ya (opens hilighted code in new window, content area is editable):
<html>
<head>
<title>WHAK.com Syntax Hilighting In Less Than 1KB Of JavaScript Code!</title>
<script>
function sintax_hilite(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++]);window.open("","_blank").document['write']('<pre contenteditable="" designmode="" autocorrect="false" spellcheck="false" style="-moz-appearance:textfield-multiline;-webkit-appearance:textarea;overflow:auto;}html{-ms-overflow-y:scroll;overflow-y:scroll}body{overflow:none;background-color:#eee;background-image:none;background-repeat:repeat;background-attachment:scroll;background-position:top left;font-family:Verdana,Arial;font-size:14px">'+a+"</pre>").close()}
</script>
</head>
<body>
<textarea rows=12 cols=77 onmouseover="this.select()" id="xCode">
function randomSite() { var websites = new Array(); websites[0] = 'http://www.WHAK.com'; websites[1] = 'http://www.BibleThumper.net'; websites[2] = 'http://www.Trollize.com'; websites[3] = 'http://www.Holy-Bibles.com'; websites[4] = 'http://www.Make-A-Meme.com'; websites[5] = 'http://www.BoobSigns.com'; websites[6] = 'http://www.SeekFreak.com'; websites[7] = 'http://www.Is-A-Jerk.com'; websites[8] = 'http://www.HolyBibleVerse.com'; websites[9] = 'http://www.HolyBibleSearch.com'; websites[10] = 'http://www.ScriptCompress.com'; websites[19] = 'http://www.Make-A-Meme.com'; var rand = Math.floor(Math.random() * websites.length); return websites[rand]; } alert(randomSite());
</textarea>
<br>
<input type="button" value="WHAK.com SinTax HiLite" onclick="sintax_hilite(document.getElementById('xCode').value)">
</body>
</html>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some handy styles