variables.colors=structnew();
// Initialize styles for various types of elements
//
// Default text color that is outside a tag
setStyle("TEXT","color:##000000");
// Comments
// Greyed out
setStyle("HTMLCOMMENT","color:##008000");
// Yellow highlight with black text
setStyle("CFCOMMENT","color:##333333;background-color:##FFFF00");
// CF Tags
setStyle("CFTAG","color:##990033");
setStyle("CFSET","color:##000000");
setStyle("SCRIPT","color:##000000");
// HTML Tags
setStyle("HTML","color:##008080");
setStyle("HTMLSTYLES","color:##990099");
setStyle("HTMLTABLES","color:##009999");
setStyle("HTMLFORMS","color:##FF9900");
// VALUES
setStyle("VALUE","color:##0000CC");
setStyle("SCRIPTVALUE","color:##006600");
// BINDS
setStyle("BIND","color:##000099");
//initialize a buffer
// If you're using JDK 1.5 or later and want some extra performance this can be a StringBuilder
//variables.buffer=createObject("java","java.lang.StringBuilder").init();
variables.buffer=createObject("java","java.lang.StringBuffer").init();
// initialize private variables
variables.isCommented=false;
variables.isTag=false;
variables.isValue=false;
variables.isCFSETTag=false;
variables.isScript=false;
variables.isOneLineComment=false;
var BIstream = createObject("java","java.io.StringBufferInputStream").init(code);
var IStream = createObject("java","java.io.InputStreamReader").init(BIstream);
var reader = createObject("java","java.io.BufferedReader").init(IStream);
var line = reader.readLine();
initializeVariables();
bufferAppend(""); // start the default text color
while (isdefined("line")) {
formatLine(line);
line = reader.readLine();
}
bufferAppend("");
reader.close();
return buffer;
var character = "";
var thisLine=arguments.line;
var i =0;
if (variables.isOneLineComment) endOneLineComment();
for (i=0; i LT thisLine.length(); i=i+1)
{
character=thisLine.charAt(javacast('int',i));
if (character EQ '<')
{
if (variables.isScript AND NOT variables.isValue)
endScript();
if (regionMatches(thisLine, 1, i+1, "!--", 0, 3))
{
if (regionMatches(thisLine, 1, i+4, "-", 0, 1))
{
startComment("CF");
} else {
startComment("HTML");
}
} else {
if (regionMatches(thisLine, 1, i+1, "CF", 0, 2) OR regionMatches(thisLine, 1, i+1, "/CF", 0, 3))
{
startTag("CF");
if (regionMatches(thisLine, 1, i+3, "SET", 0, 3) AND NOT regionMatches(thisLine, 1, i+6, "T", 0, 1)) // CFSET Tag
{
bufferAppend(substring(thisLine,i+1,i+6));
i=i+5;
startCFSET();
}
else if (regionMatches(thisLine, 1, i+3, "SCRIPT>", 0, 6)) // SCRIPT TAG
{
bufferAppend(substring(thisLine, i+1, i+9) & ">");
i=i+9;
startScript();
}
}
else if (
regionMatches(thisLine, 1, i+1, "TA", 0, 2) OR
regionMatches(thisLine, 1, i+1, "/TA", 0, 3) OR
regionMatches(thisLine, 1, i+1, "TB", 0, 2) OR
regionMatches(thisLine, 1, i+1, "/TB", 0, 3) OR
regionMatches(thisLine, 1, i+1, "TD", 0, 2) OR
regionMatches(thisLine, 1, i+1, "/TD", 0, 3) OR
regionMatches(thisLine, 1, i+1, "TF", 0, 2) OR
regionMatches(thisLine, 1, i+1, "/TF", 0, 3) OR
regionMatches(thisLine, 1, i+1, "TH", 0, 2) OR
regionMatches(thisLine, 1, i+1, "/TH", 0, 3) OR
regionMatches(thisLine, 1, i+1, "TR", 0, 2) OR
regionMatches(thisLine, 1, i+1, "/TR", 0, 3)
) // HTML TABLE
{
startTag("HTMLTABLES");
}
else if (regionMatches(thisLine, 1, i+1, "IMG", 0, 3) OR regionMatches(thisLine, 1, i+1, "STY", 0, 3) OR regionMatches(thisLine, 1, i+1, "/STY", 0, 4)) //IMG or STYLE Tag
// TODO: Do separate syntax highlighting for stuff inside style
{
startTag("HTMLSTYLES");
}
else if (
regionMatches(thisLine, 1, i+1, "FORM", 0, 4) OR
regionMatches(thisLine, 1, i+1, "/FORM", 0, 5) OR
regionMatches(thisLine, 1, i+1, "INPUT", 0, 5) OR
regionMatches(thisLine, 1, i+1, "/INPUT", 0, 5) OR
regionMatches(thisLine, 1, i+1, "TEXT", 0, 4) OR
regionMatches(thisLine, 1, i+1, "/TEXT", 0, 5) OR
regionMatches(thisLine, 1, i+1, "SELECT", 0, 6) OR
regionMatches(thisLine, 1, i+1, "/SELECT", 0, 7) OR
regionMatches(thisLine, 1, i+1, "OPT", 0, 3) OR
regionMatches(thisLine, 1, i+1, "/OPT", 0, 3)
)
{
startTag("HTMLFORMS");
} else {
startTag("HTML");
}
}
}
else if (character EQ '>')
{
if (variables.isCommented AND regionMatches(thisLine, 1, i-2, "--", 0, 2))
{
if (regionMatches(thisLine, 1, i-3, "-", 0, 1))
{
endComment("CF");
} else {
endComment("HTML");
}
} else {
if (variables.isCFSETTag) {
endCFSET();
} else {
endTag();
}
}
}
else if (character EQ '"')
{
if (variables.isTag OR variables.isScript)
{
if (NOT variables.isValue) {
startValue();
bufferAppend('"');
} else {
bufferAppend('"');
endValue();
}
} else {
bufferAppend('"');
}
}
else if (character EQ '{')
{
startBind();
bufferAppend("{");
endBind();
}
else if (character EQ '}')
{
startBind();
bufferAppend("}");
endBind();
}
else if (character EQ '/')
{
if (variables.isScript AND regionMatches(thisLine, 1, i+1, "/", 0, 1))
{
startOneLineComment();
}
else if (variables.isCommented)
{
if (regionMatches(thisLine, 1, i-1, "*", 0, 1))
{
endComment("SCRIPT");
} else {
bufferAppend("/");
}
} else {
if (regionMatches(thisLine, 1, i+1, "*", 0, 1))
{
startComment("SCRIPT");
} else {
bufferAppend("/");
}
}
}
// straight up replacements
else if (character EQ '\t' OR character EQ ' ')
{
bufferAppend(" ");
}
else if (character EQ ' ')
{
bufferAppend("#32;");
} else {
bufferAppend(character.toString());
}
}
bufferAppend("
");
")/>
")/>
startHighlight("HTMLCOMMENT");
bufferAppend("/");
variables.isOneLineComment=true;
variables.isCommented=true;
endHighlight();
variables.isOneLineComment=false;
variables.isCommented=false;
if (type EQ "CF") {
startHighlight("CFCOMMENT");
bufferAppend("<");
} else if (type EQ "HTML") {
startHighlight("HTMLCOMMENT");
bufferAppend("<");
} else if (type EQ "SCRIPT") {
startHighlight("HTMLCOMMENT");
bufferAppend("/");
}
variables.isCommented=true;
if (type EQ "SCRIPT") {
bufferAppend("/");
} else {
bufferAppend(">");
}
endHighlight();
variables.isCommented=false;
if (NOT variables.isCommented AND NOT variables.isValue) {
if (type EQ "CF") {
startHighlight("CFTAG");
} else if (type EQ "HTMLSTYLES") {
startHighlight("HTMLSTYLES");
} else if (type EQ "HTMLTABLES") {
startHighlight("HTMLTABLES");
} else if (type EQ "HTMLFORMS") {
startHighlight("HTMLFORMS");
} else { // type is HTML
startHighlight("HTML");
}
variables.isTag=true;
}
bufferAppend("<");
bufferAppend(">");
if (NOT variables.isCommented AND NOT variables.isValue) {
endHighlight();
variables.isTag=false;
}
if (NOT variables.isCommented) {
if (variables.isCFSETTag OR variables.isScript) {
startHighlight("SCRIPTVALUE");
} else {
startHighlight("VALUE");
}
variables.isValue=true;
}
if (NOT variables.isCommented) {
endHighlight();
variables.isValue=false;
}
if (NOT variables.isCommented) {
startHighlight("BIND");
bindDef=true;
}
if (NOT variables.isCommented) {
endHighlight();
bindDef=false;
}
if (NOT variables.isCommented) {
startHighlight("CFSET");
variables.isCFSETTag=true;
}
if (NOT variables.isCommented) {
endHighlight();
bufferAppend(">");
endHighlight();
variables.isCFSETTag=false;
} else {
bufferAppend(">");
}
if (NOT variables.isCommented) {
endHighlight();
startHighlight("SCRIPT");
variables.isScript=true;
}
if (NOT variables.isCommented) {
endHighlight();
variables.isScript=false;
}