Skip to content

Commit c28d8c5

Browse files
authored
Add support for WebAssembly. Fix #1140 and fix #1384 (#1386)
1 parent 6e0b20a commit c28d8c5

12 files changed

+611
-3
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@
684684
"owner": "Golmote",
685685
"alias": "vb"
686686
},
687+
"wasm": {
688+
"title": "WebAssembly",
689+
"owner": "Golmote"
690+
},
687691
"wiki": {
688692
"title": "Wiki markup",
689693
"require": "markup",

components/prism-wasm.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Prism.languages.wasm = {
2+
'comment': [
3+
/\(;[\s\S]*?;\)/,
4+
{
5+
pattern: /;;.*/,
6+
greedy: true
7+
}
8+
],
9+
'string': {
10+
pattern: /"(?:\\[\s\S]|[^"\\])*"/,
11+
greedy: true
12+
},
13+
'keyword': [
14+
{
15+
pattern: /\b(?:align|offset)=/,
16+
inside: {
17+
'operator': /=/
18+
}
19+
},
20+
{
21+
pattern: /\b(?:(?:f32|f64|i32|i64)(?:\.(?:abs|add|and|ceil|clz|const|convert_[su]\/i(?:32|64)|copysign|ctz|demote\/f64|div(?:_[su])?|eqz?|extend_[su]\/i32|floor|ge(?:_[su])?|gt(?:_[su])?|le(?:_[su])?|load(?:(?:8|16|32)_[su])?|lt(?:_[su])?|max|min|mul|nearest|neg?|or|popcnt|promote\/f32|reinterpret\/[fi](?:32|64)|rem_[su]|rot[lr]|shl|shr_[su]|store(?:8|16|32)?|sqrt|sub|trunc(?:_[su]\/f(?:32|64))?|wrap\/i64|xor))?|memory\.(?:grow|size))\b/,
22+
inside: {
23+
'punctuation': /\./
24+
}
25+
},
26+
/\b(?:anyfunc|block|br(?:_if|_table)?|call(?:_indirect)?|data|drop|elem|else|end|export|func|get_(?:global|local)|global|if|import|local|loop|memory|module|mut|nop|offset|param|result|return|select|set_(?:global|local)|start|table|tee_local|then|type|unreachable)\b/
27+
],
28+
'variable': /\$[\w!#$%&'*+\-./:<=>?@\\^_`|~]+/i,
29+
'number': /[+-]?\b(?:\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?|0x[\da-fA-F](?:_?[\da-fA-F])*(?:\.[\da-fA-F](?:_?[\da-fA-D])*)?(?:[pP][+-]?\d(?:_?\d)*)?)\b|\binf\b|\bnan(?::0x[\da-fA-F](?:_?[\da-fA-D])*)?\b/,
30+
'punctuation': /[()]/
31+
};

components/prism-wasm.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-wasm.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<h2>Comments</h2>
2+
<pre><code>;; Single line comment
3+
(; Multi-line
4+
comment ;)</code></pre>
5+
6+
<h2>Strings</h2>
7+
<pre><code>""
8+
"Foobar"
9+
"Foo\"ba\\r"</code></pre>
10+
11+
<h2>Numbers</h2>
12+
<pre><code>42
13+
3.1415
14+
0.4E-4
15+
-3.1_41_5
16+
0xBADFACE
17+
0xB_adF_a_c_e
18+
+0x4E.F7
19+
0xFFp+4
20+
inf
21+
nan
22+
nan:0xf4</code></pre>
23+
24+
<h2>Keywords</h2>
25+
<pre><code>(func (param i32) (param f32) (local f64)
26+
get_local 0
27+
get_local 1
28+
get_local 2)</code></pre>
29+
30+
<h2>Identifiers</h2>
31+
<pre><code>$p
32+
$getAnswer
33+
$return_i32</code></pre>
34+
35+
<h2>Full example</h2>
36+
<pre><code>(module
37+
(import "js" "memory" (memory 1))
38+
(import "js" "table" (table 1 anyfunc))
39+
(elem (i32.const 0) $shared0func)
40+
(func $shared0func (result i32)
41+
i32.const 0
42+
i32.load)
43+
)</code></pre>

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

+1-1
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#","gedcom":"GEDCOM","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"}/*]*/;
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#","gedcom":"GEDCOM","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","wasm":"WebAssembly","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

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;;
2+
;; Foobar
3+
;; (; foobar ;)
4+
(;;)
5+
(;Foobar;)
6+
(;Foo ;;bar
7+
baz;)
8+
9+
----------------------------------------------------
10+
11+
[
12+
["comment", ";;"],
13+
["comment", ";; Foobar"],
14+
["comment", ";; (; foobar ;)"],
15+
["comment", "(;;)"],
16+
["comment", "(;Foobar;)"],
17+
["comment", "(;Foo ;;bar\r\nbaz;)"]
18+
]
19+
20+
----------------------------------------------------
21+
22+
Checks for comments.

0 commit comments

Comments
 (0)