Skip to content

Commit c673ec2

Browse files
authored
Add support for Visual Basic. Fix #985 (#1382)
1 parent 5a524f7 commit c673ec2

15 files changed

+581
-3
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@
675675
"title": "vim",
676676
"owner": "westonganger"
677677
},
678+
"visual-basic": {
679+
"title": "Visual Basic",
680+
"owner": "Golmote",
681+
"alias": "vb"
682+
},
678683
"wiki": {
679684
"title": "Wiki markup",
680685
"require": "markup",

components/prism-visual-basic.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Prism.languages['visual-basic'] = {
2+
'comment': {
3+
pattern: /(?:[']|REM\b).*/i,
4+
inside: {
5+
'keyword': /^REM/i
6+
}
7+
},
8+
'directive': {
9+
pattern: /#(?:Const|Else|ElseIf|End|ExternalChecksum|ExternalSource|If|Region)(?:[^\S\r\n]_[^\S\r\n]*(?:\r\n?|\n)|.)+/i,
10+
alias: 'comment',
11+
greedy: true
12+
},
13+
'string': {
14+
pattern: /["](?:["]{2}|[^"])*["]C?/i,
15+
greedy: true
16+
},
17+
'date': {
18+
pattern: /#[^\S\r\n]*(?:\d+([/-])\d+\1\d+(?:[^\S\r\n]+(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))?|(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))[^\S\r\n]*#/i,
19+
alias: 'builtin'
20+
},
21+
'number': /(?:(?:\b\d+(?:\.\d+)?|\.\d+)(?:E[+-]?\d+)?|&[HO][\dA-F]+)(?:U?[ILS]|[FRD])?/i,
22+
'boolean': /\b(?:True|False|Nothing)\b/i,
23+
'keyword': /\b(?:AddHandler|AddressOf|Alias|And(?:Also)?|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|C(?:Bool|Byte|Char|Date|Dbl|Dec|Int|Lng|Obj|SByte|Short|Sng|Str|Type|UInt|ULng|UShort)|Char|Class|Const|Continue|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else(?:If)?|End(?:If)?|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get(?:Type|XMLNamespace)?|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|Must(?:Inherit|Override)|My(?:Base|Class)|Namespace|Narrowing|New|Next|Not(?:Inheritable|Overridable)?|Object|Of|On|Operator|Option(?:al)?|Or(?:Else)?|Out|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TryCast|TypeOf|U(?:Integer|Long|Short)|Using|Variant|Wend|When|While|Widening|With(?:Events)?|WriteOnly|Xor)\b/i,
24+
'operator': [
25+
/[+\-*/\\^<=>&#@$%!]/,
26+
{
27+
pattern: /([^\S\r\n])_(?=[^\S\r\n]*[\r\n])/,
28+
lookbehind: true
29+
}
30+
],
31+
'punctuation': /[{}().,:?]/
32+
};
33+
34+
Prism.languages.vb = Prism.languages['visual-basic'];

components/prism-visual-basic.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-visual-basic.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<h2>Comments</h2>
2+
<pre><code>' Comment
3+
REM This is a comment too</code></pre>
4+
5+
<h2>Strings and characters</h2>
6+
<pre><code>"Foo""bar"
7+
“”
8+
"a"c</code></pre>
9+
10+
<h2>Dates and times</h2>
11+
<pre><code># 8/23/1970 3:45:39AM #
12+
#8/23/1970 #
13+
# 3:45:39AM #
14+
# 3:45:39#
15+
# 13:45:39 #
16+
# 1AM #
17+
# 13:45:39PM #</code></pre>
18+
19+
<h2>Numbers</h2>
20+
<pre><code>42S
21+
.369E+14
22+
3.1415R</code></pre>
23+
24+
<h2>Preprocessing directives</h2>
25+
<pre><code>#ExternalChecksum("c:\wwwroot\inetpub\test.aspx", _
26+
"{12345678-1234-1234-1234-123456789abc}", _
27+
"1a2b3c4e5f617239a49b9a9c0391849d34950f923fab9484")</code></pre>
28+
29+
<h2>Keywords</h2>
30+
<pre><code>Function AddNumbers(ByVal X As Integer, ByVal Y As Integer)
31+
AddNumbers = X + Y
32+
End Function
33+
Module Test
34+
Sub Main()
35+
End Sub
36+
End Module</code></pre>

plugins/show-language/prism-show-language.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
1111
}
1212

1313
// The languages map is built automatically with gulp
14-
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
14+
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
1515
Prism.plugins.toolbar.registerButton('show-language', function(env) {
1616
var pre = env.element.parentNode;
1717
if (!pre || !/pre/i.test(pre.nodeName)) {

plugins/show-language/prism-show-language.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
True
2+
False
3+
Nothing
4+
5+
----------------------------------------------------
6+
7+
[
8+
["boolean", "True"],
9+
["boolean", "False"],
10+
["boolean", "Nothing"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for booleans.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'
2+
' Foo "bar"
3+
4+
‘ Foobar
5+
6+
’ Foobar
7+
REM
8+
REM Foobar
9+
10+
----------------------------------------------------
11+
12+
[
13+
["comment", ["'"]],
14+
["comment", ["' Foo \"bar\""]],
15+
["comment", ["‘"]],
16+
["comment", ["‘ Foobar"]],
17+
["comment", ["’"]],
18+
["comment", ["’ Foobar"]],
19+
["comment", [["keyword", "REM"]]],
20+
["comment", [["keyword", "REM"], " Foobar"]]
21+
]
22+
23+
----------------------------------------------------
24+
25+
Checks for comments.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 8/23/1970 3:45:39AM #
2+
#8/23/1970 #
3+
# 3:45:39AM #
4+
# 3:45:39#
5+
# 13:45:39 #
6+
# 1AM #
7+
# 13:45:39PM #
8+
9+
----------------------------------------------------
10+
11+
[
12+
["date", "# 8/23/1970 3:45:39AM #"],
13+
["date", "#8/23/1970 #"],
14+
["date", "# 3:45:39AM #"],
15+
["date", "# 3:45:39#"],
16+
["date", "# 13:45:39 #"],
17+
["date", "# 1AM #"],
18+
["date", "# 13:45:39PM #"]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks for dates and times.

0 commit comments

Comments
 (0)