⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _codehighlight.js

📁 《JavaScript王者归来》examples.rar
💻 JS
📖 第 1 页 / 共 2 页
字号:
/**//**//**//**//**//**//**//*  
**    ==================================================================================================  
**    类名:CLASS_HIGHLIGHT  
**    功能:语法高亮  
**    示例:  
    ---------------------------------------------------------------------------------------------------  
  
            var xx        = new CLASS_HIGHLIGHT(code,syntax);            
            document.getElementById("display").innerHTML = xx.highlight(); 
  
    ---------------------------------------------------------------------------------------------------  
**    作者:ttyp  
**    邮件:ttyp@21cn.com  
**    日期:2005-7-31
**    其它说明:本类不是 Dron 原创,这里改成这种形式只是方便 DronFw 使用,感谢原作者 ttyp
**    ==================================================================================================  
**/  
DronFw.Class.CodeHighlight = function (code,syntax) 
{
    //哈希表类
    function Hashtable()
    {
        this._hash        = new Object();
        this.add        = function(key,value){
                            if(typeof(key)!="undefined"){
                                if(this.contains(key)==false){
                                    this._hash[key]=typeof(value)=="undefined"?null:value;
                                    return true;
                                } else {
                                    return false;
                                }
                            } else {
                                return false;
                            }
                        }
        this.remove        = function(key){delete this._hash[key];}
        this.count        = function(){var i=0;for(var k in this._hash){i++;} return i;}
        this.items        = function(key){return this._hash[key];}
        this.contains    = function(key){return typeof(this._hash[key])!="undefined";}
        this.clear        = function(){for(var k in this._hash){delete this._hash[k];}}
    }
    //字符串转换为哈希表
    this.str2hashtable = function(key,cs){
        
        var _key    = key.split(/,/g);
        var _hash    = new Hashtable();
        var _cs        = true;
        if(typeof(cs)=="undefined"){
            _cs = this._caseSensitive;
        } else {
            _cs = cs;
        }
        for(var i in _key){
            if(_cs){
                _hash.add(_key[i]);
            } else {
                _hash.add((_key[i]+"").toLowerCase());
            }
        }
        return _hash;
    }
    //获得需要转换的代码
    this._codetxt        = code;
    if(typeof(syntax)=="undefined"){
        syntax = "";
    }

    switch(syntax.toLowerCase())
    {
        case "sql":
            //是否大小写敏感
            this._caseSensitive    = false;
            //得到关键字哈希表
            this._keywords        = this.str2hashtable("COMMIT,DELETE,INSERT,LOCK,ROLLBACK,SELECT,TRANSACTION,READ,ONLY,WRITE,USE,ROLLBACK,SEGMENT,ROLE,EXCEPT,NONE,UPDATE,DUAL,WORK,COMMENT,FORCE,FROM,WHERE,INTO,VALUES,ROW,SHARE,MODE,EXCLUSIVE,UPDATE,ROW,NOWAIT,TO,SAVEPOINT,UNION,UNION,ALL,INTERSECT,MINUS,START,WITH,CONNECT,BY,GROUP,HAVING,ORDER,UPDATE,NOWAIT,IDENTIFIED,SET,DROP,PACKAGE,CREATE,REPLACE,PROCEDURE,FUNCTION,TABLE,RETURN,AS,BEGIN,DECLARE,END,IF,THEN,ELSIF,ELSE,WHILE,CURSOR,EXCEPTION,WHEN,OTHERS,NO_DATA_FOUND,TOO_MANY_ROWS,CURSOR_ALREADY_OPENED,FOR,LOOP,IN,OUT,TYPE,OF,INDEX,BINARY_INTEGER,RAISE,ROWTYPE,VARCHAR2,NUMBER,LONG,DATE,RAW,LONG RAW,CHAR,INTEGER,MLSLABEL,CURRENT,OF,DEFAULT,CURRVAL,NEXTVAL,LEVEL,ROWID,ROWNUM,DISTINCT,ALL,LIKE,IS,NOT,NULL,BETWEEN,ANY,AND,OR,EXISTS,ASC,DESC,ABS,CEIL,COS,COSH,EXP,FLOOR,LN,LOG,MOD,POWER,ROUND,SIGN,SIN,SINH,SQRT,TAN,TANH,TRUNC,CHR,CONCAT,INITCAP,LOWER,LPAD,LTRIM,NLS_INITCAP,NLS_LOWER,NLS_UPPER,REPLACE,RPAD,RTRIM,SOUNDEX,SUBSTR,SUBSTRB,TRANSLATE,UPPER,ASCII,INSTR,INSTRB,LENGTH,LENGTHB,NLSSORT,ADD_MONTHS,LAST_DAY,MONTHS_BETWEEN,NEW_TIME,NEXT_DAY,ROUND,SYSDATE,TRUNC,CHARTOROWID,CONVERT,HEXTORAW,RAWTOHEX,ROWIDTOCHAR,TO_CHAR,TO_DATE,TO_LABEL,TO_MULTI_BYTE,TO_NUMBER,TO_SINGLE_BYTE,DUMP,GREATEST,GREATEST_LB,LEAST,LEAST_UB,NVL,UID,USER,USERENV,VSIZE,AVG,COUNT,GLB,LUB,MAX,MIN,STDDEV,SUM,VARIANCE");
            //得到内建对象哈希表
            this._commonObjects = this.str2hashtable("");
            //标记
            this._tags            = this.str2hashtable("",false);
            //得到分割字符
            this._wordDelimiters= "  ,.?!;:\\/<>(){}[]\"'\r\n\t=+-|*%@#$^&";
            //引用字符
            this._quotation        = this.str2hashtable("'");
            //行注释字符
            this._lineComment    = "--";
            //转义字符
            this._escape        = "";
            //多行引用开始
            this._commentOn        = "/**//**//**//**//**//**//**//*";
            //多行引用结束
            this._commentOff    = "*/";
            //忽略词
            this._ignore        = "";    
            //是否处理标记
            this._dealTag        = false;
            break;
        case "c#":
            //是否大小写敏感
            this._caseSensitive    = true;
            //得到关键字哈希表
            this._keywords        = this.str2hashtable("abstract,as,base,bool,break,byte,case,catch,char,checked,class,const,continue,decimal,default,delegate,do,double,else,enum,event,explicit,extern,false,finally,fixed,float,for,foreach,get,goto,if,implicit,in,int,interface,internal,is,lock,long,namespace,new,null,object,operator,out,override,params,private,protected,public,readonly,ref,return,sbyte,sealed,short,sizeof,stackalloc,static,set,string,struct,switch,this,throw,true,try,typeof,uint,ulong,unchecked,unsafe,ushort,using,value,virtual,void,volatile,while");
            //得到内建对象哈希表
            this._commonObjects = this.str2hashtable("String,Boolean,DateTime,Int32,Int64,Exception,DataTable,DataReader");
            //标记
            this._tags            = this.str2hashtable("",false);
            //得到分割字符
            this._wordDelimiters= "  ,.?!;:\\/<>(){}[]\"'\r\n\t=+-|*%@#$^&";
            //引用字符
            this._quotation        = this.str2hashtable("\"");
            //行注释字符
            this._lineComment    = "//";
            //转义字符
            this._escape        = "\\";
            //多行引用开始
            this._commentOn        = "/*";
            //多行引用结束
            this._commentOff    = "*/";
            //忽略词
            this._ignore        = "";                
            //是否处理标记
            this._dealTag        = false;
            break;    
        case "java":
            //是否大小写敏感
            this._caseSensitive    = true;
            //得到关键字哈希表
            this._keywords        = this.str2hashtable("abstract,boolean,break,byte,case,catch,char,class,const,continue,default,do,double,else,extends,final,finally,float,for,goto,if,implements,import,instanceof,int,interface,long,native,new,package,private,protected,public,return,short,static,strictfp,super,switch,synchronized,this,throw,throws,transient,try,void,volatile,while");
            //得到内建对象哈希表
            this._commonObjects = this.str2hashtable("String,Boolean,DateTime,Int32,Int64,Exception,DataTable,DataReader");
            //标记
            this._tags            = this.str2hashtable("",false);
            //得到分割字符
            this._wordDelimiters= "  ,.?!;:\\/<>(){}[]\"'\r\n\t=+-|*%@#$^&";
            //引用字符
            this._quotation        = this.str2hashtable("\"");
            //行注释字符
            this._lineComment    = "//";
            //转义字符
            this._escape        = "\\";
            //多行引用开始
            this._commentOn        = "/*";
            //多行引用结束
            this._commentOff    = "*/";
            //忽略词
            this._ignore        = "";        
            //是否处理标记
            this._dealTag        = false;            
            break;    
        case "vbs":
        case "vb":
            //是否大小写敏感
            this._caseSensitive    = false;
            //得到关键字哈希表
            this._keywords        = this.str2hashtable("And,ByRef,ByVal,Call,Case,Class,Const,Dim,Do,Each,Else,ElseIf,Empty,End,Eqv,Erase,Error,Exit,Explicit,False,For,Function,Get,If,Imp,In,Is,Let,Loop,Mod,Next,Not,Nothing,Null,On,Option,Or,Private,Property,Public,Randomize,ReDim,Resume,Select,Set,Step,Sub,Then,To,True,Until,Wend,While,Xor,Anchor,Array,Asc,Atn,CBool,CByte,CCur,CDate,CDbl,Chr,CInt,CLng,Cos,CreateObject,CSng,CStr,Date,DateAdd,DateDiff,DatePart,DateSerial,DateValue,Day,Dictionary,Document,Element,Err,Exp,FileSystemObject,Filter,Fix,Int,Form,FormatCurrency,FormatDateTime,FormatNumber,FormatPercent,GetObject,Hex,Hour,InputBox,InStr,InstrRev,IsArray,IsDate,IsEmpty,IsNull,IsNumeric,IsObject,Join,LBound,LCase,Left,Len,Link,LoadPicture,Location,Log,LTrim,RTrim,Trim,Mid,Minute,Month,MonthName,MsgBox,Navigator,Now,Oct,Replace,Right,Rnd,Round,ScriptEngine,ScriptEngineBuildVersion,ScriptEngineMajorVersion,ScriptEngineMinorVersion,Second,Sgn,Sin,Space,Split,Sqr,StrComp,String,StrReverse,Tan,Time,TextStream,TimeSerial,TimeValue,TypeName,UBound,UCase,VarType,Weekday,WeekDayName,Year");
            //得到内建对象哈希表
            this._commonObjects = this.str2hashtable("String,Number,Boolean,Date,Integert,Long,Double,Single");
            //标记
            this._tags            = this.str2hashtable("",false);
            //得到分割字符
            this._wordDelimiters= "  ,.?!;:\\/<>(){}[]\"'\r\n\t=+-|*%@#$^&";
            //引用字符
            this._quotation        = this.str2hashtable("\"");
            //行注释字符
            this._lineComment    = "'";
            //转义字符
            this._escape        = "";
            //多行引用开始
            this._commentOn        = "";
            //多行引用结束
            this._commentOff    = "";
            //忽略词
            this._ignore        = "<!--";    
            //是否处理标记
            this._dealTag        = false;
            break;
        case "js":
            //是否大小写敏感
            this._caseSensitive    = true;
            //得到关键字哈希表
            this._keywords        = this.str2hashtable("function,void,this,boolean,while,if,return,new,true,false,try,catch,throw,null,else,int,long,do,var");
            //得到内建对象哈希表
            this._commonObjects = this.str2hashtable("String,Number,Boolean,RegExp,Error,Math,Date");
            //标记
            this._tags            = this.str2hashtable("",false);
            //得到分割字符
            this._wordDelimiters= "  ,.?!;:\\/<>(){}[]\"'\r\n\t=+-|*%@#$^&";
            //引用字符
            this._quotation        = this.str2hashtable("\",'");
            //行注释字符
            this._lineComment    = "//";
            //转义字符
            this._escape        = "\\";
            //多行引用开始
            this._commentOn        = "/*";
            //多行引用结束
            this._commentOff    = "*/";
            //忽略词
            this._ignore        = "<!--";
            break;
        case "html":
            //是否大小写敏感
            this._caseSensitive    = true;
            //得到关键字哈希表
            this._keywords        = this.str2hashtable("function,void,this,boolean,while,if,return,new,true,false,try,catch,throw,null,else,int,long,do,var");
            //得到内建对象哈希表
            this._commonObjects = this.str2hashtable("String,Number,Boolean,RegExp,Error,Math,Date");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -