生成语法高亮代码

网友投稿 647 2022-09-01

生成语法高亮代码

生成语法高亮代码

把下面代码保存为HightLightCode.asp:

生成语法高亮代码




<%Class Wyd_AspCodeHighLightPrivate RegExPublic Keyword,ObjectCommand,Strings,VBCodePublic KeyWordColor,ObjectCommandColor,StringsColor,Comment,CodeColor Private Sub Class_Initialize() Set RegEx = New RegExpRegEx.IgnoreCase = True ' 设置是否区分字母的大小写 True 不区分。 RegEx.Global = True ' 设置全程性质。 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" '关建字 请自己添加ObjectCommand="Left|Mid|Right|Int|Cint|Clng|String|Join|Array" '函数 请自己添加VBCode="" End Sub Private Sub Class_Terminate() Set RegEx = Nothing End Sub Private Function M_Replace(Str,Pattern,Color) RegEx.Pattern = Pattern ' 设置模式。 M_Replace=RegEx.Replace(Str,"$1") End Function Private Function String_Replace(Str,Pattern,Pattern1,Color,IsString) Dim Temp,RetStrRegEx.Pattern =Pattern1 Set Matches = RegEx.Execute(Str) For Each Match In Matches ' 遍历 Matches 集合 Temp=Re(Match.value) Str = Replace(Str,Match.value,Temp) NextRegEx.Pattern = Pattern ' 设置模式。If IsString=1 Then String_Replace=RegEx.Replace(Str,""$1"")Else String_Replace=RegEx.Replace(Str,"$1")End If End Function Private Function Re(Str) Dim TRegEx,Temp Set TRegEx = New RegExp TRegEx.IgnoreCase = True ' 设置是否区分字母的大小写。 TRegEx.Global = True ' 设置全程性质。 TRegEx.Pattern="<.*?>" Temp=TRegEx.Replace(Str,"") Temp=Replace(Temp,"<","") Temp=Replace(Temp,">","") Re=Temp Set TRegEx=Nothing End Function Public Function MakeLi() Dim TempIf VBCode="" Then MakeLi="" Exit FunctionEnd If VBCode=HTMLEncode(VBCode) Temp=M_Replace(VBCode,"/b("&Keyword&")/b",KeyWordColor) Temp=M_Replace(Temp,"/b("&ObjEctCommand&")/b",ObjectCommandColor) Temp=String_Replace(Temp,"""(.*?)""","""(.*)(<.+?>)("&KeyWord&ObjectCommand&")+(<.+?>)(.*)""",StringsColor,1)' 字符串 Temp=String_Replace(Temp,"(('|rem).*)","'(.*)(<.+?>)("&KeyWord&ObjectCommand&")+(<.+?>)(.*)",Comment,0) '注释 MakeLi=""&RepVbCrlf(Temp)&"" End Function Public Function RepVbCrlf(fString) RepVbCrlf = Replace(fString, CHR(10), "
") 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), "

") 'fString = Replace(fString, CHR(10), "
") HTMLEncode = fString End FunctionEnd Classstar=timer()Set TT = New Wyd_AspCodeHighLightIf Request("Content")<>"" Then TT.VBCode=Request("Content") Response.write TT.MakeLi() REsponse.write "
耗时:"&FormatNumber(timer()-star,2)*1000End If%>

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:php7新特性的理解和比较总结(PHP新特性)
下一篇:PHP简单实现单点登录功能示例(php单入口)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~