Skip to content

Commit ef53f02

Browse files
Added support for Web IDL (#3107)
1 parent 3b2238f commit ef53f02

20 files changed

+811
-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

+5
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,11 @@
14241424
"title": "WebAssembly",
14251425
"owner": "Golmote"
14261426
},
1427+
"web-idl": {
1428+
"title": "Web IDL",
1429+
"alias": "webidl",
1430+
"owner": "RunDevelopment"
1431+
},
14271432
"wiki": {
14281433
"title": "Wiki markup",
14291434
"require": "markup",

components/prism-web-idl.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
(function (Prism) {
2+
3+
var id = /(?:\B-|\b_|\b)[A-Za-z][\w-]*(?![\w-])/.source;
4+
var type =
5+
'(?:' +
6+
/\b(?:unsigned\s+)?long\s+long(?![\w-])/.source +
7+
'|' +
8+
/\b(?:unrestricted|unsigned)\s+[a-z]+(?![\w-])/.source +
9+
'|' +
10+
/(?!(?:unrestricted|unsigned)\b)/.source + id + /(?:\s*<(?:[^<>]|<[^<>]*>)*>)?/.source +
11+
')' + /(?:\s*\?)?/.source;
12+
13+
var typeInside = {};
14+
15+
Prism.languages['web-idl'] = {
16+
'comment': {
17+
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
18+
greedy: true
19+
},
20+
'string': {
21+
pattern: /"[^"]*"/,
22+
greedy: true
23+
},
24+
25+
'namespace': {
26+
pattern: RegExp(/(\bnamespace\s+)/.source + id),
27+
lookbehind: true,
28+
},
29+
'class-name': [
30+
{
31+
pattern: /(^|[^\w-])(?:iterable|maplike|setlike)\s*<(?:[^<>]|<[^<>]*>)*>/,
32+
lookbehind: true,
33+
inside: typeInside
34+
},
35+
{
36+
pattern: RegExp(/(\b(?:attribute|const|deleter|getter|optional|setter)\s+)/.source + type),
37+
lookbehind: true,
38+
inside: typeInside
39+
},
40+
{
41+
// callback return type
42+
pattern: RegExp('(' + /\bcallback\s+/.source + id + /\s*=\s*/.source + ')' + type),
43+
lookbehind: true,
44+
inside: typeInside
45+
},
46+
{
47+
// typedef
48+
pattern: RegExp(/(\btypedef\b\s*)/.source + type),
49+
lookbehind: true,
50+
inside: typeInside
51+
},
52+
53+
{
54+
pattern: RegExp(/(\b(?:callback|dictionary|enum|interface(?:\s+mixin)?)\s+)(?!(?:interface|mixin)\b)/.source + id),
55+
lookbehind: true,
56+
},
57+
{
58+
// inheritance
59+
pattern: RegExp(/(:\s*)/.source + id),
60+
lookbehind: true,
61+
},
62+
63+
// includes and implements
64+
RegExp(id + /(?=\s+(?:implements|includes)\b)/.source),
65+
{
66+
pattern: RegExp(/(\b(?:implements|includes)\s+)/.source + id),
67+
lookbehind: true,
68+
},
69+
70+
{
71+
// function return type, parameter types, and dictionary members
72+
pattern: RegExp(type + '(?=' + /\s*(?:\.{3}\s*)?/.source + id + /\s*[(),;=]/.source + ')'),
73+
inside: typeInside
74+
},
75+
],
76+
77+
'builtin': /\b(?:ArrayBuffer|BigInt64Array|BigUint64Array|ByteString|DOMString|DataView|Float32Array|Float64Array|FrozenArray|Int16Array|Int32Array|Int8Array|ObservableArray|Promise|USVString|Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray)\b/,
78+
'keyword': [
79+
/\b(?:async|attribute|callback|const|constructor|deleter|dictionary|enum|getter|implements|includes|inherit|interface|mixin|namespace|null|optional|or|partial|readonly|required|setter|static|stringifier|typedef|unrestricted)\b/,
80+
// type keywords
81+
/\b(?:any|bigint|boolean|byte|double|float|iterable|long|maplike|object|octet|record|sequence|setlike|short|symbol|undefined|unsigned|void)\b/
82+
],
83+
'boolean': /\b(?:false|true)\b/,
84+
85+
'number': {
86+
pattern: /(^|[^\w-])-?(?:0x[0-9a-f]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|NaN|Infinity)(?![\w-])/i,
87+
lookbehind: true
88+
},
89+
'operator': /\.{3}|[=:?<>-]/,
90+
'punctuation': /[(){}[\].,;]/
91+
};
92+
93+
for (var key in Prism.languages['web-idl']) {
94+
if (key !== 'class-name') {
95+
typeInside[key] = Prism.languages['web-idl'][key];
96+
}
97+
}
98+
99+
Prism.languages['webidl'] = Prism.languages['web-idl'];
100+
101+
}(Prism));

components/prism-web-idl.min.js

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

examples/prism-web-idl.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<h2>Full example</h2>
2+
<pre><code>[Exposed=Window]
3+
interface Paint { };
4+
5+
[Exposed=Window]
6+
interface SolidColor : Paint {
7+
attribute double red;
8+
attribute double green;
9+
attribute double blue;
10+
};
11+
12+
[Exposed=Window]
13+
interface Pattern : Paint {
14+
attribute DOMString imageURL;
15+
};
16+
17+
[Exposed=Window]
18+
interface GraphicalWindow {
19+
constructor();
20+
readonly attribute unsigned long width;
21+
readonly attribute unsigned long height;
22+
23+
attribute Paint currentPaint;
24+
25+
undefined drawRectangle(double x, double y, double width, double height);
26+
27+
undefined drawText(double x, double y, DOMString text);
28+
};</code></pre>

plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
"url": "uri",
251251
"vb": "visual-basic",
252252
"vba": "visual-basic",
253+
"webidl": "web-idl",
253254
"mathematica": "wolfram",
254255
"nb": "wolfram",
255256
"wl": "wolfram",

plugins/autoloader/prism-autoloader.min.js

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

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

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
"vba": "VBA",
247247
"vb": "Visual Basic",
248248
"wasm": "WebAssembly",
249+
"web-idl": "Web IDL",
250+
"webidl": "Web IDL",
249251
"wiki": "Wiki markup",
250252
"wolfram": "Wolfram language",
251253
"nb": "Mathematica Notebook",

0 commit comments

Comments
 (0)