此類高亮根據(jù)Editplus高亮來(lái)做的
復(fù)制代碼 代碼如下:
Class Wyd_AspCodeHighLight
Private RegEx
Public Keyword,ObjectCommand,Strings,VBCode
Public KeyWordColor,ObjectCommandColor,StringsColor,Comment,CodeColor
Private Sub Class_Initialize()
Set RegEx = New RegExp
RegEx.IgnoreCase = True ' 設(shè)置是否區(qū)分字母的大小寫(xiě) True 不區(qū)分。
RegEx.Global = True ' 設(shè)置全程性質(zhì)。
KeyWordColor="#0000FF"
ObjectCommandColor="#FF0000"
StringsColor="#FF00FF"
Comment="#008000"
CodeColor="#993300"
Keyword="Set|Private|If|Then|Sub|End|Function|For|Next|Do|While|Wend|True|False|Nothing|Class" '關(guān)建字 請(qǐng)自己添加
ObjectCommand="Left|Mid|Right|Int|Cint|Clng|String|Join|Array" '函數(shù) 請(qǐng)自己添加
VBCode=""
End Sub
Private Sub Class_Terminate()
Set RegEx = Nothing
End Sub
Private Function M_Replace(Str,Pattern,Color)
RegEx.Pattern = Pattern ' 設(shè)置模式。
M_Replace=RegEx.Replace(Str,"font color="Color">$1/font>")
End Function
Private Function String_Replace(Str,Pattern,Pattern1,Color,IsString)
Dim Temp,RetStr
RegEx.Pattern =Pattern1
Set Matches = RegEx.Execute(Str)
For Each Match In Matches ' 遍歷 Matches 集合
Temp=Re(Match.value)
Str = Replace(Str,Match.value,Temp)
Next
RegEx.Pattern = Pattern ' 設(shè)置模式。
If IsString=1 Then
String_Replace=RegEx.Replace(Str,"font color="Color">"$1"/font>")
Else
String_Replace=RegEx.Replace(Str,"font color="Color">$1/font>")
End If
End Function
Private Function Re(Str)
Dim TRegEx,Temp
Set TRegEx = New RegExp
TRegEx.IgnoreCase = True ' 設(shè)置是否區(qū)分字母的大小寫(xiě)。
TRegEx.Global = True ' 設(shè)置全程性質(zhì)。
TRegEx.Pattern=".*?>"
Temp=TRegEx.Replace(Str,"")
Temp=Replace(Temp,"","")
Temp=Replace(Temp,">","")
Re=Temp
Set TRegEx=Nothing
End Function
Public Function MakeLi()
Dim Temp
If VBCode="" Then
MakeLi=""
Exit Function
End If
VBCode=HTMLEncode(VBCode)
Temp=M_Replace(VBCode,"\b("Keyword")\b",KeyWordColor)
Temp=M_Replace(Temp,"\b("ObjEctCommand")\b",ObjectCommandColor)
Temp=String_Replace(Temp,"""(.*?)""","""(.*)(.+?>)("KeyWordObjectCommand")+(.+?>)(.*)""",StringsColor,1)' 字符串
Temp=String_Replace(Temp,"(('|rem).*)","'(.*)(.+?>)("KeyWordObjectCommand")+(.+?>)(.*)",Comment,0) '注釋
MakeLi="FONT COLOR="CodeColor">"RepVbCrlf(Temp)"/FONT>"
End Function
Public Function RepVbCrlf(fString)
RepVbCrlf = Replace(fString, CHR(10), "BR> ")
End Function
Public Function HTMLEncode(fString)
If IsNull(fString) or fString="" Then
HTMLEncode=""
Exit Function
End If
fString = replace(fString, ">", ">")
fString = replace(fString, "", "")
'fString = Replace(fString, CHR(32), " ")
'fString = Replace(fString, CHR(9), " ")
'fString = Replace(fString, CHR(34), """)
'fString = Replace(fString, CHR(39), "'")
'fString = Replace(fString, CHR(13), "")
'fString = Replace(fString, CHR(10) CHR(10), "/P>P> ")
'fString = Replace(fString, CHR(10), "BR> ")
HTMLEncode = fString
End Function
End Class
例子
復(fù)制代碼 代碼如下:
star=timer()
Set TT = New Wyd_AspCodeHighLight
If Request("xx")>"" Then
TT.VBCode=Request("xx")
Response.write TT.MakeLi()
REsponse.write "br>"FormatNumber(timer()-star,2)*1000
Else
%>
FORM METHOD=POST action="Index2.asp">
TEXTAREA NAME="xx" ROWS="30" COLS="80">Class Lih
Private RegEx
Public Keyword,ObjectCommand,Strings,VBCode
Public KeyWordColor,ObjectCommandColor,StringsColor,Comment
Private Sub Class_Initialize()
Set RegEx = New RegExp
KeyWordColor="#0000FF"
ObjectCommandColor="#FF0000"
StringsColor="#FF00FF"
Comment="#008000"
Keyword="If|End|For|Next|Function|Then|Do|While|Wend|Class"
VBCode=""
End Sub
Private Sub Class_Terminate()
Set RegEx = Nothing
End Sub
Private Function M_Replace(Str,Pattern,Color)
RegEx.IgnoreCase = False ' 設(shè)置是否區(qū)分字母的大小寫(xiě)。
RegEx.Global = True ' 設(shè)置全程性質(zhì)。
RegEx.Pattern = Pattern ' 設(shè)置模式。/TEXTAREA>
INPUT TYPE="submit" value=fff>
/FORM>
%End If%>
您可能感興趣的文章:- JavaScript版代碼高亮
- 用js查找法實(shí)現(xiàn)當(dāng)前欄目的高亮顯示的代碼
- js兼容IE6,IE7菜單高亮顯示效果代碼
- javascript網(wǎng)頁(yè)關(guān)鍵字高亮代碼
- fckeditor 代碼語(yǔ)法高亮
- Javascript實(shí)現(xiàn)的CSS代碼高亮顯示
- tinyMCE插件開(kāi)發(fā)之插入html,php,sql,js代碼 并代碼高亮顯示
- 兩種簡(jiǎn)單實(shí)現(xiàn)菜單高亮顯示的JS類代碼
- javascript 關(guān)鍵字高亮顯示實(shí)現(xiàn)代碼
- 高亮顯示web頁(yè)表格行的javascript代碼
- 高效的表格行背景隔行變色及選定高亮的JS代碼
- jQuery語(yǔ)法高亮插件支持各種程序源代碼語(yǔ)法著色加亮
- 分享15個(gè)美化代碼的代碼語(yǔ)法高亮工具
- 用JS將搜索的關(guān)鍵字高亮顯示實(shí)現(xiàn)代碼
- 如何實(shí)現(xiàn)正則表達(dá)式的JavaScript的代碼高亮
- 2014最熱門(mén)的JavaScript代碼高亮插件推薦
- 2016年最熱門(mén)的15 款代碼語(yǔ)法高亮工具,美化你的代碼