@gaijin/highlightjs-blk 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/blk.d.ts +4 -0
- package/dist/blk.js +201 -0
- package/dist/blk.min.js +2 -0
- package/package.json +44 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gaijin Entertainment
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gaijin/highlightjs-blk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [highlight.js](https://highlightjs.org/) 11 grammar for BLK, the DataBlock text format of the
|
|
4
|
+
[Dagor Engine](https://github.com/GaijinEntertainment/DagorEngine). The language name is `blk`.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install highlight.js @gaijin/highlightjs-blk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import hljs from 'highlight.js/lib/core';
|
|
14
|
+
import blk from '@gaijin/highlightjs-blk';
|
|
15
|
+
|
|
16
|
+
hljs.registerLanguage('blk', blk);
|
|
17
|
+
const html = hljs.highlight(code, {language: 'blk'}).value;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
In a web page, load `dist/blk.min.js` after highlight.js. The script registers the grammar on the global `hljs`:
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/@gaijin/highlightjs-blk/dist/blk.min.js"></script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## References
|
|
27
|
+
|
|
28
|
+
- [GaijinEntertainment/tree-sitter-blk](https://github.com/GaijinEntertainment/tree-sitter-blk), the tree-sitter
|
|
29
|
+
grammar that this grammar follows.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
MIT. See [LICENSE](LICENSE).
|
package/dist/blk.d.ts
ADDED
package/dist/blk.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
//#region src/blk.ts
|
|
2
|
+
const TEXT_TYPES = ["t"];
|
|
3
|
+
const BOOLEAN_TYPES = ["b"];
|
|
4
|
+
const NUMBER_TYPES = [
|
|
5
|
+
"i64",
|
|
6
|
+
"ip2",
|
|
7
|
+
"ip3",
|
|
8
|
+
"ip4",
|
|
9
|
+
"p2",
|
|
10
|
+
"p3",
|
|
11
|
+
"p4",
|
|
12
|
+
"i",
|
|
13
|
+
"c",
|
|
14
|
+
"r",
|
|
15
|
+
"m"
|
|
16
|
+
];
|
|
17
|
+
const TYPE_WORDS = [
|
|
18
|
+
...NUMBER_TYPES,
|
|
19
|
+
...TEXT_TYPES,
|
|
20
|
+
...BOOLEAN_TYPES
|
|
21
|
+
];
|
|
22
|
+
const BOOLEAN_WORDS = [
|
|
23
|
+
"yes",
|
|
24
|
+
"no",
|
|
25
|
+
"true",
|
|
26
|
+
"false",
|
|
27
|
+
"on",
|
|
28
|
+
"off"
|
|
29
|
+
];
|
|
30
|
+
const NAME = "[A-Za-z0-9_.~-]+";
|
|
31
|
+
const QUOTE = "(?:\"\"\"|'''|\"|')";
|
|
32
|
+
const INCLUDE_WORD = "[iI][nN][cC][lL][uU][dD][eE]";
|
|
33
|
+
function typeName(types) {
|
|
34
|
+
return `${QUOTE}?~?(?:${types.join("|")})${QUOTE}?`;
|
|
35
|
+
}
|
|
36
|
+
function unquotedValue(stops) {
|
|
37
|
+
const slash = "\\/(?![/*])";
|
|
38
|
+
const last = `(?:[^\\s;}/${stops}]|${slash})`;
|
|
39
|
+
return `${`(?:[^\\s;}/"'${stops}]|${slash})`}(?:${`(?:[^;}\\r\\n/${stops}]|${slash}|${`\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\/(?=[ \\t]*${last})`})`}*${last})?`;
|
|
40
|
+
}
|
|
41
|
+
function blk(hljs) {
|
|
42
|
+
const STRING = {
|
|
43
|
+
scope: "string",
|
|
44
|
+
contains: [{
|
|
45
|
+
begin: /~[\s\S]/,
|
|
46
|
+
relevance: 0
|
|
47
|
+
}],
|
|
48
|
+
variants: [
|
|
49
|
+
{
|
|
50
|
+
begin: /"""/,
|
|
51
|
+
end: /"""/
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
begin: /'''/,
|
|
55
|
+
end: /'''/
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
begin: /"/,
|
|
59
|
+
end: /"|(?=\n)/
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
begin: /'/,
|
|
63
|
+
end: /'|(?=\n)/
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
const BLOCK_COMMENT = {
|
|
68
|
+
scope: "comment",
|
|
69
|
+
begin: /\/\*/,
|
|
70
|
+
end: /\*\//,
|
|
71
|
+
contains: ["self"]
|
|
72
|
+
};
|
|
73
|
+
const COMMENT_AFTER_UNQUOTED = {
|
|
74
|
+
scope: "comment",
|
|
75
|
+
begin: /(?<=[^\s;=[\]"'{}][ \t]*)\/\*/,
|
|
76
|
+
end: /\*\//
|
|
77
|
+
};
|
|
78
|
+
const value = (equals, scope, end = /(?=[;}\r\n]|\s*\/\/)/) => ({
|
|
79
|
+
begin: equals,
|
|
80
|
+
end,
|
|
81
|
+
contains: [
|
|
82
|
+
{
|
|
83
|
+
...COMMENT_AFTER_UNQUOTED,
|
|
84
|
+
endsParent: true
|
|
85
|
+
},
|
|
86
|
+
BLOCK_COMMENT,
|
|
87
|
+
{
|
|
88
|
+
...STRING,
|
|
89
|
+
endsParent: true
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
scope,
|
|
93
|
+
begin: new RegExp(unquotedValue(""))
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
const typedEquals = (types) => new RegExp(`(?<=:[ \\t]*${typeName(types)}[ \\t]*(?:;[ \\t]*)?)=`);
|
|
98
|
+
const ELEMENT = unquotedValue("\\]");
|
|
99
|
+
const ARRAY = {
|
|
100
|
+
begin: /(?<=\[\][ \t]*=\s*)\[/,
|
|
101
|
+
end: /\]/,
|
|
102
|
+
contains: [
|
|
103
|
+
hljs.C_LINE_COMMENT_MODE,
|
|
104
|
+
COMMENT_AFTER_UNQUOTED,
|
|
105
|
+
BLOCK_COMMENT,
|
|
106
|
+
STRING,
|
|
107
|
+
{
|
|
108
|
+
scope: "literal",
|
|
109
|
+
begin: new RegExp(`(?:${BOOLEAN_WORDS.join("|")})(?=[ \\t]*(?:[;}\\]\\r\\n]|\\/[/*]|$))`)
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
scope: "number",
|
|
113
|
+
begin: new RegExp(`(?=[-+.0-9])${ELEMENT}`)
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
scope: "string",
|
|
117
|
+
begin: new RegExp(ELEMENT)
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
};
|
|
121
|
+
const TYPE = {
|
|
122
|
+
begin: /:[ \t]*/,
|
|
123
|
+
end: /(?=\[|=|;|\s|\n|$)/,
|
|
124
|
+
contains: [{
|
|
125
|
+
scope: "type",
|
|
126
|
+
begin: new RegExp(`(?<![A-Za-z0-9_])${QUOTE}?~?(?:${TYPE_WORDS.join("|")})(?![A-Za-z0-9_])${QUOTE}?`)
|
|
127
|
+
}]
|
|
128
|
+
};
|
|
129
|
+
const INCLUDE = {
|
|
130
|
+
begin: new RegExp(`(?<![A-Za-z0-9_.~-])(?:(${QUOTE})${INCLUDE_WORD}\\1|${INCLUDE_WORD}(?![A-Za-z0-9_.~-]))(?![ \\t]*(?:[{:]|=[ \\t]*(?:[^\\s"']|"[^"\\n]*"|'[^'\\n]*')))`),
|
|
131
|
+
beginScope: "keyword",
|
|
132
|
+
end: /(?=[;}])/,
|
|
133
|
+
contains: [
|
|
134
|
+
{ begin: /(?<=["'])[ \t]*;/ },
|
|
135
|
+
BLOCK_COMMENT,
|
|
136
|
+
hljs.C_LINE_COMMENT_MODE,
|
|
137
|
+
{
|
|
138
|
+
...STRING,
|
|
139
|
+
endsParent: true
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
scope: "string",
|
|
143
|
+
begin: new RegExp(unquotedValue("")),
|
|
144
|
+
endsParent: true
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
name: "BLK",
|
|
150
|
+
contains: [
|
|
151
|
+
BLOCK_COMMENT,
|
|
152
|
+
hljs.C_LINE_COMMENT_MODE,
|
|
153
|
+
INCLUDE,
|
|
154
|
+
{
|
|
155
|
+
scope: "meta",
|
|
156
|
+
begin: new RegExp(`${QUOTE}~?@[^"'\\n]*?${QUOTE}`)
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
scope: "built_in",
|
|
160
|
+
begin: new RegExp(`${QUOTE}~?_[^"'\\n]*?${QUOTE}(?=\\s*(?:;\\s*)?\\{)`)
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
scope: "built_in",
|
|
164
|
+
begin: new RegExp(`${QUOTE}~?_[^"'\\n]*?${QUOTE}(?=\\s*(?:;\\s*)?[:=])`)
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
scope: "title",
|
|
168
|
+
begin: new RegExp(`${QUOTE}~?[^"'\\n]*?${QUOTE}(?=\\s*(?:;\\s*)?\\{)`)
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
scope: "attr",
|
|
172
|
+
begin: new RegExp(`${QUOTE}~?[^"'\\n]*?${QUOTE}(?=\\s*(?:;\\s*)?[:=])`)
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
scope: "built_in",
|
|
176
|
+
begin: new RegExp(`_${NAME}(?=\\s*\\{)`)
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
scope: "title",
|
|
180
|
+
begin: new RegExp(`(?!_)${NAME}(?=\\s*\\{)`)
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
scope: "built_in",
|
|
184
|
+
begin: new RegExp(`_${NAME}(?=\\s*[:=])`)
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
scope: "attr",
|
|
188
|
+
begin: new RegExp(`(?!_)${NAME}(?=\\s*[:=])`)
|
|
189
|
+
},
|
|
190
|
+
TYPE,
|
|
191
|
+
ARRAY,
|
|
192
|
+
value(typedEquals(TEXT_TYPES), "string"),
|
|
193
|
+
value(typedEquals(BOOLEAN_TYPES), "literal"),
|
|
194
|
+
value(typedEquals(NUMBER_TYPES), "number"),
|
|
195
|
+
value(/(?<!\[\][ \t]*)=/, "string", /(?=[;}]|\s*\/\/)|(?<!=[ \t]*)(?=[\r\n])/),
|
|
196
|
+
STRING
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
export { blk as default };
|
package/dist/blk.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var hljsBlk=(function(){let e=[`t`],t=[`b`],n=[`i64`,`ip2`,`ip3`,`ip4`,`p2`,`p3`,`p4`,`i`,`c`,`r`,`m`],r=[...n,...e,...t],i=[`yes`,`no`,`true`,`false`,`on`,`off`],a=`[A-Za-z0-9_.~-]+`,o=`(?:"""|'''|"|')`,s=`[iI][nN][cC][lL][uU][dD][eE]`;function c(e){return`${o}?~?(?:${e.join(`|`)})${o}?`}function l(e){let t=`\\/(?![/*])`,n=`(?:[^\\s;}/${e}]|${t})`;return`${`(?:[^\\s;}/"'${e}]|${t})`}(?:${`(?:[^;}\\r\\n/${e}]|${t}|${`\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\/(?=[ \\t]*${n})`})`}*${n})?`}function u(u){let d={scope:`string`,contains:[{begin:/~[\s\S]/,relevance:0}],variants:[{begin:/"""/,end:/"""/},{begin:/'''/,end:/'''/},{begin:/"/,end:/"|(?=\n)/},{begin:/'/,end:/'|(?=\n)/}]},f={scope:`comment`,begin:/\/\*/,end:/\*\//,contains:[`self`]},p={scope:`comment`,begin:/(?<=[^\s;=[\]"'{}][ \t]*)\/\*/,end:/\*\//},m=(e,t,n=/(?=[;}\r\n]|\s*\/\/)/)=>({begin:e,end:n,contains:[{...p,endsParent:!0},f,{...d,endsParent:!0},{scope:t,begin:new RegExp(l(``))}]}),h=e=>RegExp(`(?<=:[ \\t]*${c(e)}[ \\t]*(?:;[ \\t]*)?)=`),g=l(`\\]`),_={begin:/(?<=\[\][ \t]*=\s*)\[/,end:/\]/,contains:[u.C_LINE_COMMENT_MODE,p,f,d,{scope:`literal`,begin:RegExp(`(?:${i.join(`|`)})(?=[ \\t]*(?:[;}\\]\\r\\n]|\\/[/*]|$))`)},{scope:`number`,begin:RegExp(`(?=[-+.0-9])${g}`)},{scope:`string`,begin:new RegExp(g)}]},v={begin:/:[ \t]*/,end:/(?=\[|=|;|\s|\n|$)/,contains:[{scope:`type`,begin:RegExp(`(?<![A-Za-z0-9_])${o}?~?(?:${r.join(`|`)})(?![A-Za-z0-9_])${o}?`)}]},y={begin:RegExp(`(?<![A-Za-z0-9_.~-])(?:(${o})${s}\\1|${s}(?![A-Za-z0-9_.~-]))(?![ \\t]*(?:[{:]|=[ \\t]*(?:[^\\s"']|"[^"\\n]*"|'[^'\\n]*')))`),beginScope:`keyword`,end:/(?=[;}])/,contains:[{begin:/(?<=["'])[ \t]*;/},f,u.C_LINE_COMMENT_MODE,{...d,endsParent:!0},{scope:`string`,begin:new RegExp(l(``)),endsParent:!0}]};return{name:`BLK`,contains:[f,u.C_LINE_COMMENT_MODE,y,{scope:`meta`,begin:RegExp(`${o}~?@[^"'\\n]*?${o}`)},{scope:`built_in`,begin:RegExp(`${o}~?_[^"'\\n]*?${o}(?=\\s*(?:;\\s*)?\\{)`)},{scope:`built_in`,begin:RegExp(`${o}~?_[^"'\\n]*?${o}(?=\\s*(?:;\\s*)?[:=])`)},{scope:`title`,begin:RegExp(`${o}~?[^"'\\n]*?${o}(?=\\s*(?:;\\s*)?\\{)`)},{scope:`attr`,begin:RegExp(`${o}~?[^"'\\n]*?${o}(?=\\s*(?:;\\s*)?[:=])`)},{scope:`built_in`,begin:RegExp(`_${a}(?=\\s*\\{)`)},{scope:`title`,begin:RegExp(`(?!_)${a}(?=\\s*\\{)`)},{scope:`built_in`,begin:RegExp(`_${a}(?=\\s*[:=])`)},{scope:`attr`,begin:RegExp(`(?!_)${a}(?=\\s*[:=])`)},v,_,m(h(e),`string`),m(h(t),`literal`),m(h(n),`number`),m(/(?<!\[\][ \t]*)=/,`string`,/(?=[;}]|\s*\/\/)|(?<!=[ \t]*)(?=[\r\n])/),d]}}return u})();
|
|
2
|
+
hljs.registerLanguage("blk", hljsBlk);
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@gaijin/highlightjs-blk",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "highlight.js grammar for BLK, the DataBlock text format of the Dagor Engine",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"blk",
|
|
7
|
+
"dagor",
|
|
8
|
+
"highlight.js",
|
|
9
|
+
"highlightjs",
|
|
10
|
+
"syntax"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/GaijinEntertainment/dagor-hljs/tree/main/packages/blk#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/GaijinEntertainment/dagor-hljs/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Gaijin Entertainment"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/GaijinEntertainment/dagor-hljs.git",
|
|
23
|
+
"directory": "packages/blk"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/blk.d.ts",
|
|
33
|
+
"default": "./dist/blk.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "vp pack"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"highlight.js": "^11.12.0"
|
|
44
|
+
}
|
|
45
|
+
}
|