html2any 0.1.1 → 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 CHANGED
@@ -2,27 +2,29 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/html2any.svg)](https://badge.fury.io/js/html2any)
4
4
 
5
- > A non-dependecy package for coverting html/xml string to your customized format/structures.
5
+ > Compile messy HTML into compact context for AI agents.
6
6
 
7
- While building websites, people may met issues for rendering rich text into different formats.
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
- Now `html2any` help you to render html string. It not only parses your html but also gives you ability to transform it from origin to the dest.
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 provide following APIs
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 the AST from source to AST from source html/xml code
24
+ > Build an AST from HTML/XML source.
23
25
 
24
26
  - transform
25
- > Convert the AST to the final form with the specific rule.
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
- ### How It Works
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
- Use `html2any` to construct an AST of html string, then convert each node recursively with `rule` passed to transform function.
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
- For example, we translate `<p>` tag into React Native component `<Text style={styles.paragraph}>` with the prepared styles. Then decode the p tag' s content to avoid html entities mess up.
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.