How to display source in HTML

Below are the set of function used to do a HTML color display of source code. It uses regular expressions to parse the source and cascading style sheets (css) to render the formatting. If you view the source of this page and look for the HTML in between the <pre> tags, you will see how the page is rendered.

Now for the source code to do this.

<% if Request.QueryString("file") <> "" then dim css css = "http://www.jdmx.com/css/src.css" Response.Write "<link rel=""stylesheet"" href=""" & css & """ />" WriteASP(Request.QueryString("file")) end if function ReadFile(sfile) dim fobj dim file dim s set fobj = Server.CreateObject("Scripting.FileSystemObject") if fobj.FileExists(sfile) then set file = fobj.OpenTextFile(sfile, 1) if not file.AtEndOfStream then s = file.readall end if file.Close end if set fobj = nothing ReadFile = s end function function ReplaceChar(byval sText, byval sFind, byval sReplace) dim oQre set oQre = new regexp oQre.Pattern = sFind oQre.Global = true sText = oQre.Replace(sText, sReplace) set oQre = nothing ReplaceChar = sText end function function KeyWordASP() dim s s = "('.*[^\r\n])~<asp class=""comment"">$1</asp>," _ & "if|then|else|end|for|to|next|while|loop|with|" _ & "function|sub|dim|select|case|const|set" KeyWordASP = Split(s, ",") end function function KeyWordDelphi() dim s '& "(<delphi[^>]*>[\w\W]*</delphi>)|('[^\r\n]*')" _ '& "~$1<delphi class=""text"">$2</delphi>," _ s = "(//.*[^\r\n])~<delphi class=""comment"">$1</delphi>," _ & "({[^}]*}.)~<delphi class=""comment"">$1</delphi>," _ & "(<delphi[^>]*>[^<>]*</delphi>)|('[^\r\n']*')" _ & "~<delphi class=""text"">$1</delphi>," _ & "begin|end|result|var|uses|if|then|else|do|" _ & "for|to|next|while|with|function|procedure|" _ & "select|case|const|program|try|catch|" _ & "finally|and|or|not" KeyWordDelphi = Split(s, ",") end function function KeyWordJavascript() dim s s = "if|then|else|{|}|for|while|loop|with|" _ & "function|var|switch|case|const" KeyWordJavascript = Split(s, ",") end function function KeyWordVB() dim s s = "('.*[^\r\n])~<asp class=""comment"">$1</asp>," _ & "if,then,else,end,for,to,next,while,wend,loop,with," _ & "function,sub,dim,select,case,const,set" KeyWordVB = Split(s, ",") end function function ReadASP(sfile) ReadASP = ReadSrc(sfile, "ASP") end function function ReadDelphi(sfile) ReadDelphi = ReadSrc(sfile, "DELPHI") end function function ReadJavaScript(sfile) ReadDelphi = ReadSrc(sfile, "JAVASCRIPT") end function function ReadVB(sfile) ReadVB = ReadSrc(sfile, "VB") end function sub WriteASP(sfile) WriteSrc ReadSrc(sfile, "ASP") end sub sub WriteDelphi(sfile) WriteSrc ReadSrc(sfile, "DELPHI") end sub sub WriteJavascript(sfile) WriteSrc ReadSrc(sfile, "JAVASCRIPT") end sub sub WriteVB(sfile) WriteSrc ReadSrc(sfile, "VB") end sub function ReadSrc(sfile, stype) dim s dim kw dim i s = ReadFile(sfile) select case uCase(stype) case "ASP" : kw = KeyWordASP case "VB" : kw = KeyWordVB case "DELPHI" : kw = KeyWordDelphi case "JAVASCRIPT" : kw = KeyWordJavascript case else : kw = ASPKeyWord end select stype = lCase(stype) if s <> "" then s = ReplaceChar(s, "<", "<") s = ReplaceChar(s, ">", ">") for i = 0 to uBound(kw) dim x dim sfind dim srep x = Split(kw(i), "~") if uBound(x) = 0 then sfind = "(<" & stype & "[^>]*>[^<>]*</" & stype & ">)|\b(" & kw(i) & ")\b" srep = "$1<" & stype & " class=""$2"">$2</" & stype & ">" else sfind = "(" & x(0) & ")" srep = x(1) end if s = ReplaceChar(s, sfind, srep) next s = ReplaceChar(s, "<" & stype & "[^>]*></" & stype & ">", "") end if ReadSrc = s end function sub WriteSrc(s) response.Write "<pre><div id=""src"">" & s & "</div></pre>" end sub %>

Note: The third parameter in the function ReplaceChar is suppose to be &#060; but shows up as < in this layout (the same goes for &#062). This is just the result of displaying the exact source that I am using to create this.

Testimonals
I can't envision an easier program to use to record trades.
ProductsMore ...
Electronic Trade Journal
Risk/Reward Calculator
Stock Calculator
Subscription Manager
ArticlesAll
Programming Guidelines
Regular Expressions
Display Source in HTML
HTML-Safe Color Table
Quotes in a HTML TextBox
Convert Windows File to Unix
Shortcuts in the SendTo Menu
Backup and Scan Hard Drive