Prefab code highlighting
This code highlighter will allow you to colorize a code sniplet. To use, insert your code, look how it looks, select the radio button behind the color you want change. Then you click on the color palet bit below. The outpur html will be updated with those color values.
Your code:
function highlightCode(codeblock,colorSet) {
defaultColor = "#cccccc";
defaultBackground = "#000000";
if(colorSet=='blueish green') {colorScheme="#C3FF00,#8CFF00,#5DFF00,#00CE29,#00CE97,#00FFF6";}
else if(colorSet=='fire') {colorScheme="#FF006E,#FF0000,#FF6A00,#FFBF00,#FFEE00,#E9FF00,#CCFF00";}
else if(colorSet=='purple blue') {colorScheme="#00CBFF,#0094FF,#0065FF,#001DFF,#6A00FF,#9000FF,#C300FF,#FF00F2";}
else if(colorSet=='techno') {colorScheme="#00FFD4,#00FF99,#00FF3F,#8BFF6B,#BCFF6B,#BBFF00,#83C1FC,#58DBFC,#09F5F9,#00FF8C,#A5C600,#A5C600";}
else if(colorSet=='restfull') {colorScheme="#A5C600,#00C475,#00C475,#00C475,#25BC8A,#25BC8A,#25BC8A,#25BC8A,#4800FF,#6474FC,#009DFF,#A24CED,#294BE5,#317237";}
else if(colorSet=='contrast') {colorScheme="#935456,#009DFF,#A24CED,#294BE5,#317237,#935456,#009DFF,#A24CED,#294BE5,#317237,#935456";}
else if(colorSet=='gray shades') {colorScheme="#ffffff,#dddddd,#aaaaaa,#777777,#555555";}
else if(colorSet=='haxor green') {colorScheme="#1C8E31,#16AD43,#1BD352,#18F45A,#54F284,#69D389,#A1EDB8";}
else {
colorScheme="$$customStyle$$";
defaultColor = "$$defaultColor$$";
defaultBackground = "$$defaultBackground$$";
}
colorScheme = colorScheme.split(',');
raw = (document.getElementById(codeblock).innerHTML).split('\n').join('<br>');
raw = raw.split('\t').join(' ');
colorArray = new Array();
for(long=0;long<raw.length;long++){
colorArray[long] = defaultColor;
}
rawArr = raw.split('');
lowercaseRaw=raw.toLowerCase();
justletters=lowercaseRaw.replace(/[^a-z0-9]/g," ");
justletters=justletters.replace(/\s+/g," ");
myarray=("< > & &lt; &gt; / ' { } = ( )"+' " '+justletters).split(' ');
y = 0;
result = new Array();
myarray=myarray.sort();
result[0]=myarray[0];
for(x=1;x<myarray.length;x++){
if(myarray[x]!=myarray[x-1]){
result[y]=myarray[x];
y++;
}
}
result=result.sort(function(a,b){return a.length - b.length});
if(result!=-1){
for(x=0;x<result.length;x++){
locations = findInString(result[x], lowercaseRaw);
if(locations!=-1){
for (ww = 0; ww < locations.length; ww++) {
for(zz=0;zz<result[x].length;zz++){
if(x>=colorScheme.length){
colorScheme = colorScheme.concat(colorScheme);
}
colorArray[1 * locations[ww] + zz] = colorScheme[x];
}
}
}
}
}
var output = '<ol start="0"><li><span style="color:'+colorArray[0]+'">';
var theOldColor = colorArray[0];
for (CharacterPointer=0;CharacterPointer<raw.length;CharacterPointer++){
theLetter=rawArr[CharacterPointer];
theColor=colorArray[CharacterPointer];
theFutureColor=colorArray[CharacterPointer*1+1];
if(theLetter=="<"){
if(lowercaseRaw.substring(CharacterPointer, (1*CharacterPointer+4))=="<br>"){
theLetter="</li><li>";
CharacterPointer=CharacterPointer*1+3;
// theOldColor=colorArray[CharacterPointer*1-1];
}
}
if (theLetter==" ") {
theLetter=" <wbr>";
}
if (theColor == theOldColor && theColor == theFutureColor) {
output = output + theLetter;
} else if (theColor == theOldColor&&CharacterPointer>1) {
output = output + theLetter + '</span>';
} else if (theColor == theFutureColor) {
output = output + '</span><span style="color:' + theColor + ';">' + theLetter;
} else {
output = output + '<span style="color:' + theColor + ';">' + theLetter + '</span>';
}
theOldColor=colorArray[CharacterPointer];
}
document.getElementById(codeblock).innerHTML = '<div style="font-weight:bold;font-family:\'Courier New\', Times, serif;color:'+defaultColor+';font-size:14px;padding:4px 0px 4px 4px;background-color:'+defaultBackground+';">'+output+"</div>";
}
function findInString(searchFor, searchIn) {
var results = new Array();
var yy = 0;
var aa = searchIn.indexOf(searchFor);
results[0] = aa;
searchIn = searchIn.slice(aa * 1 + searchFor.length);
yy = aa * 1 + searchFor.length;
if (aa != -1) {
for (xx = 1; searchIn.indexOf(searchFor) != -1; xx++) {
yy = searchIn.indexOf(searchFor)
results[xx] = 1 * results[1 * xx - 1] + searchIn.indexOf(searchFor) + searchFor.length;
searchIn = searchIn.slice(1 * searchIn.indexOf(searchFor) + searchFor.length);
}
}
return results;
}
Your colored code:
credits
The nice color picker is from johndyer.name. If you want to use it remember that the file names have capitals and the example uses lower case file names. On local host it will work just fine like that.