소스 전체 복사 및 소스 하이라이트
페이지 정보
작성자 서방님 댓글 0건 조회 418회 작성일 07-08-07 17:30본문
<script language="javascript">
<!--
//정규식으로 본문을 편집하게 해주는것
function replaceReg(id, re, reRusult, flag){
var target = eval("document.getElementById('" + id + "')");
re = eval("/" + re + "/" + flag);
if(id == "iView"){
target.innerHTML = target.innerHTML.replace(re, reRusult);
}else{
target.value = target.value.replace(re, reRusult);
}
}
function hightlightCode(sort){
if(document.getElementById('isHighLighted').value != 0){
alert("이미 하이라이트 되었습니다.");
return true;
}
var source = document.getElementById('sourcecode').innerHTML;
source = source.replace(/ /gi, "▒");
var re;
switch(sort){
case 0 : //HTML, Style, JavaScript
////////////////////HTML//////////////////////
re = "\/?table|\/?tr|\/?td";
re = eval("/(<(?:" + re + ")w?.*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#008080▩>$1</span>");
re = "\/?body|\/?b|br|\/?center|\/?div|\/?font|H1|H2|H3|H4|H5|H6|\/?hr|\/?head|\/?html|\/?i|\/?marquee|meta|nobr|\/?span|\/?p|\/?strong|\/?sub|\/?sup|\/?title|link";
re = eval("/(<(?:" + re + ")w?.*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#000084▩>$1</span>");
re = "\/?form|input|\/?option|\/?select|\/?textarea";
re = eval("/(<(?:" + re + ")w?.*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#ff8200▩>$1</span>");
re = "\/?a";
re = eval("/(<(?:" + re + ")w?.*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#008200▩>$1</span>");
re = "img";
re = eval("/(<(?:" + re + ")w?.*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#840084▩>$1</span>");
re = "\/?object|\/?embed|param";
re = eval("/(<(?:" + re + ")w?.*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#848200▩>$1</span>");
//문자열처리
source = commentProcess(source, "".*?"", "gi", "#0000ff", 0)
//HTML 주석처리
source = commentProcess(source, "<!--.*?-->", "gim", "#808080", 0)
///////////////////////////style 처리/////////////////////////////////
re = /(<style.*?</style>)/gim;
matchResults = source.match(re);
if(matchResults){
//다른 테그로 인해 붙은것들 없앰 - style 덩어리단위
for (i=0; i<matchResults.length; i++){
matchTemp = matchResults[i].replace(/<[^b].*?>/gi, "");
re = "ascent|azimuth|background-attachment|background-color|background-image|background-position|background-repeat|background|baseline|bbox|border-collapse|border-color|border-spacing|border-style|border-top-color|border-right-color|border-bottom-color|border-left-color|border-top-style|border-right-style|border-bottom-style|border-left-style|border-top-width|border-right-width|border-bottom-width|border-left-width|border-width|border-top|border-right|border-bottom|border-left|border|bottom|cap-height|caption-side|centerline|clear|clip|color|counter-increment|counter-reset|content|cue-after|cue-before|cue|cursor|definition-src|descent|direction|display|elevation|empty-cells|float|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|font|height|left|letter-spacing|line-height|list-style|list-style-image|list-style-position|list-style-type|margin-top|margin-right|margin-bottom|margin-left|margin|marker-offset|marks|mathline|max-height|max-width|min-height|min-width|orphans|outline-color|outline-style|outline-width|outline|overflow-x|overflow-y|overflow|padding-top|padding-right|padding-bottom|padding-left|padding|page-break-after|page-break-before|page-break-inside|page|panose-1|pause-after|pause-before|pause|pitch-range|pitch|play-during|position|quotes|richness|right|scrollbar-face-color|scrollbar-base-color|scrollbar-darkshadow-color|scrollbar-shadow-color|scrollbar-highlight-color|scrollbar-3dlight-color|scrollbar-arrow-color|scrollbar-track-color|size|slope|src|speak-header|speak-numeral|speak-punctuation|speak|speech-rate|stemh|stemv|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|unicode-bidi|unicode-range|units-per-em|vertical-align|visibility|voice-family|volume|white-space|widows|width|widths|word-break|word-spacing|x-height|z-index";
matchTemp = specialProcess(matchTemp, "\{.*?\}", re, "gim", "#0000ff", 0)
re = /(:)(.*?)((?:;|}))/gi;
matchTemp = matchTemp.replace(re, "<span id〓HL style〓color▦#000080;font♨weight▦bold▩>$1</span><span id〓HL style〓color▦#ff0000▩>$2</span><span id〓HL style〓color▦#000080;font♨weight▦bold▩>$3</span>");
re = /({|}|.)/gi;
matchTemp = matchTemp.replace(re, "<span id〓HL style〓color▦#000080;font♨weight▦bold▩>$1</span>");
//여러줄 주석처리
matchTemp = commentProcess(matchTemp, "\/\*.*?\*\/", "gim", "#808080", 0)
source = source.replace(matchResults[i], matchTemp);
}
}
re = "\/?style";
re = eval("/(<(?:" + re + ").*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#840084▩>$1</span>");
///////////////////////////Javascript 테그속의 내용만 하이라이팅처리 ////////////////////////////////////
re=/<script.*?</script>/gim;
matchResults = source.match(re);
if(matchResults){
//다른 테그로 인해 붙은것들 없앰 - script 덩어리단위
for (i=0; i<matchResults.length; i++){
matchTemp = matchResults[i].replace(/<[^b].*?>/gi, "");
source = source.replace(matchResults[i], javascriptProcess(matchTemp));
}
}
re = "\/?script";
re = eval("/(<(?:" + re + ").*?>)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#840000▩>$1</span>");
///////////////////////////XML 처리 ////////////////////////////////////
re=/<?xml.*?</xml>/gim;
matchResults = source.match(re);
if(matchResults){
//다른 테그로 인해 붙은것들 없앰 - xml 덩어리단위
for (i=0; i<matchResults.length; i++){
matchTemp = matchResults[i].replace(/<[^b].*?>/gi, "");
re = eval("/(<.*?>)/gi");
matchTemp = matchTemp.replace(re, "<span id〓HL style〓color▦#3333cc▩>$1</span>");
source = source.replace(matchResults[i], matchTemp);
}
}
re = /(<(?:?xml|/xml).*?>)/gi;
source = source.replace(re, "<span id〓HL style〓color▦#ff0000▩>$1</span>");
break;
case 3 : //MSSQL
//키워드
re = "ABSOLUTE|ACTION|[^e]ADD|ALTER|ASC\(|ASSERTION|[▒\)]AS[▒\(]|▒AT▒|AUTHORIZATION|BACKUP|BEGIN|BINARY|BIT|BREAK|BROWSE|BULK|BY|CASCADE|[▒,]CHAR[\(]|CHARACTER|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COLLATE|COLUMN|COMMIT|COMPUTE|CONNECT|CONNECTION|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CREATE|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|▒CURSOR▒|DATABASE|[^t]DATE[^pat]|DATETIME|DBCC|DEALLOCATE|▒DEC▒|DECIMAL|DECLARE|DEFAULT|DELETE|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DROP|DUMMY|DUMP|ELSE▒|END|ERRLVL|ESCAPE|EXCEPT|EXEC|EXECUTE|EXIT|FALSE|FETCH|FILE|FILLFACTOR|FIRST|FLOAT|FOR|FOREIGN|FREETEXT|FREETEXTTABLE|FROM▒|FULL|FUNCTION|GLOBAL|GOTO|GO|GRANT|GROUP|HAVING|HOLDLOCK|HOUR|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF▒|IMMEDIATE|INCLUDE|[^rt]INDEX|INDICATOR|INITIALLY|INNER|INPUT|INSENSITIVE|INSERT|INTEGER|INTERSECT|INTERVAL|INTO|[,▒]INT[,▒]?|[▒\)]IS[▒\(]|ISOLATION|KEY|KILL|LANGUAGE|LAST|LEADING|LEVEL|LINENO|LOAD|LOCAL|MATCH|MAX|MIN|MINUTE|MODULE|NAMES|NATIONAL|NATURAL|NCHAR|NEXT|▒NO▒|NOCHECK|NONCLUSTERED|NONE|NTEXT|NUMERIC|NVARCHAR|OCTET_LENGTH|▒OF▒|OFF|OFFSETS|ONLY|[▒]ON[▒]?|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|OPTION|▒OR▒|ORDER|OUTPUT|OVER|OVERLAPS|PAD|PARTIAL|PASCAL|PERCENT|PLAN|POSITION|PRECISION|PREPARE|PRESERVE|PRIMARY|PRINT|PRIOR|PRIVILEGES|PROCEDURE|PROC|PUBLIC|RAISERROR|READ|READTEXT|REAL|RECONFIGURE|REFERENCES|RELATIVE|REPLICATION|RESTORE|RESTRICT|RETURN|REVOKE|ROLLBACK|ROWCOUNT|ROWGUIDCOL|ROWS|RULE|SAVE|SCHEMA|SCROLL|SECOND|SECTION|SELECT|SESSION|SESSION_USER|SET|SETUSER|SHUTDOWN|SIZE|SMALLINT|SQL|SQLCA|SQLCODE|SQLERROR|SQLSTATE|SQLWARNING|STATISTICS|SYSNAME|SYSTEM_USER|TABLE|TEMPORARY|TEXTSIZE|THEN|[^e]TIME|TIMESTAMP|TIMEZONE_HOUR|TIMEZONE_MINUTE|▒TO▒|TOP|TRAILING|TRAN|TRANSACTION|TRANSLATE|TRANSLATION|TRIGGER|TRUE|TRUNCATE|TSEQUAL|UNION|UNIQUE|UNKNOWN|UPDATE|UPDATETEXT|USAGE|USER▒|USE▒|USING|VALUE|VALUES|VARCHAR|VARYING|VIEW|WAITFOR|WHEN|WHENEVER|WHERE|WHILE|WITH|WORK|WRITE|WRITETEXT|ZONE";
re = eval("/(" + re + ")([<]?)/gi");
source = source.replace(re, "<span id〓HL style〓color▦#0000ff▩>$1</span>$2");
//연산자
re = "ALL|AND|ANY|BETWEEN|CROSS|EXISTS|IN|JOIN|LIKE|NOT|NULL|OUTER|SOME"
re = eval("/([▒<>=+\-\(])(" + re + ")([▒\(])/gi");
source = source.replace(re, "$1<span id〓HL style〓color▦#666666;>$2</span>$3");
//함수
re = "ASCII|AVG|CASE|CAST|CHARINDEX|COALESCE|CONVERT|COUNT|DAY|DATEADD|DATALENGTH|DATEPART|GETDATE|LEFT|LEN|LOWER|LTRIM|MONTH|NULLIF|OBJECT_ID|PATINDEX|REPLACE|REPLICATE|RTRIM|RIGHT|SPACE|SUBSTRING|SUM|TRIM|UPPER|USER_ID|YEAR"
re = eval("/([▒,<>=+\-\(])(" + re + ")([\(,])/gi");
source = source.replace(re, "$1<span id〓HL style〓color▦#ff00ff;>$2</span>$3");
//문자열속에 들어있는 테그제거
re=/'.*?'[nr]?/gi;
matchResults = source.match(re);
if(matchResults){
for (i=0; i<matchResults.length; i++){
matchTemp = matchResults[i].replace(/<[^b].*?>/gi, "");
source = source.replace(matchResults[i], matchTemp);
}
source = source.replace(/('.*?')/gi, "<span id〓HL style〓color▦#ff0000▩>$1</span>");
}
//주석제거용속에 들어있는 태그제거
re=/--.*?<br>/gi;
matchResults = source.match(re);
if(matchResults){
for (i=0; i<matchResults.length; i++){
matchTemp = matchResults[i].replace(/<[^b].*?>/gi, "");
source = source.replace(matchResults[i], matchTemp);
}
source = source.replace(/(--.*?<br>)/gi, "<span id〓HL style〓color▦#008080▩>$1</span>");
}
break;
case 5 : //Javascript Only
source = javascriptProcess(source);
}
//source = ReplaceTag2Text(source)
source = source.replace("/t/gi"," ");
source = source.replace("/ss/gi", " ");
//meta문자 바꾸기
source = source.replace(/▒/g, " ");
source = source.replace(/〓/g, "=");
source = source.replace(/▦/g, ":");
source = source.replace(/▩/g, ";");
source = source.replace(/♨/g, "-");
document.getElementById('sourcecode').innerHTML = source;
document.getElementById('isHighLighted').value = 1;
}
function javascriptProcess(str){
var matchTemp = str;
//예약어
re = "\{|\}|\]|\[|abstract|boolean|break|byte|case|catch|char|class▒|const|continue|debugger|default|delete|do[s{]|double|else|enum\(|export|extends|false|final|finally|float|for▒?\(|function[▒\(]|goto|if▒?\(|implements|import|sins|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";
re = eval("/(" + re + ")([<]?)/gi");
matchTemp = matchTemp.replace(re, "<span id〓HL style〓color▦#000080;font♨weight▦bold▩>$1</span>$2");
//Built-in objects
re = "anchors?|applets?|Area|▒Array|Button|Checkbox|Date|document|FileUpload|forms?|frames?|Hidden|history|▒image[(]|[.]images|links?|Area|location|Math|MimeType|mimeTypes|navigator|options|Password|plugins?|Radio|Reset|▒Select|▒String|Submit|[.]Text|Textarea|window";
re = eval("/(" + re + ")([<]?)/gi");
matchTemp = matchTemp.replace(re, "<span id〓HL style〓color▦#000080;font♨weight▦bold▩>$1</span>$2");
//IE,NS공통속성
//re = "Anchor|Button|Checkbox|Form|Hidden|Link|Password|Radio|Reset|Select|Submit|Text|Textarea|above|action|alinkColor|anchors|appCodeName|appName|appVersion|applets|availHeight|availWidth|background|below|bgColor|border|checked|clip|colorDepth|complete|cookie|defaultChecked|defaultSelected|defaultStatus|defaultValue|description|document|elements|enabledPlugin|encoding|fgColor|filename|form|forms|frames|gostname|hash|height|hidden|history|host|hostname|href|hspace|index|lastModified|left|length|linkColor|links|location|lowsrc|method|name|offscreenBuffering|options|pageX|pageY|parent|parentLayer|pathname|platform|port|protocol|referrer|search|selected|selectedIndex|self|siblingAbove|siblingBelow|src|suffixes|target|text|title|toolbar|top|type|userAgent|value|value |visibility|vlinkColor|vspace|width|window|zindex";
//re = eval("/(" + re + ")([<]?)/g");
//matchTemp = matchTemp.replace(re, "<span id〓HL style〓color▦#000080;font♨weight▦bold▩>$1</span>$2");
//기타
re = /((|)|+|-|=|%|||)/gi;
matchTemp = matchTemp.replace(re, "<span id〓HL style〓color▦#0000ff;font♨weight▦normal▩>$1</span>");
//문자열처리
matchTemp = commentProcess(matchTemp, "".*?"|\'.*?\'", "gi", "#0000ff", 0)
//한줄주석의 오류를 막기 위해서
re = /(w{3,4}:)///gi;
matchTemp = matchTemp.replace(re, "$1§§");
//한줄주석처리
matchTemp = commentProcess(matchTemp, "\/\/.*?<br>", "gi", "#008000", 0)
//한줄주석이 끝났으므로 원래대로 복귀
re = /(w{3,4}:)§§/gi;
matchTemp = matchTemp.replace(re, "$1//");
//여러줄 주석처리
matchTemp = commentProcess(matchTemp, "\/\*.*?\*\/", "gim", "#008000", 0)
return matchTemp;
}
/*****************************************
한줄, 여러줄 주석 및 문자열 처리부
******************************************/
function commentProcess(str, re, flag, color, bold){
var matchArray, matchTemp, i;
if(bold) bold = "font♨weight▦bold";
matchArray = str.match(eval("/" + re + "/" + flag));
if(matchArray){
for (i=0; i<matchArray.length; i++){
matchTemp = matchArray[i].replace(/<[^b].*?>/gi, "");
str = str.replace(matchArray[i], matchTemp);
}
str = str.replace(eval("/(" + re + ")/" + flag), "<span id〓HL style〓color▦" + color + "▩" + bold + ">$1</span>");
//source = source.replace(/('.*?')/gi, "<span id〓HL style〓color▦#ff0000▩>$1</span>");
}
return str;
}
/******************************************
특정문자 속에 들어있는 것들에서의 처리부
******************************************/
function specialProcess(str, gubunRe, re, flag, color, bold){
var matchArray, matchTemp, i;
if(bold) bold = "font♨weight▦bold";
matchArray = str.match(eval("/" + gubunRe + "/" + flag));
if(matchArray){
for (i=0; i<matchArray.length; i++){
matchTemp = matchArray[i].replace(/<[^b].*?>/gi, "");
matchTemp = matchTemp.replace(eval("/(" + re + ")/gi"), "<span id〓HL style〓color▦" + color + "▩" + bold + ">$1</span>");
str = str.replace(matchArray[i], matchTemp);
}
}
return str;
}
//Select All & Copy
function selectall(s){
var doc = document.body.createTextRange();
doc.moveToElementText(document.all(s));
doc.select();
doc.execCommand('copy');
alert('소스가 클립보드에 저장되었습니다.');
}
//-->
</script>
<a href="javascript:void(0);" onclick="selectall('sourcecode', '소스가')"><strong style="color:#82ae01;font-size:8pt;">select & copy all</strong></a>
<font style="color:#f7f7f7">|</font> <a href="javascript:void(0);" onclick="hightlightCode(0)"><strong style="color:#82ae01;font-size:8pt;"><span style="color:#f30">h</span><span style="color:#f90">i</span><span style="color:#fc0">g</span><span style="color:#690">h</span><span style="color:#060">l</span><span style="color:#3cf">i</span><span style="color:#06f">g</span><span style="color:#66f">h</span><span style="color:#309">t</span> code</strong></a>
<input type="hidden" id="isHighLighted" value="0">
<div id="sourcecode" style="width:95%;line-height:15px;word-wrap:break-word;word-break:break-all;height:210; border:1 solid #999999; background-image: url('../image/line.gif');color:#000000;text-align:left;font-size:9pt;"><script><br/>function togDis(el) {<br/>el.style.display = (el.currentStyle.display=='none') ? 'block' : 'none';<br/>}<br/></script><br/><br/><a href="javascript://" onClick="togDis(myTr);">toggle display</a><br/><br/><table id="kaka" style="display=none;"><br/><tr><td><INPUT TYPE=TEXT></td></tr><br/><tr id="myTr"><td><INPUT TYPE=TEXT></td></tr><br/><tr><td><INPUT TYPE=TEXT></td></tr><br/></table><br/><br/></div>
<script language=javascript src="../common/highlightCode.js"></script>
댓글목록
등록된 댓글이 없습니다.