@willbooster/tree-sitter-html 2.0.0 → 3.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 CHANGED
@@ -14,7 +14,7 @@ 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.0.0 or later in the 2.x series
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
@@ -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.0.0 or later in the 2.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
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 = "2" }
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: {
@@ -42,6 +45,7 @@ module.exports = grammar({
42
45
 
43
46
  _node: $ => choice(
44
47
  $.doctype,
48
+ $.comment,
45
49
  $.entity,
46
50
  $.text,
47
51
  $.element,
@@ -124,13 +128,32 @@ module.exports = grammar({
124
128
 
125
129
  attribute_name: _ => /[^<>"'/=\s]+/,
126
130
 
127
- attribute_value: _ => /[^<>"'=\s]+/,
131
+ attribute_value: $ => seq(
132
+ choice(
133
+ alias($._unquoted_attribute_entity, $.entity),
134
+ /[^<>"'=\s&]+/,
135
+ $._attribute_ampersand,
136
+ ),
137
+ repeat(choice(
138
+ alias($._attribute_entity, $.entity),
139
+ $._unquoted_attribute_fragment,
140
+ $._attribute_ampersand,
141
+ )),
142
+ ),
128
143
 
129
- entity: _ => token(/&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?/),
144
+ entity: _ => token(/&(#([xX][0-9a-fA-F]+|[0-9]+)|[A-Za-z][A-Za-z0-9]*);?/),
130
145
 
131
146
  quoted_attribute_value: $ => choice(
132
- seq('\'', optional(alias(/[^']+/, $.attribute_value)), '\''),
133
- seq('"', optional(alias(/[^"]+/, $.attribute_value)), '"'),
147
+ seq('\'', optional(alias(repeat1(choice(
148
+ alias($._attribute_entity, $.entity),
149
+ token.immediate(/[^'&]+/),
150
+ $._attribute_ampersand,
151
+ )), $.attribute_value)), '\''),
152
+ seq('"', optional(alias(repeat1(choice(
153
+ alias($._attribute_entity, $.entity),
154
+ token.immediate(/[^"&]+/),
155
+ $._attribute_ampersand,
156
+ )), $.attribute_value)), '"'),
134
157
  ),
135
158
 
136
159
  text: _ => token.immediate(/[^<&]+|&/),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-html",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "HTML grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -22,6 +22,21 @@
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,
@@ -36,6 +51,10 @@
36
51
  "multiple": true,
37
52
  "required": false,
38
53
  "types": [
54
+ {
55
+ "type": "comment",
56
+ "named": true
57
+ },
39
58
  {
40
59
  "type": "doctype",
41
60
  "named": true
@@ -75,6 +94,10 @@
75
94
  "multiple": true,
76
95
  "required": true,
77
96
  "types": [
97
+ {
98
+ "type": "comment",
99
+ "named": true
100
+ },
78
101
  {
79
102
  "type": "doctype",
80
103
  "named": true
@@ -283,14 +306,9 @@
283
306
  "type": "attribute_name",
284
307
  "named": true
285
308
  },
286
- {
287
- "type": "attribute_value",
288
- "named": true
289
- },
290
309
  {
291
310
  "type": "comment",
292
- "named": true,
293
- "extra": true
311
+ "named": true
294
312
  },
295
313
  {
296
314
  "type": "doctype",
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": "2.0.0",
23
+ "version": "3.0.0",
22
24
  "license": "MIT",
23
25
  "description": "HTML grammar for tree-sitter",
24
26
  "authors": [