@aljazmc/syntax 0.4.0 → 0.5.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
@@ -1,7 +1,7 @@
1
1
  # > syntax
2
2
 
3
3
  Shared, dependency-free scanner and recursive descent parser for JavaScript,
4
- TypeScript, JSX, JSON and Markdown, bundled into `@aljazmc/formatero` and `@aljazmc/lintero`, and published for their
4
+ TypeScript, JSX, JSON, Markdown and HTML, bundled into `@aljazmc/formatero` and `@aljazmc/lintero`, and published for their
5
5
  types.
6
6
 
7
7
  ```ts
@@ -31,3 +31,20 @@ const root = parseMarkdown("# Title\n\n- [x] done\n");
31
31
  Blocks have offsets into the source and 1-based lines, and keep what a
32
32
  formatter needs to print them as written, like the indentation of each
33
33
  line. Inlines have offsets into the text of their block.
34
+
35
+ HTML is parsed like Biome parses it: elements must be closed, only void
36
+ elements may have no closing tag, and whitespace and comments are trivia
37
+ between nodes, not children:
38
+
39
+ ```ts
40
+ import { isHtml, parseHtml } from "@aljazmc/syntax";
41
+
42
+ isHtml("index.html"); // true
43
+ const root = parseHtml('<p class="a">Hi <b>there</b></p>\n');
44
+ // root.children: an Element p, with its attributes, a Text and an Element b
45
+ // root.comments: every <!-- --> comment
46
+ ```
47
+
48
+ Element names keep their case, and `tag` is the known tag they match, like
49
+ `div` for `DIV` and `feBlend` for `feBlend`. Scripts, styles and
50
+ preformatted elements keep their content as one raw text.