@willbooster/tree-sitter-html 8.0.0 → 10.0.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/README.md +23 -13
- package/grammar.js +24 -15
- package/package.json +15 -18
- package/queries/highlights.scm +4 -1
- package/src/node-types.json +78 -17
- package/tree-sitter-html.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-html/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-html/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](https://crates.io/crates/willbooster-tree-sitter-html)
|
|
10
10
|
|
|
11
11
|
HTML grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
@@ -41,21 +41,30 @@ uses HTML parsing for its children. Encoding comparisons ignore ASCII case and d
|
|
|
41
41
|
HTML escaped and double-escaped states, so closing-tag text inside a double escape remains raw text. A script that reaches
|
|
42
42
|
EOF while scanning raw content closes implicitly without an error: its `script_element` has no `end_tag` child, and its
|
|
43
43
|
remaining content stays available for JavaScript injection. Incomplete closing tags such as `</script` still report
|
|
44
|
-
recovery errors. Unterminated style elements still report an error.
|
|
45
|
-
|
|
44
|
+
recovery errors. Unterminated style elements still report an error. HTML-namespace void elements such as `<input>` and
|
|
45
|
+
`<br/>` use `void_element` nodes with direct `tag_name` and `attribute` children. Following text, entities, comments,
|
|
46
|
+
and processing instructions are siblings, and explicit void-element end tags are `erroneous_end_tag` siblings.
|
|
47
|
+
In SVG/MathML content outside HTML integration points, HTML breakout start tags such as `<p>` and `<span>` implicitly
|
|
48
|
+
close the foreign ancestors. The same applies to `<font>` with a `color`, `face`, or `size` attribute and to `</br>` or
|
|
49
|
+
`</p>`. Later end tags for those foreign ancestors become `erroneous_end_tag` nodes.
|
|
46
50
|
Scanner serialization stores the open-tag stack from its innermost tag, compressing runs of identical tags, so active
|
|
47
|
-
|
|
51
|
+
script and style elements retain their identities when deeply nested. When distinct tags exceed the fixed-size
|
|
48
52
|
buffer, serialization prioritizes inner tags and outer namespace boundaries, replacing ordinary outer tags with unknown
|
|
49
53
|
runs. Custom tag names are retained in full when they fit the remaining buffer. Names that exceed the buffer are
|
|
50
54
|
omitted along with older tags. Lost tag identities can still produce recovery errors when those tags close.
|
|
51
55
|
Malformed input after a void element can replace its enclosing element with an `ERROR` node during recovery.
|
|
52
56
|
|
|
53
|
-
Attribute values
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
Attribute values use distinct `unquoted_attribute_value`, `singlequoted_attribute_value`, and
|
|
58
|
+
`doublequoted_attribute_value` nodes directly inside `attribute`. Quoted nodes include both delimiters and retain an
|
|
59
|
+
`attribute_value` child for nonempty content; empty quoted values have no content child. Unquoted nodes cover the value
|
|
60
|
+
without surrounding whitespace. Recognized named and numeric character references are `entity` children of the content
|
|
61
|
+
node. Other content, including literal ampersands, has no child nodes. Injections that need quote-free value content can
|
|
62
|
+
capture `attribute_value` and `unquoted_attribute_value`; set `injection.include-children` when they need the original
|
|
63
|
+
reference spellings as well. The highlight query captures those same content nodes, excluding quote delimiters.
|
|
64
|
+
Legacy names without a semicolon remain literal before an ASCII letter, digit, or `=`; unknown names and incomplete
|
|
65
|
+
numeric prefixes remain literal. Comments are document or element content and are not accepted between attributes.
|
|
66
|
+
Comment-shaped text inside a quoted value remains part of that value. Whitespace after `=` separates the operator from
|
|
67
|
+
the value, so `noval= bool` remains one attribute with the unquoted value `bool`.
|
|
59
68
|
|
|
60
69
|
## Usage
|
|
61
70
|
|
|
@@ -65,6 +74,7 @@ In Node.js and Bun, load the grammar from its path:
|
|
|
65
74
|
|
|
66
75
|
```js
|
|
67
76
|
import { fileURLToPath } from 'node:url';
|
|
77
|
+
|
|
68
78
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
69
79
|
|
|
70
80
|
await Parser.init();
|
|
@@ -77,9 +87,9 @@ const tree = parser.parse('<!DOCTYPE html>\n<p>Hello</p>\n');
|
|
|
77
87
|
In browsers, serve both `.wasm` files and load them by URL (the example uses Vite's `?url` imports):
|
|
78
88
|
|
|
79
89
|
```js
|
|
90
|
+
import htmlUrl from '@willbooster/tree-sitter-html/tree-sitter-html.wasm?url';
|
|
80
91
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
81
92
|
import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url';
|
|
82
|
-
import htmlUrl from '@willbooster/tree-sitter-html/tree-sitter-html.wasm?url';
|
|
83
93
|
|
|
84
94
|
await Parser.init({ locateFile: () => runtimeUrl });
|
|
85
95
|
const parser = new Parser();
|
|
@@ -90,9 +100,9 @@ Cloudflare Workers do not allow compiling Wasm at run time, so import both `.was
|
|
|
90
100
|
Node.js compatibility:
|
|
91
101
|
|
|
92
102
|
```js
|
|
103
|
+
import html from '@willbooster/tree-sitter-html/tree-sitter-html.wasm';
|
|
93
104
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
94
105
|
import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
|
|
95
|
-
import html from '@willbooster/tree-sitter-html/tree-sitter-html.wasm';
|
|
96
106
|
|
|
97
107
|
await Parser.init({ wasmModule: runtime });
|
|
98
108
|
const parser = new Parser();
|
|
@@ -108,7 +118,7 @@ fuzzed with:
|
|
|
108
118
|
```toml
|
|
109
119
|
[dependencies]
|
|
110
120
|
tree-sitter = { package = "willbooster-tree-sitter", version = "13.0.0" }
|
|
111
|
-
tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "
|
|
121
|
+
tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "10" }
|
|
112
122
|
```
|
|
113
123
|
|
|
114
124
|
```rust
|
package/grammar.js
CHANGED
|
@@ -34,6 +34,7 @@ module.exports = grammar({
|
|
|
34
34
|
$._unquoted_attribute_fragment,
|
|
35
35
|
$._discarded_start_tag,
|
|
36
36
|
$._missing_start_tag_end,
|
|
37
|
+
$._void_start_tag_name,
|
|
37
38
|
],
|
|
38
39
|
|
|
39
40
|
rules: {
|
|
@@ -61,6 +62,7 @@ module.exports = grammar({
|
|
|
61
62
|
$.text,
|
|
62
63
|
alias('&', $.text),
|
|
63
64
|
$.element,
|
|
65
|
+
$.void_element,
|
|
64
66
|
$.script_element,
|
|
65
67
|
$.style_element,
|
|
66
68
|
$.erroneous_end_tag,
|
|
@@ -75,6 +77,13 @@ module.exports = grammar({
|
|
|
75
77
|
$.self_closing_tag,
|
|
76
78
|
),
|
|
77
79
|
|
|
80
|
+
void_element: $ => seq(
|
|
81
|
+
'<',
|
|
82
|
+
alias($._void_start_tag_name, $.tag_name),
|
|
83
|
+
repeat($.attribute),
|
|
84
|
+
choice(seq('>', $._implicit_end_tag), '/>'),
|
|
85
|
+
),
|
|
86
|
+
|
|
78
87
|
script_element: $ => seq(
|
|
79
88
|
alias($.script_start_tag, $.start_tag),
|
|
80
89
|
optional($.raw_text),
|
|
@@ -132,15 +141,16 @@ module.exports = grammar({
|
|
|
132
141
|
optional(seq(
|
|
133
142
|
'=',
|
|
134
143
|
choice(
|
|
135
|
-
$.
|
|
136
|
-
$.
|
|
144
|
+
$.unquoted_attribute_value,
|
|
145
|
+
$.singlequoted_attribute_value,
|
|
146
|
+
$.doublequoted_attribute_value,
|
|
137
147
|
),
|
|
138
148
|
)),
|
|
139
149
|
),
|
|
140
150
|
|
|
141
151
|
attribute_name: _ => /[^<>"'/=\s]+/,
|
|
142
152
|
|
|
143
|
-
|
|
153
|
+
unquoted_attribute_value: $ => seq(
|
|
144
154
|
choice(
|
|
145
155
|
alias($._unquoted_attribute_entity, $.entity),
|
|
146
156
|
/[^<>"'=\s&]+/,
|
|
@@ -155,18 +165,17 @@ module.exports = grammar({
|
|
|
155
165
|
|
|
156
166
|
entity: _ => token(/&(#([xX][0-9a-fA-F]+|[0-9]+)|[A-Za-z][A-Za-z0-9]*);?/),
|
|
157
167
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
),
|
|
168
|
+
singlequoted_attribute_value: $ => seq('\'', optional(alias(repeat1(choice(
|
|
169
|
+
alias($._attribute_entity, $.entity),
|
|
170
|
+
token.immediate(/[^'&]+/),
|
|
171
|
+
$._attribute_ampersand,
|
|
172
|
+
)), $.attribute_value)), '\''),
|
|
173
|
+
|
|
174
|
+
doublequoted_attribute_value: $ => seq('"', optional(alias(repeat1(choice(
|
|
175
|
+
alias($._attribute_entity, $.entity),
|
|
176
|
+
token.immediate(/[^"&]+/),
|
|
177
|
+
$._attribute_ampersand,
|
|
178
|
+
)), $.attribute_value)), '"'),
|
|
170
179
|
|
|
171
180
|
text: _ => token(prec(1, /[^<&]+/)),
|
|
172
181
|
},
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-html",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "HTML grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"html",
|
|
6
7
|
"incremental",
|
|
7
8
|
"parsing",
|
|
8
|
-
"tree-sitter"
|
|
9
|
-
"html"
|
|
9
|
+
"tree-sitter"
|
|
10
10
|
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "WillBooster Inc.",
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
13
15
|
"url": "git+https://github.com/WillBooster/tree-sitter-html.git"
|
|
14
16
|
},
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"author": "WillBooster Inc.",
|
|
17
17
|
"files": [
|
|
18
18
|
"grammar.js",
|
|
19
19
|
"queries/*.scm",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"tree-sitter.json",
|
|
22
22
|
"*.wasm"
|
|
23
23
|
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
24
28
|
"scripts": {
|
|
25
29
|
"build-wasm": "script/generate --build-wasm",
|
|
26
30
|
"build/ci": "bun run build-wasm",
|
|
@@ -43,21 +47,18 @@
|
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"@tsconfig/bun": "1.0.11",
|
|
45
49
|
"@types/bun": "1.4.3",
|
|
46
|
-
"@vitest/browser-playwright": "5.0.
|
|
47
|
-
"@willbooster/
|
|
48
|
-
"@willbooster/
|
|
49
|
-
"@willbooster/wb": "22.26.2",
|
|
50
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
51
|
+
"@willbooster/oxlint-config": "1.4.9",
|
|
52
|
+
"@willbooster/wb": "22.29.3",
|
|
50
53
|
"@willbooster/web-tree-sitter": "13.0.0",
|
|
51
54
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
52
55
|
"lefthook": "2.2.2",
|
|
53
|
-
"oxfmt": "0.73.0",
|
|
54
56
|
"oxlint": "1.88.0",
|
|
55
57
|
"oxlint-tsgolint": "7.0.2004",
|
|
56
|
-
"playwright": "1.64.
|
|
58
|
+
"playwright": "1.64.1",
|
|
57
59
|
"semantic-release": "25.0.9",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"wrangler": "4.149.0"
|
|
60
|
+
"vitest": "5.0.5",
|
|
61
|
+
"wrangler": "4.151.1"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
64
|
"@willbooster/web-tree-sitter": "^13.0.0"
|
|
@@ -66,9 +67,5 @@
|
|
|
66
67
|
"@willbooster/web-tree-sitter": {
|
|
67
68
|
"optional": true
|
|
68
69
|
}
|
|
69
|
-
},
|
|
70
|
-
"publishConfig": {
|
|
71
|
-
"access": "public",
|
|
72
|
-
"registry": "https://registry.npmjs.org/"
|
|
73
70
|
}
|
|
74
71
|
}
|
package/queries/highlights.scm
CHANGED
package/src/node-types.json
CHANGED
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
"named": true
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
"type": "
|
|
15
|
+
"type": "doublequoted_attribute_value",
|
|
16
|
+
"named": true
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"type": "singlequoted_attribute_value",
|
|
16
20
|
"named": true
|
|
17
21
|
},
|
|
18
22
|
{
|
|
19
|
-
"type": "
|
|
23
|
+
"type": "unquoted_attribute_value",
|
|
20
24
|
"named": true
|
|
21
25
|
}
|
|
22
26
|
]
|
|
@@ -101,6 +105,25 @@
|
|
|
101
105
|
{
|
|
102
106
|
"type": "text",
|
|
103
107
|
"named": true
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"type": "void_element",
|
|
111
|
+
"named": true
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"type": "doublequoted_attribute_value",
|
|
118
|
+
"named": true,
|
|
119
|
+
"fields": {},
|
|
120
|
+
"children": {
|
|
121
|
+
"multiple": false,
|
|
122
|
+
"required": false,
|
|
123
|
+
"types": [
|
|
124
|
+
{
|
|
125
|
+
"type": "attribute_value",
|
|
126
|
+
"named": true
|
|
104
127
|
}
|
|
105
128
|
]
|
|
106
129
|
}
|
|
@@ -160,6 +183,10 @@
|
|
|
160
183
|
{
|
|
161
184
|
"type": "text",
|
|
162
185
|
"named": true
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"type": "void_element",
|
|
189
|
+
"named": true
|
|
163
190
|
}
|
|
164
191
|
]
|
|
165
192
|
}
|
|
@@ -194,21 +221,6 @@
|
|
|
194
221
|
]
|
|
195
222
|
}
|
|
196
223
|
},
|
|
197
|
-
{
|
|
198
|
-
"type": "quoted_attribute_value",
|
|
199
|
-
"named": true,
|
|
200
|
-
"fields": {},
|
|
201
|
-
"children": {
|
|
202
|
-
"multiple": false,
|
|
203
|
-
"required": false,
|
|
204
|
-
"types": [
|
|
205
|
-
{
|
|
206
|
-
"type": "attribute_value",
|
|
207
|
-
"named": true
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
224
|
{
|
|
213
225
|
"type": "script_element",
|
|
214
226
|
"named": true,
|
|
@@ -251,6 +263,21 @@
|
|
|
251
263
|
]
|
|
252
264
|
}
|
|
253
265
|
},
|
|
266
|
+
{
|
|
267
|
+
"type": "singlequoted_attribute_value",
|
|
268
|
+
"named": true,
|
|
269
|
+
"fields": {},
|
|
270
|
+
"children": {
|
|
271
|
+
"multiple": false,
|
|
272
|
+
"required": false,
|
|
273
|
+
"types": [
|
|
274
|
+
{
|
|
275
|
+
"type": "attribute_value",
|
|
276
|
+
"named": true
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
},
|
|
254
281
|
{
|
|
255
282
|
"type": "start_tag",
|
|
256
283
|
"named": true,
|
|
@@ -293,6 +320,40 @@
|
|
|
293
320
|
]
|
|
294
321
|
}
|
|
295
322
|
},
|
|
323
|
+
{
|
|
324
|
+
"type": "unquoted_attribute_value",
|
|
325
|
+
"named": true,
|
|
326
|
+
"fields": {},
|
|
327
|
+
"children": {
|
|
328
|
+
"multiple": true,
|
|
329
|
+
"required": false,
|
|
330
|
+
"types": [
|
|
331
|
+
{
|
|
332
|
+
"type": "entity",
|
|
333
|
+
"named": true
|
|
334
|
+
}
|
|
335
|
+
]
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
"type": "void_element",
|
|
340
|
+
"named": true,
|
|
341
|
+
"fields": {},
|
|
342
|
+
"children": {
|
|
343
|
+
"multiple": true,
|
|
344
|
+
"required": true,
|
|
345
|
+
"types": [
|
|
346
|
+
{
|
|
347
|
+
"type": "attribute",
|
|
348
|
+
"named": true
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
"type": "tag_name",
|
|
352
|
+
"named": true
|
|
353
|
+
}
|
|
354
|
+
]
|
|
355
|
+
}
|
|
356
|
+
},
|
|
296
357
|
{
|
|
297
358
|
"type": "\"",
|
|
298
359
|
"named": false
|
package/tree-sitter-html.wasm
CHANGED
|
Binary file
|