@willbooster/tree-sitter-html 10.0.0 → 12.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 +19 -17
- package/package.json +7 -8
- package/tree-sitter-html.wasm +0 -0
- package/tree-sitter.json +1 -3
- package/queries/highlights.scm +0 -17
- package/queries/injections.scm +0 -7
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
|
|
@@ -14,14 +14,14 @@ 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 `
|
|
17
|
+
number `0x5742000b`, so it loads with the WillBooster runtime, version 15.0.0 or later in the 15.x series
|
|
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
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. Processing instructions use source-preserving
|
|
24
|
-
`processing_instruction` nodes
|
|
24
|
+
`processing_instruction` nodes. Delimited `xml` and `xml-stylesheet` targets in any ASCII
|
|
25
25
|
case, including XML declarations, and malformed targets produce `comment` nodes. Valid targets start with an ASCII
|
|
26
26
|
letter or `_` and continue with ASCII letters, digits, `-` or `_`. A valid-target instruction without a closing `>`
|
|
27
27
|
reports an error. In HTML-namespace `title` and `textarea`, tags, comments,
|
|
@@ -36,11 +36,11 @@ name boundary instead of the HTML tokenizer's replacement-character behavior.
|
|
|
36
36
|
In the HTML namespace, a trailing
|
|
37
37
|
slash on a `script` or `style` opening tag remains part of its `start_tag`; it does not close the element, so subsequent
|
|
38
38
|
content remains raw text until the matching end tag. Self-closing foreign-namespace `script` and `style` use ordinary element nodes. Complete foreign
|
|
39
|
-
elements retain raw-text nodes
|
|
39
|
+
elements retain raw-text nodes, including CDATA delimiters. MathML `annotation-xml` with an `encoding` value of `text/html` or `application/xhtml+xml`
|
|
40
40
|
uses HTML parsing for its children. Encoding comparisons ignore ASCII case and decode character references. Script content follows
|
|
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
|
-
remaining content stays
|
|
43
|
+
remaining content stays in its `raw_text` node. Incomplete closing tags such as `</script` still report
|
|
44
44
|
recovery errors. Unterminated style elements still report an error. HTML-namespace void elements such as `<input>` and
|
|
45
45
|
`<br/>` use `void_element` nodes with direct `tag_name` and `attribute` children. Following text, entities, comments,
|
|
46
46
|
and processing instructions are siblings, and explicit void-element end tags are `erroneous_end_tag` siblings.
|
|
@@ -58,18 +58,24 @@ Attribute values use distinct `unquoted_attribute_value`, `singlequoted_attribut
|
|
|
58
58
|
`doublequoted_attribute_value` nodes directly inside `attribute`. Quoted nodes include both delimiters and retain an
|
|
59
59
|
`attribute_value` child for nonempty content; empty quoted values have no content child. Unquoted nodes cover the value
|
|
60
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.
|
|
62
|
-
|
|
63
|
-
reference spellings as well. The highlight query captures those same content nodes, excluding quote delimiters.
|
|
61
|
+
node. Other content, including literal ampersands, has no child nodes. The quote-free content of a value is its
|
|
62
|
+
`attribute_value` or `unquoted_attribute_value` node.
|
|
64
63
|
Legacy names without a semicolon remain literal before an ASCII letter, digit, or `=`; unknown names and incomplete
|
|
65
64
|
numeric prefixes remain literal. Comments are document or element content and are not accepted between attributes.
|
|
66
65
|
Comment-shaped text inside a quoted value remains part of that value. Whitespace after `=` separates the operator from
|
|
67
66
|
the value, so `noval= bool` remains one attribute with the unquoted value `bool`.
|
|
68
67
|
|
|
68
|
+
## Support Scope
|
|
69
|
+
|
|
70
|
+
This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
|
|
71
|
+
nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
|
|
72
|
+
but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
|
|
73
|
+
the trees that error recovery produces may change; such changes are released as new major versions.
|
|
74
|
+
|
|
69
75
|
## Usage
|
|
70
76
|
|
|
71
77
|
The npm package ships `tree-sitter-html.wasm` for
|
|
72
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
78
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 15.0.0 or later in the 15.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers.
|
|
73
79
|
In Node.js and Bun, load the grammar from its path:
|
|
74
80
|
|
|
75
81
|
```js
|
|
@@ -109,7 +115,7 @@ const parser = new Parser();
|
|
|
109
115
|
parser.setLanguage(await Language.load(html));
|
|
110
116
|
```
|
|
111
117
|
|
|
112
|
-
The package also ships `grammar.js
|
|
118
|
+
The package also ships `grammar.js` and the node types in `src/node-types.json`.
|
|
113
119
|
|
|
114
120
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-html) and on
|
|
115
121
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
|
|
@@ -117,8 +123,8 @@ fuzzed with:
|
|
|
117
123
|
|
|
118
124
|
```toml
|
|
119
125
|
[dependencies]
|
|
120
|
-
tree-sitter = { package = "willbooster-tree-sitter", version = "
|
|
121
|
-
tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "
|
|
126
|
+
tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
|
|
127
|
+
tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "12" }
|
|
122
128
|
```
|
|
123
129
|
|
|
124
130
|
```rust
|
|
@@ -154,9 +160,6 @@ and the release build regenerate the parsers before compiling them.
|
|
|
154
160
|
`bun run test` runs:
|
|
155
161
|
|
|
156
162
|
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
157
|
-
- an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
|
|
158
|
-
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
159
|
-
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
|
|
160
163
|
- a check that the real-world HTML files in `examples/`, the checked-in ones and those of the cloned repositories, fail
|
|
161
164
|
to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example repositories are pinned to commits in
|
|
162
165
|
`script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites it;
|
|
@@ -171,8 +174,7 @@ and the release build regenerate the parsers before compiling them.
|
|
|
171
174
|
Cloudflare Workers with and without Node.js compatibility (`test/e2e/workers.test.ts`).
|
|
172
175
|
|
|
173
176
|
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
174
|
-
by every checkout
|
|
175
|
-
afterwards.
|
|
177
|
+
by every checkout.
|
|
176
178
|
|
|
177
179
|
CI also runs these tests on Linux arm64 and macOS, where the CLI compiles the parser and the scanner natively, and fuzzes
|
|
178
180
|
both with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-html",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "HTML grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"grammar.js",
|
|
19
|
-
"queries/*.scm",
|
|
20
19
|
"src/node-types.json",
|
|
21
20
|
"tree-sitter.json",
|
|
22
21
|
"*.wasm"
|
|
@@ -46,22 +45,22 @@
|
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@tsconfig/bun": "1.0.11",
|
|
49
|
-
"@types/bun": "1.4.
|
|
48
|
+
"@types/bun": "1.4.4",
|
|
50
49
|
"@vitest/browser-playwright": "5.0.5",
|
|
51
50
|
"@willbooster/oxlint-config": "1.4.9",
|
|
52
|
-
"@willbooster/wb": "
|
|
53
|
-
"@willbooster/web-tree-sitter": "
|
|
51
|
+
"@willbooster/wb": "23.0.0",
|
|
52
|
+
"@willbooster/web-tree-sitter": "15.5.4",
|
|
54
53
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
55
54
|
"lefthook": "2.2.2",
|
|
56
|
-
"oxlint": "1.
|
|
57
|
-
"oxlint-tsgolint": "7.0.
|
|
55
|
+
"oxlint": "1.89.0",
|
|
56
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
58
57
|
"playwright": "1.64.1",
|
|
59
58
|
"semantic-release": "25.0.9",
|
|
60
59
|
"vitest": "5.0.5",
|
|
61
60
|
"wrangler": "4.151.1"
|
|
62
61
|
},
|
|
63
62
|
"peerDependencies": {
|
|
64
|
-
"@willbooster/web-tree-sitter": "^
|
|
63
|
+
"@willbooster/web-tree-sitter": "^15.0.0"
|
|
65
64
|
},
|
|
66
65
|
"peerDependenciesMeta": {
|
|
67
66
|
"@willbooster/web-tree-sitter": {
|
package/tree-sitter-html.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -14,13 +14,11 @@
|
|
|
14
14
|
"file-types": [
|
|
15
15
|
"html"
|
|
16
16
|
],
|
|
17
|
-
"highlights": "queries/highlights.scm",
|
|
18
|
-
"injections": "queries/injections.scm",
|
|
19
17
|
"injection-regex": "html"
|
|
20
18
|
}
|
|
21
19
|
],
|
|
22
20
|
"metadata": {
|
|
23
|
-
"version": "
|
|
21
|
+
"version": "12.0.0",
|
|
24
22
|
"license": "MIT",
|
|
25
23
|
"description": "HTML grammar for tree-sitter",
|
|
26
24
|
"authors": [
|
package/queries/highlights.scm
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
(tag_name) @tag
|
|
2
|
-
(erroneous_end_tag_name) @tag.error
|
|
3
|
-
(doctype) @constant
|
|
4
|
-
(processing_instruction) @keyword.directive
|
|
5
|
-
(attribute_name) @attribute
|
|
6
|
-
[
|
|
7
|
-
(attribute_value)
|
|
8
|
-
(unquoted_attribute_value)
|
|
9
|
-
] @string
|
|
10
|
-
(comment) @comment
|
|
11
|
-
|
|
12
|
-
[
|
|
13
|
-
"<"
|
|
14
|
-
">"
|
|
15
|
-
"</"
|
|
16
|
-
"/>"
|
|
17
|
-
] @punctuation.bracket
|