@aljazmc/syntax 0.4.0 → 0.6.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 +36 -1
- package/bin/index.js +3511 -1585
- package/bin/types/css/ast.d.ts +231 -0
- package/bin/types/css/parser.d.ts +10 -0
- package/bin/types/css/tokens.d.ts +27 -0
- package/bin/types/html/ast.d.ts +85 -0
- package/bin/types/html/parser.d.ts +12 -0
- package/bin/types/html/tags.d.ts +2 -0
- package/bin/types/index.d.ts +21 -0
- package/package.json +3 -3
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
|
|
4
|
+
TypeScript, JSX, JSON, Markdown, HTML and CSS, bundled into `@aljazmc/formatero` and `@aljazmc/lintero`, and published for their
|
|
5
5
|
types.
|
|
6
6
|
|
|
7
7
|
```ts
|
|
@@ -31,3 +31,38 @@ 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.
|
|
51
|
+
|
|
52
|
+
CSS is parsed into rules, at-rules, declarations and their component
|
|
53
|
+
values, and the selectors of rules into compound selectors, combinators
|
|
54
|
+
and simple selectors, like Biome reads them:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { isCss, parseCss } from "@aljazmc/syntax";
|
|
58
|
+
|
|
59
|
+
isCss("styles.css"); // true
|
|
60
|
+
const sheet = parseCss("a > .b:hover { color: red !important; }\n");
|
|
61
|
+
// sheet.children: a Rule, its selectors and a block with a Declaration
|
|
62
|
+
// sheet.comments: every /* */ comment
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Nested rules, `@media` queries and other at-rule preludes keep their
|
|
66
|
+
values, keyframes keep theirs instead of selectors. Errors throw a
|
|
67
|
+
`ParseError`, or with `parseCss(source, { recover: true })` the items
|
|
68
|
+
with errors are skipped and listed in `sheet.errors`.
|