Support ASP for use in Rainbow.js | Michele Pisani

Support for Classic ASP language for use in library Rainbow.js to highlight the code syntax

by Michele Pisani

HTML

<script src="http://media.bigbossweb.com/corporates/chdlr48tnm8thg95tgh9e4mjgngthemb/website/michelepisani/www.michelepisani.it/jscript/rainbow.min.js"></script>
<p class="container">
<i>GitHub: https://github.com/ccampbell/rainbow</i><br />
<b>Rainbow: support for ASP language</b><br />
@author Michele Pisani - www.michelepisani.it<br />
@version 1.0.0
<pre data-language="asp">
<code>&lt;!--&num;include file="test.asp"--&gt;
&lt;!--&num;include virtual="/test2.asp"--&gt;

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
&lt;%

function changeTextFunc(a, b, c, mystring)
  d = b + c
  if cint(a) = cint(d) then
      mystring=replace(mystring,"ASP","Classic ASP")
  end if
    changeTextFunc = mystring
end function
    
dim mystring = ""
dim position = 0
mystring_empty = true
mystring = "Support ASP for use in Rainbow.js"

if len(trim(mystring)) = 0 then mystring_empty = false

mystring = changeTextFunc(5, 2, 3, mystring)

position = instr(mystring,"ASP")
    
select case cint(position)
  case 0
    'operations
    response.Write "The word searched is not in the string"
  case else
    'other operations
    response.Write "Great! The word searched is in the string"
end select

dim string_names = ""
sql="select id, name from my_table;" 'query example
set rs=connection.execute(sql)
if not rs.eof then
    Do while not rs.eof
        string_names = string_names & rs("name") & ","
    rs.movenext
    Loop
    string_names = left(string_names,len(string_names)-1)
end if
rs.close
set rs = nothing
%&gt;

<!-- Eventual HTML code before and after ASP code -->
    
&lt;%
strTest = ""
For i = 1 To Request.Form.Count
    strTest = strTest &amp; Request.Form.Key(i) &amp; ": " &amp; Request.Form.Item(i) & "<br />"
Next
    
'other examples
session.Timeout = 30
session.Abandon
response.Write request.Form
response.redirect "http://www.michelepisani.it"

'...and more (cicle for, do while, on error resume next, ...)
%&gt;
        </code>
    </pre>
</p>

CSS

pre {background: #F9F9F9;word-wrap: break-word;margin: 0px;padding: 0px;padding: 10px;color: #525252;font-size: 14px;margin-bottom: 20px;border: solid 1px #C6CACD;overflow-x:scroll;}
pre, code {font-family: 'Monaco', courier, monospace;}
pre .variable.language.asp-tag {color: #525252;background-color: #FFFF00}
pre .comment {color: #57ac57;}
pre .constant.language {color: #0000ff;}
pre .string {color: #960000;}
pre .variable.language.asp-include {color: #57ac57;}
pre .support.function {color: #0092db;}
pre .support.function.suggested {color: #0000ff;}
pre .keyword {color: #0000ff;}
pre .keyword.dot {color: #525252;}
pre .keyword.operator {color: #ff3400;}

/* Only for head of result */
p.container {background: #F9F9F9;word-wrap: break-word;margin: 0px;padding: 0px;padding: 10px;color: #525252;font-size: 14px;margin-bottom: 20px;border: solid 1px #C6CACD;font-family: 'Monaco', courier, monospace;}

JavaScript

/**
 * Classic ASP patterns
 *
 * @author Michele Pisani - www.michelepisani.it
 * @version 1.0.0
 */
Rainbow.extend('asp', [
    {
      'name': 'constant.language',
      'pattern': /true|false|null/ig
    },
    {
      'name': 'keyword.dot',
      'pattern': /\./g
    },
    {
      'name': 'keyword',
      'pattern': /\b(dim|function|end|select|case|for|next|loop|do|while|wend|to|until|exit|then|not|if|else|elseif|option|explicit|on|error|resume|codepage|language|sub|call|set|class|private|public|nothing|let|get|new|const|property|execute?)(?=\(|\b)/ig
    },
    {
      'name': 'support.function',
      'pattern': /\b(ubound|replace|len|left|right|asc|chr|instr|lcase|ltrim|rtrim|space|split|strcomp|string|strreverse|trim|ucase|mid|instrrev|cint|cdbl|clng)(?=\(|\b)/ig
    },
    {
      'name': 'support.function.suggested',
      'pattern': /\b(.binaryread|.clientcertificate|.cookies|.form|.item|.querystring|.servervariables|.totalbytes|.abandon|.codepage|.contents|.lcid|.sessionid|.staticobjects|.timeout|.value|.count|.key|.addheader|.appendtolog|.binarywrite|.buffer|.cachecontrol|.charset|.clear|.contenttype|.end|.expires|.expiresabsolute|.flush|.isclientconnected|.pics|.redirect|.status|.write)(?=\(|\b)/ig
    },
    {
      //pattern for classic ASP tags
      'name': 'variable.language.asp-tag',
      'pattern': /(&lt;\%|\%&gt;)/g
    },
    {
      //pattern for classic ASP comments
      'name': 'comment',
      'pattern': /([']).*/g
    },
    {
      //pattern for classic ASP string (find all string between each group of double quotes)
      'name': 'string',
      'pattern': /\".*?\"/g
    },
    {
      //pattern for INCLUDE (file or virtual) and for HTML comment
      'name': 'variable.language.asp-include',
      'pattern': /(&lt;!--).*(--&gt;)/g
    },
    {
      'name': 'keyword.operator',
      'pattern': /\+|\!|\-|&amp;|\||\*|\=/g
    }
]);