@willbooster/tree-sitter-html 2.0.1 → 3.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/README.md +14 -4
- package/grammar.js +30 -5
- package/package.json +1 -1
- package/src/node-types.json +39 -6
- package/tree-sitter-html.wasm +0 -0
- package/tree-sitter.json +4 -2
package/README.md
CHANGED
|
@@ -14,13 +14,13 @@ to its authors and contributors. This is not an official release of that project
|
|
|
14
14
|
|
|
15
15
|
This fork is based on upstream's version 0.23.2 grammar and external scanner and generates the parser with the
|
|
16
16
|
[WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries that fork's own ABI
|
|
17
|
-
number, so it loads only with the WillBooster runtime, version 2.
|
|
17
|
+
number, so it loads only with the WillBooster runtime, version 2.x
|
|
18
18
|
([willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter),
|
|
19
19
|
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter)); upstream's runtime rejects
|
|
20
20
|
it. Input that contains NUL characters can parse to a different tree than with upstream's 0.23.2 parser, because the
|
|
21
21
|
lexers that generator emits treat a NUL character as an ordinary character. This grammar also accepts literal `>`
|
|
22
22
|
characters and bare `&` in text nodes, which upstream 0.23.2 rejects. A bare `&` becomes its own `text` node beside
|
|
23
|
-
surrounding text, while character references remain `entity` nodes. Text nodes include leading, trailing, and whitespace-only content, including whitespace between markup and character references.
|
|
23
|
+
surrounding text, while character references remain `entity` nodes. Text nodes include leading, trailing, and whitespace-only content, including whitespace between markup and character references. A DOCTYPE declaration exposes its uninterpreted body as a `doctype_value` child, including legacy PUBLIC or SYSTEM identifiers. The grammar's scanner requires an HTML tag-name boundary after
|
|
24
24
|
`</script` and `</style`, so longer names and overlapping prefixes remain raw text. Closing-name comparisons
|
|
25
25
|
fold only ASCII letters, and embedded NUL characters remain part of raw-text content. Script content follows
|
|
26
26
|
HTML escaped and double-escaped states, so closing-tag text inside a double escape remains raw text. A script that reaches
|
|
@@ -34,10 +34,17 @@ exceeds its fixed-size buffer, the outermost tag identities are lost, which can
|
|
|
34
34
|
tags close. Custom tag names longer than 255 bytes are truncated in serialized state.
|
|
35
35
|
Malformed input after a void element can replace its enclosing element with an `ERROR` node during recovery.
|
|
36
36
|
|
|
37
|
+
Attribute values retain their complete `attribute_value` range and expose recognized named and numeric character
|
|
38
|
+
references as `entity` children. Quoted values retain their `quoted_attribute_value` wrapper. Other value content,
|
|
39
|
+
including literal ampersands, has no child nodes, so injections targeting `attribute_value` retain it by default. Set `injection.include-children` when the injected language needs the original reference
|
|
40
|
+
spellings. Legacy names without a semicolon remain literal before an ASCII letter, digit, or `=`; unknown
|
|
41
|
+
names and incomplete numeric prefixes remain literal. Comments are document or element content, and are not accepted
|
|
42
|
+
between attributes. Comment-shaped text inside a quoted value remains part of that value.
|
|
43
|
+
|
|
37
44
|
## Usage
|
|
38
45
|
|
|
39
46
|
The npm package ships `tree-sitter-html.wasm` for
|
|
40
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 2.
|
|
47
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 2.x, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
|
|
41
48
|
|
|
42
49
|
```js
|
|
43
50
|
import { fileURLToPath } from 'node:url';
|
|
@@ -84,7 +91,7 @@ fuzzed with:
|
|
|
84
91
|
```toml
|
|
85
92
|
[dependencies]
|
|
86
93
|
tree-sitter = { package = "willbooster-tree-sitter", version = "2.0.0" }
|
|
87
|
-
tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "
|
|
94
|
+
tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "3" }
|
|
88
95
|
```
|
|
89
96
|
|
|
90
97
|
```rust
|
|
@@ -143,6 +150,9 @@ afterwards.
|
|
|
143
150
|
CI also runs these tests on Linux arm64 and macOS, where the CLI compiles the parser and the scanner natively, and fuzzes
|
|
144
151
|
both with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
|
145
152
|
|
|
153
|
+
Run `script/generate-entities` with Python 3.8 or later when refreshing the HTML Standard's named-reference data, then regenerate
|
|
154
|
+
and commit `src/`. The command reads the official `entities.json` over HTTPS.
|
|
155
|
+
|
|
146
156
|
### References
|
|
147
157
|
|
|
148
158
|
- [The HTML Standard](https://html.spec.whatwg.org/multipage/)
|
package/grammar.js
CHANGED
|
@@ -12,7 +12,6 @@ module.exports = grammar({
|
|
|
12
12
|
name: 'html',
|
|
13
13
|
|
|
14
14
|
extras: $ => [
|
|
15
|
-
$.comment,
|
|
16
15
|
/\s+/,
|
|
17
16
|
],
|
|
18
17
|
|
|
@@ -26,6 +25,10 @@ module.exports = grammar({
|
|
|
26
25
|
$._implicit_end_tag,
|
|
27
26
|
$.raw_text,
|
|
28
27
|
$.comment,
|
|
28
|
+
$._attribute_entity,
|
|
29
|
+
$._unquoted_attribute_entity,
|
|
30
|
+
$._attribute_ampersand,
|
|
31
|
+
$._unquoted_attribute_fragment,
|
|
29
32
|
],
|
|
30
33
|
|
|
31
34
|
rules: {
|
|
@@ -34,14 +37,17 @@ module.exports = grammar({
|
|
|
34
37
|
doctype: $ => seq(
|
|
35
38
|
'<!',
|
|
36
39
|
alias($._doctype, 'doctype'),
|
|
37
|
-
|
|
40
|
+
$.doctype_value,
|
|
38
41
|
'>',
|
|
39
42
|
),
|
|
40
43
|
|
|
41
44
|
_doctype: _ => /[Dd][Oo][Cc][Tt][Yy][Pp][Ee]/,
|
|
42
45
|
|
|
46
|
+
doctype_value: _ => repeat1(/[^>]+/),
|
|
47
|
+
|
|
43
48
|
_node: $ => choice(
|
|
44
49
|
$.doctype,
|
|
50
|
+
$.comment,
|
|
45
51
|
$.entity,
|
|
46
52
|
$.text,
|
|
47
53
|
$.element,
|
|
@@ -124,13 +130,32 @@ module.exports = grammar({
|
|
|
124
130
|
|
|
125
131
|
attribute_name: _ => /[^<>"'/=\s]+/,
|
|
126
132
|
|
|
127
|
-
attribute_value:
|
|
133
|
+
attribute_value: $ => seq(
|
|
134
|
+
choice(
|
|
135
|
+
alias($._unquoted_attribute_entity, $.entity),
|
|
136
|
+
/[^<>"'=\s&]+/,
|
|
137
|
+
$._attribute_ampersand,
|
|
138
|
+
),
|
|
139
|
+
repeat(choice(
|
|
140
|
+
alias($._attribute_entity, $.entity),
|
|
141
|
+
$._unquoted_attribute_fragment,
|
|
142
|
+
$._attribute_ampersand,
|
|
143
|
+
)),
|
|
144
|
+
),
|
|
128
145
|
|
|
129
146
|
entity: _ => token(/&(#([xX][0-9a-fA-F]+|[0-9]+)|[A-Za-z][A-Za-z0-9]*);?/),
|
|
130
147
|
|
|
131
148
|
quoted_attribute_value: $ => choice(
|
|
132
|
-
seq('\'', optional(alias(
|
|
133
|
-
|
|
149
|
+
seq('\'', optional(alias(repeat1(choice(
|
|
150
|
+
alias($._attribute_entity, $.entity),
|
|
151
|
+
token.immediate(/[^'&]+/),
|
|
152
|
+
$._attribute_ampersand,
|
|
153
|
+
)), $.attribute_value)), '\''),
|
|
154
|
+
seq('"', optional(alias(repeat1(choice(
|
|
155
|
+
alias($._attribute_entity, $.entity),
|
|
156
|
+
token.immediate(/[^"&]+/),
|
|
157
|
+
$._attribute_ampersand,
|
|
158
|
+
)), $.attribute_value)), '"'),
|
|
134
159
|
),
|
|
135
160
|
|
|
136
161
|
text: _ => token.immediate(/[^<&]+|&/),
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
|
@@ -22,9 +22,39 @@
|
|
|
22
22
|
]
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
+
{
|
|
26
|
+
"type": "attribute_value",
|
|
27
|
+
"named": true,
|
|
28
|
+
"fields": {},
|
|
29
|
+
"children": {
|
|
30
|
+
"multiple": true,
|
|
31
|
+
"required": false,
|
|
32
|
+
"types": [
|
|
33
|
+
{
|
|
34
|
+
"type": "entity",
|
|
35
|
+
"named": true
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
25
40
|
{
|
|
26
41
|
"type": "doctype",
|
|
27
42
|
"named": true,
|
|
43
|
+
"fields": {},
|
|
44
|
+
"children": {
|
|
45
|
+
"multiple": false,
|
|
46
|
+
"required": true,
|
|
47
|
+
"types": [
|
|
48
|
+
{
|
|
49
|
+
"type": "doctype_value",
|
|
50
|
+
"named": true
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"type": "doctype_value",
|
|
57
|
+
"named": true,
|
|
28
58
|
"fields": {}
|
|
29
59
|
},
|
|
30
60
|
{
|
|
@@ -36,6 +66,10 @@
|
|
|
36
66
|
"multiple": true,
|
|
37
67
|
"required": false,
|
|
38
68
|
"types": [
|
|
69
|
+
{
|
|
70
|
+
"type": "comment",
|
|
71
|
+
"named": true
|
|
72
|
+
},
|
|
39
73
|
{
|
|
40
74
|
"type": "doctype",
|
|
41
75
|
"named": true
|
|
@@ -75,6 +109,10 @@
|
|
|
75
109
|
"multiple": true,
|
|
76
110
|
"required": true,
|
|
77
111
|
"types": [
|
|
112
|
+
{
|
|
113
|
+
"type": "comment",
|
|
114
|
+
"named": true
|
|
115
|
+
},
|
|
78
116
|
{
|
|
79
117
|
"type": "doctype",
|
|
80
118
|
"named": true
|
|
@@ -283,14 +321,9 @@
|
|
|
283
321
|
"type": "attribute_name",
|
|
284
322
|
"named": true
|
|
285
323
|
},
|
|
286
|
-
{
|
|
287
|
-
"type": "attribute_value",
|
|
288
|
-
"named": true
|
|
289
|
-
},
|
|
290
324
|
{
|
|
291
325
|
"type": "comment",
|
|
292
|
-
"named": true
|
|
293
|
-
"extra": true
|
|
326
|
+
"named": true
|
|
294
327
|
},
|
|
295
328
|
{
|
|
296
329
|
"type": "doctype",
|
package/tree-sitter-html.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
"scope": "source.html",
|
|
8
8
|
"path": ".",
|
|
9
9
|
"external-files": [
|
|
10
|
-
"src/tag.h"
|
|
10
|
+
"src/tag.h",
|
|
11
|
+
"src/attributeEntity.h",
|
|
12
|
+
"src/entities.h"
|
|
11
13
|
],
|
|
12
14
|
"file-types": [
|
|
13
15
|
"html"
|
|
@@ -18,7 +20,7 @@
|
|
|
18
20
|
}
|
|
19
21
|
],
|
|
20
22
|
"metadata": {
|
|
21
|
-
"version": "
|
|
23
|
+
"version": "3.1.0",
|
|
22
24
|
"license": "MIT",
|
|
23
25
|
"description": "HTML grammar for tree-sitter",
|
|
24
26
|
"authors": [
|