Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save JavaScript-Packer/eb5112206f0622209add to your computer and use it in GitHub Desktop.

Select an option

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/
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, "&amp;", /</g, "&lt;", />/g, "&gt;", /\\./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);
*/
@JavaScript-Packer

Copy link
Copy Markdown
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,"&amp;",/</g,"&lt;",/>/g,"&gt;",/\\./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 &nbsp;randomSite() &nbsp;{&#10; &nbsp; &nbsp; &nbsp; &nbsp;var &nbsp;websites &nbsp;= &nbsp;new &nbsp;Array();&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[0] &nbsp;= &nbsp;'http://www.WHAK.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[1] &nbsp;= &nbsp;'http://www.BibleThumper.net';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[2] &nbsp;= &nbsp;'http://www.Trollize.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[3] &nbsp;= &nbsp;'http://www.Holy-Bibles.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[4] &nbsp;= &nbsp;'http://www.Make-A-Meme.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[5] &nbsp;= &nbsp;'http://www.BoobSigns.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[6] &nbsp;= &nbsp;'http://www.SeekFreak.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[7] &nbsp;= &nbsp;'http://www.Is-A-Jerk.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[8] &nbsp;= &nbsp;'http://www.HolyBibleVerse.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[9] &nbsp;= &nbsp;'http://www.HolyBibleSearch.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[10] &nbsp;= &nbsp;'http://www.ScriptCompress.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;websites[19] &nbsp;= &nbsp;'http://www.Make-A-Meme.com';&#10; &nbsp; &nbsp; &nbsp; &nbsp;var &nbsp;rand &nbsp;= &nbsp;Math.floor(Math.random() &nbsp;* &nbsp;websites.length);&#10; &nbsp; &nbsp; &nbsp; &nbsp;return &nbsp;websites[rand];&#10;}&#10;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