code_junkie

Is there a lang-vb or lang-basic option for prettify.js from Google?

Nov 10th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. Partial Public Class WebForm1
  2. Inherits System.Web.UI.Page
  3.  
  4. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5. 'set page title
  6. Page.Title = "Something"
  7. End Sub
  8.  
  9. End Class
  10.  
  11. <pre class="prettyprint lang-html">
  12. The lang-* class specifies the language file extensions.
  13. Supported file extensions include
  14. "c", "cc", "cpp", "cs", "cyc", "java", "bsh", "csh", "sh",
  15. "cv", "py", "perl", "pl", "pm", "rb", "js",
  16. "html", "html", "xhtml", "xml", "xsl".
  17. </pre>
  18.  
  19. var highlightVB = function(code) {
  20. var regex = /("(?:""|[^"])+"c?)|('.*$)|#.+?#|(&[HO])?d+(.d*)?(e[+-]?d+)?U?([SILDFR%@!#]|&)?|.d+[FR!#]?|s+|w+|&|<|>|([-+*/\^$@!#%&<>()[]{}.,:=]+)/gi;
  21.  
  22. var lines = code.split("n");
  23. for (var i = 0; i < lines.length; i++) {
  24. var line = lines[i];
  25.  
  26. var tokens;
  27. var result = "";
  28.  
  29. while (tokens = regex.exec(line)) {
  30. var tok = getToken(tokens);
  31. switch (tok.charAt(0)) {
  32. case '"':
  33. if (tok.charAt(tok.length - 1) == "c")
  34. result += span("char", tok);
  35. else
  36. result += span("string", tok);
  37. break;
  38. case "'":
  39. result += span("comment", tok);
  40. break;
  41. case '#':
  42. result += span("date", tok);
  43. break;
  44. default:
  45. var c1 = tok.charAt(0);
  46.  
  47. if (isDigit(c1) ||
  48. tok.length > 1 && c1 == '.' && isDigit(tok.charAt(1)) ||
  49. tok.length > 5 && (tok.indexOf("&") == 0 &&
  50. tok.charAt(5) == 'H' || tok.charAt(5) == 'O')
  51. )
  52. result += span("number", tok);
  53. else if (isKeyword(tok))
  54. result += span("keyword", tok);
  55. else
  56. result += tok;
  57. break;
  58. }
  59. }
  60.  
  61. lines[i] = result;
  62. }
  63.  
  64. return lines.join("n");
  65. }
  66.  
  67. var keywords = [
  68. "addhandler", "addressof", "alias", "and", "andalso", "as", "boolean", "byref",
  69. "byte", "byval", "call", "case", "catch", "cbool", "cbyte", "cchar", "cdate",
  70. "cdec", "cdbl", "char", "cint", "class", "clng", "cobj", "const", "continue",
  71. "csbyte", "cshort", "csng", "cstr", "ctype", "cuint", "culng", "cushort", "date",
  72. "decimal", "declare", "default", "delegate", "dim", "directcast", "do", "double",
  73. "each", "else", "elseif", "end", "endif", "enum", "erase", "error", "event",
  74. "exit", "false", "finally", "for", "friend", "function", "get", "gettype",
  75. "getxmlnamespace", "global", "gosub", "goto", "handles", "if", "if",
  76. "implements", "imports", "in", "inherits", "integer", "interface", "is", "isnot",
  77. "let", "lib", "like", "long", "loop", "me", "mod", "module", "mustinherit",
  78. "mustoverride", "mybase", "myclass", "namespace", "narrowing", "new", "next",
  79. "not", "nothing", "notinheritable", "notoverridable", "object", "of", "on",
  80. "operator", "option", "optional", "or", "orelse", "overloads", "overridable",
  81. "overrides", "paramarray", "partial", "private", "property", "protected",
  82. "public", "raiseevent", "readonly", "redim", "rem", "removehandler", "resume",
  83. "return", "sbyte", "select", "set", "shadows", "shared", "short", "single",
  84. "static", "step", "stop", "string", "structure", "sub", "synclock", "then",
  85. "throw", "to", "true", "try", "trycast", "typeof", "variant", "wend", "uinteger",
  86. "ulong", "ushort", "using", "when", "while", "widening", "with", "withevents",
  87. "writeonly", "xor", "#const", "#else", "#elseif", "#end", "#if"
  88. ]
  89.  
  90. var isKeyword = function(token) {
  91. return keywords.indexOf(token.toLowerCase()) != -1;
  92. }
  93.  
  94. var isDigit = function(c) {
  95. return c >= '0' && c <= '9';
  96. }
  97.  
  98. var getToken = function(tokens) {
  99. for (var i = 0; i < tokens.length; i++)
  100. if (tokens[i] != undefined)
  101. return tokens[i];
  102. return null;
  103. }
  104.  
  105. var span = function(class, text) {
  106. return "<span class="" + class + "">" + text + "</span>";
  107. }
  108.  
  109. Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  110. 'set page title'
  111. Page.Title = "Something"
  112. Dim r As String = "Say ""Hello"""
  113. Dim i As Integer = 1234
  114. Dim d As Double = 1.23
  115. Dim s As Single = .123F
  116. Dim l As Long = 123L
  117. Dim ul As ULong = 123UL
  118. Dim c As Char = "x"c
  119. Dim h As Integer = &H0
  120. Dim t As Date = #5/31/1993 1:15:30 PM#
  121. Dim f As Single = 1.32e-5F
  122. End Sub
  123.  
  124. Sub TestMethod()
  125. 'Method body goes here'
  126. End Sub
  127.  
  128. Sub TestMethod2()
  129. 'Here''s another comment'
  130. End Sub
  131.  
  132. Sub TestMethod3()
  133. ''// one final comment
  134. End Sub
  135.  
  136. <script type="text/javascript" src="/External/css/prettify/prettify.js"></script>
  137. <script type="text/javascript" src="/External/css/prettify/lang-vb.js"></script>
  138.  
  139. <PRE class="prettyprint lang-vb">
  140. Function SomeVB() as string
  141. ' do stuff
  142. i = i + 1
  143. End Function
  144. </PRE>
Add Comment
Please, Sign In to add comment