@willbooster/tree-sitter-html 8.0.0 → 9.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 +11 -6
- package/grammar.js +9 -0
- package/package.json +15 -18
- package/src/node-types.json +27 -0
- 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,10 +41,14 @@ 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.
|
|
@@ -65,6 +69,7 @@ In Node.js and Bun, load the grammar from its path:
|
|
|
65
69
|
|
|
66
70
|
```js
|
|
67
71
|
import { fileURLToPath } from 'node:url';
|
|
72
|
+
|
|
68
73
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
69
74
|
|
|
70
75
|
await Parser.init();
|
|
@@ -77,9 +82,9 @@ const tree = parser.parse('<!DOCTYPE html>\n<p>Hello</p>\n');
|
|
|
77
82
|
In browsers, serve both `.wasm` files and load them by URL (the example uses Vite's `?url` imports):
|
|
78
83
|
|
|
79
84
|
```js
|
|
85
|
+
import htmlUrl from '@willbooster/tree-sitter-html/tree-sitter-html.wasm?url';
|
|
80
86
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
81
87
|
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
88
|
|
|
84
89
|
await Parser.init({ locateFile: () => runtimeUrl });
|
|
85
90
|
const parser = new Parser();
|
|
@@ -90,9 +95,9 @@ Cloudflare Workers do not allow compiling Wasm at run time, so import both `.was
|
|
|
90
95
|
Node.js compatibility:
|
|
91
96
|
|
|
92
97
|
```js
|
|
98
|
+
import html from '@willbooster/tree-sitter-html/tree-sitter-html.wasm';
|
|
93
99
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
94
100
|
import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
|
|
95
|
-
import html from '@willbooster/tree-sitter-html/tree-sitter-html.wasm';
|
|
96
101
|
|
|
97
102
|
await Parser.init({ wasmModule: runtime });
|
|
98
103
|
const parser = new Parser();
|
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),
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-html",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.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/src/node-types.json
CHANGED
|
@@ -101,6 +101,10 @@
|
|
|
101
101
|
{
|
|
102
102
|
"type": "text",
|
|
103
103
|
"named": true
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"type": "void_element",
|
|
107
|
+
"named": true
|
|
104
108
|
}
|
|
105
109
|
]
|
|
106
110
|
}
|
|
@@ -160,6 +164,10 @@
|
|
|
160
164
|
{
|
|
161
165
|
"type": "text",
|
|
162
166
|
"named": true
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"type": "void_element",
|
|
170
|
+
"named": true
|
|
163
171
|
}
|
|
164
172
|
]
|
|
165
173
|
}
|
|
@@ -293,6 +301,25 @@
|
|
|
293
301
|
]
|
|
294
302
|
}
|
|
295
303
|
},
|
|
304
|
+
{
|
|
305
|
+
"type": "void_element",
|
|
306
|
+
"named": true,
|
|
307
|
+
"fields": {},
|
|
308
|
+
"children": {
|
|
309
|
+
"multiple": true,
|
|
310
|
+
"required": true,
|
|
311
|
+
"types": [
|
|
312
|
+
{
|
|
313
|
+
"type": "attribute",
|
|
314
|
+
"named": true
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"type": "tag_name",
|
|
318
|
+
"named": true
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
},
|
|
296
323
|
{
|
|
297
324
|
"type": "\"",
|
|
298
325
|
"named": false
|
package/tree-sitter-html.wasm
CHANGED
|
Binary file
|