인터넷정보

강좌 설명시 html, script등의 내용을 컬로 코드로 변환

알 수 없는 사용자 2007. 10. 18. 14:15


<!--
/*******************************************************/
/* Make Syntax                                         */
/* Programmed by Powring                               */
/* powring @hotmail.com                                */
/* 2004-10-24                                          */
/*******************************************************/
// {{
// 전역 변수 {{
// 구문 강조 구분
var Syntax=new Array(7);
Syntax[0]=new Array("//","/*","*/");
Syntax[1]=new Array(",","(",")","{","}","[","]","-","+","*","%","/","=","\"","\'","~","!","&","|","<",">","?",":",";",".");
Syntax[2]=new Array("abstract","boolean","break","byte","case","catch","char","class","const","continue","default","delete","do","double","else","extends","false","final","finally","float","for","function","goto","if","implements","import","in","instanceof","int","interface","long","native","new","null","package","private","protected","public","return","short","static","super","switch","synchronized","this","throw","throws","transient","true","try","typeof","var","void","while","with");
Syntax[3]=new Array("anchor","applet","area","Array","button","checkbox","Date","document","event","FileUpload","form","frame","hidden","history","image","layer","link","location","Math","mimeType","navigator","Number","Password","Plugin","Radio","RegExp","reset","screen","select","string","submit","textarea","window");
Syntax[4]=new Array("above","abs","acos","action","alert","alinkColor","anchors","appCodeName","applets","appName","appVersion","arguments","asin","atan","atan2","back","background","below","bgColor","big","blink","blur","bold","border","bottom","caller","captureEvents","ceil","charAt","charCodeAt","checked","clear","clearInterval","clearTimeout","click","clip","close","closed","compile","complete","concat","confirm","cookie","cos","current","data","defaultChecked","defaultStatus","defaultValue","description","disableExternalCapture","domain","E","elements","embeds","enableExternalCapture","enablePlugin","encoding","eval","exec","exp","fgColor","filename","find","fixed","floor","focus","fontcolor","fontsize","forms","forward","frames","fromCharCode","getDate","getDay","getHours","getMinutes","getMonth","getSeconds","getSelection","getTime","getTimezoneOffset","getYear","global","go","handleEvent","hash","height","home","host","hostname","href","hspace","ignoreCase","images","indexOf","innerHeight","innerWidth","input","isNaN","italics","javaEnabled","join","language","lastIndex","lastIndexOf","lastMatch","lastModified","lastParen","layers","layerX","layerY","left","leftContext","length","link","linkColor","links","LN10","LN2","load","location","locationbar","log","LOG10E","LOG2E","lowsrc","match","max","MAX_VALUE","menubar","method","mimeTypes","min","MIN_VALUE","modifiers","moveAbove","moveBelow","moveBy","moveTo","moveToAbsolute","multiline","name","NaN","NEGATIVE_INFINITY","next","open","opener","options","outerHeight","outerWidth","pageX","pageXOffset","pageY","pageYOffset","parent","parentLayer","parse","parseFloat()","parseInt()","pathname","personalbar","PI","platform","plugins","pop","port","POSITIVE_INFINITY","pow","previous","print","prompt","protocol","prototype","push","random","referrer","releaseEvents","releaseEvents","reload","replace","replace","reset","resizeBy","resizeTo","reverse","right","rightContext","round","routeEvent","screenX","screenY","scroll","scrollbars","scrollBy","scrollTo","search","search","select","selectedIndex","self","setDate","setHours","setInterval","setMinutes","setMonth","setSeconds","setTime","setTimeout","setYear","shift","siblingAbove","siblingBelow","sin","slice","small","sort","source","splice","split","sqrt","SQRT1_2","SQRT2","src","status","statusbar","stop","strike","sub","submit","substr","substring","suffixes","sup","taintEnabled","tan","target","test","text","title","toGMTString","toLocaleString","toLowerCase","toolbar","top","toString","toUpperCase","type","unshift","userAgent","UTC","value","valueOf","visibility","vlinkColor","vspace","which","width","write","writeln","zIndex");
Syntax[5]=new Array("onAbort","onAfterUpdate","onBeforeUnload","onBeforeUpdate","onBlur","onChange","onClick","onDataAvailable","onDataSetChanged","onDataSetComplete","onDblClick","onDragDrop","onDragStart","onError","onErrorUpdate","onFilterChange","onFocus","onHelp","onKeyDown","onKeyPress","onKeyUp","onLoad","onMouseDown","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onMove","onReadyStateChange","onReset","onResize","onRowEnter","onRowExit","onScroll","onSelect","onSelectStart","onSubmit","onUnLoad");
Syntax[6]=new Array(" ","\\","\n","\t","\'","\"","/");

// 강조색
var SyntaxColor=new Array("#008080","#828282","#0000FF","#FF0000","#CD853F","#8B4513","#FF1493");

//탭크기
var TabSize=2;
// }} 전역 변수

// 내부 함수 {{
function isString(list, str) {
 var i;

 for(i=0;i<list.length;i++) {
  if(str==list[i]) return i+1;
 }

 return 0;
}
// }} 내부 함수

// 사용자 함수 {{
// 구문 강조 색 재지정 (주석, 연산자, 키워드, 객체, 속성, 이벤트, 문자열)
function SetSyntaxColor(c1, c2, c3, c4, c5, c6, c7) {
 SyntaxColor[0]=c1;
 SyntaxColor[1]=c2;
 SyntaxColor[2]=c3;
 SyntaxColor[3]=c4;
 SyntaxColor[4]=c5;
 SyntaxColor[5]=c6;
 SyntaxColor[6]=c7;
}

// 탭 크기 변경
function SetTabSize(t) {
 TabSize=(t<0?2:t);
}

// 구문 강조 함수 입구
function MakeSyntax(str) {
 var i=0,j=0;
 var token="";
 var nowchar="";

 document.write("<pre>");

 for(i=0;i<=str.length;i++) {
  nowchar=(i<str.length?str.charAt(i):"");
  if(isString(Syntax[6],nowchar) || isString(Syntax[1],nowchar) || i==str.length) {
   if(token.length>0) {
    var kind=0;

    for(j=2;j<=5;j++) {
     if(isString(Syntax[j],token)) {
      kind=j;
      break;
     }
    }
 
    if(kind) {
     document.write("<font color=\""+SyntaxColor[kind]+"\">");
     document.write(token);
     document.write("</font>");
    } else {
     document.write(token);
    }
   }

   if(nowchar==' ') {
    document.write(" ");
   } else if(nowchar=='\\') {
    document.write(nowchar+str.charAt(++i));
   } else if(nowchar=='\n') {
    document.write("<br>");
   } else if(nowchar=='\t') {
    for(j=0;j<TabSize;j++) {
     document.write(" ");
    }
   } else if(nowchar=='\'' || nowchar=='\"') {
    document.write("<font color=\""+SyntaxColor[6]+"\">"+nowchar);

    for(j=i+1;j<str.length;j++) {
     var strchar=str.charAt(j);
     ++i;

     if(strchar==' ') {
      document.write(" ");
      continue;
     } else if(strchar=='\n') {
      document.write("<br>");
      continue;
     } else if(strchar=='\\') {
      document.write(strchar+str.charAt(j+1));
      ++j;
      ++i;
      continue;
     } else if(strchar=='<') {
      document.write("&lt;");
      continue;
     } else if(strchar=='>') {
      document.write("&gt;");
      continue;
     } else if(strchar==nowchar) {
      document.write(nowchar);
      break;
     }

     document.write(strchar);
    }

    document.write("</font>");
   } else if(nowchar=='/') {
    if(i+1<=str.length) {
     var nextchar=str.charAt(i+1);

     if(nextchar=='/') {
      document.write("<font color=\""+SyntaxColor[0]+"\">//");
      ++i;

      for(j=i+1;j<str.length;j++) {
       var cmtchar=str.charAt(j);
       ++i;

       if(cmtchar==' ') {
        document.write(" ");
        continue;
       } else if(cmtchar=='\n') {
        document.write("<br>");
        break;
       } else if(strchar=='<') {
        document.write("&lt;");
        continue;
       } else if(strchar=='>') {
        document.write("&gt;");
        continue;
       }

       document.write(cmtchar);
      }

      document.write("</font>");
     } else if(nextchar=='*') {
      document.write("<font color=\""+SyntaxColor[0]+"\">/*");
      ++i;

      for(j=i+1;j<str.length;j++) {
       var cmtchar=str.charAt(j);
       ++i;

       if(cmtchar==' ') {
        document.write(" ");
        continue;
       } else if(cmtchar=='\n') {
        document.write("<br>");
        continue;
       } else if(cmtchar=='*' && str.charAt(j+1)=='/') {
        document.write("*/");
        ++i;
        break;
       } else if(strchar=='<') {
        document.write("&lt;");
        continue;
       } else if(strchar=='>') {
        document.write("&gt;");
        continue;
       }

       document.write(cmtchar);
      }         

      document.write("</font>");
     } else {
      document.write("<font color=\""+SyntaxColor[1]+"\">/</font>");
     }
    } else {
     document.write("<font color=\""+SyntaxColor[1]+"\">/</font>");
    }
   } else {
    if(nowchar=='<') {
     nowchar="&lt;";
    } else if(nowchar=='>') {
     nowchar="&gt;"
    }
   
    document.write("<font color=\""+SyntaxColor[1]+"\">");
    document.write(nowchar);
    document.write("</font>");
   }

   token="";
  } else {
   token=token+nowchar;
  }
 }

 document.write("</pre>");
}

// 스트링에 찍기
function MakeSyntaxToString(str) {
 var i=0,j=0;
 var token="";
 var nowchar="";
 var ResultString="";

 ResultString=ResultString+"<pre>";

 for(i=0;i<=str.length;i++) {
  nowchar=(i<str.length?str.charAt(i):"");
  if(isString(Syntax[6],nowchar) || isString(Syntax[1],nowchar) || i==str.length) {
   if(token.length>0) {
    var kind=0;

    for(j=2;j<=5;j++) {
     if(isString(Syntax[j],token)) {
      kind=j;
      break;
     }
    }
 
    if(kind) {
     ResultString=ResultString+"<font color=\""+SyntaxColor[kind]+"\">";
     ResultString=ResultString+token;
     ResultString=ResultString+"</font>";
    } else {
     ResultString=ResultString+token;
    }
   }

   if(nowchar==' ') {
    ResultString=ResultString+" ";
   } else if(nowchar=='\\') {
    ResultString=ResultString+nowchar+str.charAt(++i);
   } else if(nowchar=='\n') {
    ResultString=ResultString+"<br>";
   } else if(nowchar=='\t') {
    for(j=0;j<TabSize;j++) {
     ResultString=ResultString+" ";
    }
   } else if(nowchar=='\'' || nowchar=='\"') {
    ResultString=ResultString+"<font color=\""+SyntaxColor[6]+"\">"+nowchar;

    for(j=i+1;j<str.length;j++) {
     var strchar=str.charAt(j);
     ++i;

     if(strchar==' ') {
      ResultString=ResultString+" ";
      continue;
     } else if(strchar=='\n') {
      ResultString=ResultString+"<br>";
      continue;
     } else if(strchar=='\\') {
      ResultString=ResultString+strchar+str.charAt(j+1);
      ++j;
      ++i;
      continue;
     } else if(strchar=='<') {
      ResultString=ResultString+"&lt;";
      continue;
     } else if(strchar=='>') {
      ResultString=ResultString+"&gt;";
      continue;
     } else if(strchar==nowchar) {
      ResultString=ResultString+nowchar;
      break;
     }

     ResultString=ResultString+strchar;
    }

    ResultString=ResultString+"</font>";
   } else if(nowchar=='/') {
    if(i+1<=str.length) {
     var nextchar=str.charAt(i+1);

     if(nextchar=='/') {
      ResultString=ResultString+"<font color=\""+SyntaxColor[0]+"\">//";
      ++i;

      for(j=i+1;j<str.length;j++) {
       var cmtchar=str.charAt(j);
       ++i;

       if(cmtchar==' ') {
        ResultString=ResultString+" ";
        continue;
       } else if(cmtchar=='\n') {
        ResultString=ResultString+"<br>";
        break;
       } else if(strchar=='<') {
        ResultString=ResultString+"&lt;";
        continue;
       } else if(strchar=='>') {
        ResultString=ResultString+"&gt;";
        continue;
       }

       ResultString=ResultString+cmtchar;
      }

      ResultString=ResultString+"</font>";
     } else if(nextchar=='*') {
      ResultString=ResultString+"<font color=\""+SyntaxColor[0]+"\">/*";
      ++i;

      for(j=i+1;j<str.length;j++) {
       var cmtchar=str.charAt(j);
       ++i;

       if(cmtchar==' ') {
        ResultString=ResultString+" ";
        continue;
       } else if(cmtchar=='\n') {
        ResultString=ResultString+"<br>";
        continue;
       } else if(cmtchar=='*' && str.charAt(j+1)=='/') {
        ResultString=ResultString+"*/";
        ++i;
        break;
       } else if(strchar=='<') {
        ResultString=ResultString+"&lt;";
        continue;
       } else if(strchar=='>') {
        ResultString=ResultString+"&gt;";
        continue;
       }

       ResultString=ResultString+cmtchar;
      }         

      ResultString=ResultString+"</font>";
     } else {
      ResultString=ResultString+"<font color=\""+SyntaxColor[1]+"\">/</font>";
     }
    } else {
     ResultString=ResultString+"<font color=\""+SyntaxColor[1]+"\">/</font>";
    }
   } else {
    if(nowchar=='<') {
     nowchar="&lt;";
    } else if(nowchar=='>') {
     nowchar="&gt;"
    }
   
    ResultString=ResultString+"<font color=\""+SyntaxColor[1]+"\">";
    ResultString=ResultString+nowchar;
    ResultString=ResultString+"</font>";
   }

   token="";
  } else {
   token=token+nowchar;
  }
 }

 ResultString=ResultString+"</pre>";

 return ResultString;
}

// }} 사용자 함수
// }} Make Syntax
//-->

반응형