@willbooster/tree-sitter-html 1.0.5 → 2.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,15 +14,19 @@ 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
17
+ number, so it loads only with the WillBooster runtime, version 2.0.0 or later in the 2.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
- surrounding text, while character references remain `entity` nodes. Its scanner requires an HTML tag-name boundary after
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. Its 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
- fold only ASCII letters, and embedded NUL characters remain part of raw-text content. Void elements close
25
+ fold only ASCII letters, and embedded NUL characters remain part of raw-text content. Script content follows
26
+ HTML escaped and double-escaped states, so closing-tag text inside a double escape remains raw text. A script that reaches
27
+ EOF while scanning raw content closes implicitly without an error: its `script_element` has no `end_tag` child, and its
28
+ remaining content stays available for JavaScript injection. Incomplete closing tags such as `</script` still report
29
+ recovery errors. Unterminated style elements still report an error. Void elements close
26
30
  before following text, entities, and complete comments, which become siblings instead of children.
27
31
  Scanner serialization stores the open-tag stack from its innermost tag, compressing runs of identical tags, so active
28
32
  void, script, and style elements retain their identities when deeply nested. When deep nesting of distinct tags
@@ -33,7 +37,7 @@ Malformed input after a void element can replace its enclosing element with an `
33
37
  ## Usage
34
38
 
35
39
  The npm package ships `tree-sitter-html.wasm` for
36
- [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 2.0.0 or later, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
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:
37
41
 
38
42
  ```js
39
43
  import { fileURLToPath } from 'node:url';
@@ -80,7 +84,7 @@ fuzzed with:
80
84
  ```toml
81
85
  [dependencies]
82
86
  tree-sitter = { package = "willbooster-tree-sitter", version = "2.0.0" }
83
- tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "1" }
87
+ tree-sitter-html = { package = "willbooster-tree-sitter-html", version = "2" }
84
88
  ```
85
89
 
86
90
  ```rust
package/grammar.js CHANGED
@@ -62,7 +62,7 @@ module.exports = grammar({
62
62
  script_element: $ => seq(
63
63
  alias($.script_start_tag, $.start_tag),
64
64
  optional($.raw_text),
65
- $.end_tag,
65
+ choice($.end_tag, $._implicit_end_tag),
66
66
  ),
67
67
 
68
68
  style_element: $ => seq(
@@ -126,14 +126,13 @@ module.exports = grammar({
126
126
 
127
127
  attribute_value: _ => /[^<>"'=\s]+/,
128
128
 
129
- // HTML fixes the named-reference set: https://html.spec.whatwg.org/multipage/named-characters.html
130
- entity: _ => /&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?/,
129
+ entity: _ => token(/&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?/),
131
130
 
132
131
  quoted_attribute_value: $ => choice(
133
132
  seq('\'', optional(alias(/[^']+/, $.attribute_value)), '\''),
134
133
  seq('"', optional(alias(/[^"]+/, $.attribute_value)), '"'),
135
134
  ),
136
135
 
137
- text: _ => /[^<&\s]([^<&]*[^<&\s])?|&/,
136
+ text: _ => token.immediate(/[^<&]+|&/),
138
137
  },
139
138
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-html",
3
- "version": "1.0.5",
3
+ "version": "2.0.0",
4
4
  "description": "HTML grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -18,7 +18,7 @@
18
18
  }
19
19
  ],
20
20
  "metadata": {
21
- "version": "1.0.5",
21
+ "version": "2.0.0",
22
22
  "license": "MIT",
23
23
  "description": "HTML grammar for tree-sitter",
24
24
  "authors": [