html2any 0.0.7 → 0.2.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 +32 -9
- package/dist/_cli.cjs +852 -0
- package/dist/_cli.d.cts +1 -0
- package/dist/_cli.d.ts +1 -0
- package/dist/_cli.js +848 -0
- package/dist/bin/html2.js +2 -0
- package/dist/bin/html2any.js +2 -0
- package/dist/index.js +258 -0
- package/package.json +44 -18
- package/lib/index.js +0 -198
- package/lib/index.js.map +0 -1
- package/lib/index.mjs +0 -196
- package/lib/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -2,27 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/html2any)
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> Compile messy HTML into compact context for AI agents.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Library
|
|
8
|
+
|
|
9
|
+
While building websites, people may need to render rich text into different formats.
|
|
8
10
|
For example, I've got an `<video>` tag, but I wanna render it with my own React video component.
|
|
9
11
|
But I also want to render the whole html easily rather than parse it manually.
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
`html2any` helps you render an HTML string. It parses HTML and gives you the ability to transform it from the source format into your target format.
|
|
12
14
|
|
|
13
15
|
### API
|
|
14
16
|
|
|
15
|
-
html2any
|
|
17
|
+
html2any provides the following APIs:
|
|
16
18
|
|
|
17
19
|
- `AST(Object) parse(String source)`
|
|
18
20
|
- `void transform(AST ast, function rule)`
|
|
19
21
|
- `void html2any(html, function rule)`
|
|
20
22
|
|
|
21
23
|
- parse
|
|
22
|
-
> Build
|
|
24
|
+
> Build an AST from HTML/XML source.
|
|
23
25
|
|
|
24
26
|
- transform
|
|
25
|
-
> Convert the AST to
|
|
27
|
+
> Convert the AST to a final form with a custom rule.
|
|
26
28
|
|
|
27
29
|
- html2any
|
|
28
30
|
> Convert the html/xml to the final form directly.
|
|
@@ -60,9 +62,30 @@ Or you can just call html2any directly
|
|
|
60
62
|
const vdom = html2any(html, rule)
|
|
61
63
|
```
|
|
62
64
|
|
|
63
|
-
###
|
|
65
|
+
### CLI
|
|
66
|
+
|
|
67
|
+
Convert a local file, URL, or stdin into compact Markdown:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
html2any md <file|url|->
|
|
71
|
+
|
|
72
|
+
# Short alias
|
|
73
|
+
html2 md <file|url|->
|
|
74
|
+
```
|
|
64
75
|
|
|
65
|
-
|
|
76
|
+
Examples:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
html2 md page.html > page.context.md
|
|
80
|
+
cat page.html | html2 md - --url https://example.com/page
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The Markdown output keeps docs-friendly structure: title, description, headings, paragraphs, lists, tables, code blocks, and links.
|
|
84
|
+
|
|
85
|
+
The extractor is deterministic and token-size friendly. It drops scripts, styles, hidden content, and layout chrome while preserving semantically useful docs content.
|
|
86
|
+
|
|
87
|
+
### How It Works
|
|
66
88
|
|
|
67
|
-
|
|
89
|
+
Use `html2any` to construct an AST from an HTML string, then convert each node recursively with the `rule` passed to the transform function.
|
|
68
90
|
|
|
91
|
+
For example, translate a `<p>` tag into a React Native component like `<Text style={styles.paragraph}>` with prepared styles, then decode the paragraph content to avoid HTML entity issues.
|