44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
|
|
//Colour constants
|
|
var fc_cmt = "#888";
|
|
var fc_html = "#11a";
|
|
var fc_quot = "#a24";
|
|
var fc_kwds = "#008";
|
|
|
|
//Language keywords
|
|
var fc_java_kwds = "public|int|float|double|private|new|void|synchronized|if|for|byte|break|else";
|
|
|
|
var pres = document.getElementsByTagName("pre");
|
|
for (var a = 0; a < pres.length; a++) {
|
|
var elem = pres[a];
|
|
if (elem.className.toLowerCase() == 'code') formatCode(elem);
|
|
}
|
|
|
|
function formatCode(precode) {
|
|
var lang = 'html';
|
|
if (!precode.split) return;
|
|
var textlines = precode.split(/\r|\n/);
|
|
var linecount = 1;
|
|
var newcode = "";
|
|
for (var b = 0; b < textlines.length; b++) {
|
|
var code = textlines[b];
|
|
code = code.replace(/\f|\n/g, "");
|
|
code = code.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
code = code.replace(/(".+")/g, "<span style=\"clear: both; padding: 0px; margin: 0px; color: " + fc_quot + ";\">$1</span>");
|
|
code = code.replace(/('.+')/g, "<span style=\" clear: both; padding: 0px; margin: 0px; color: " + fc_quot + ";\">$1</span>");
|
|
code = code.replace(/<(\S.*?)>/g, "<span style=\"clear: both; padding: 0px; margin: 0px; color: " + fc_html + ";\"><$1></span>");
|
|
code = code.replace(/<!--/g, "<span style=\"clear: both; padding: 0px; margin: 0px; color: " + fc_cmt + ";\"><!--");
|
|
code = code.replace(/-->/g, "--></span>");
|
|
var formatline = (" " + linecount).slice(-3);
|
|
newcode += code + "<div/>";
|
|
linecount++;
|
|
}
|
|
|
|
return "<pre style='width: 700px; max-width: 700px; margin: 10px;' class='code'>" + newcode + "</pre>";
|
|
}
|
|
|
|
function colourKeywords(keywords, codeline) {
|
|
var wordre = new RegExp("(" + keywords + ") ", "gi");
|
|
return codeline.replace(wordre, "<span style=\"color: " + fc_kwds + ";\">$1 </span>");
|
|
}
|
|
|