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 +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 +14 -11
- package/package.json +16 -10
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ function transform(ast, rule) {
|
|
|
9
9
|
if (typeof n !== 'string') {
|
|
10
10
|
n.index = index; // critical array element index
|
|
11
11
|
}
|
|
12
|
-
return rule(n, next(n.children), index);
|
|
12
|
+
return rule(n, next(typeof n === 'string' ? undefined : n.children), index);
|
|
13
13
|
});
|
|
14
14
|
} else {
|
|
15
15
|
return rule(node, next(node.children), index);
|
|
@@ -40,6 +40,9 @@ function isSelfClose(tagName) {
|
|
|
40
40
|
return voidElementTags.indexOf(tagName.toLowerCase()) > -1;
|
|
41
41
|
}
|
|
42
42
|
function isPair(tagX, tagY) {
|
|
43
|
+
if (!tagX || tagY.type === 'string') {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
43
46
|
return tagX.name === tagY.name && tagX.type === 'start' && tagY.type === 'end';
|
|
44
47
|
}
|
|
45
48
|
var utils = {
|
|
@@ -190,7 +193,7 @@ function splitTokens(html) {
|
|
|
190
193
|
return tokens;
|
|
191
194
|
}
|
|
192
195
|
function tokenize(html) {
|
|
193
|
-
return splitTokens(html).map((s)=>s.replace(/^\n+$/g, '')).map((s)=>s.trim()).filter(Boolean).map(makeToken).filter(Boolean);
|
|
196
|
+
return splitTokens(html).map((s)=>s.replace(/^\n+$/g, '')).map((s)=>s.trim()).filter(Boolean).map(makeToken).filter((token)=>Boolean(token));
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
function isEmpty(stack) {
|
|
@@ -209,20 +212,20 @@ function filterProps(node) {
|
|
|
209
212
|
if (typeof node === 'string') {
|
|
210
213
|
return node;
|
|
211
214
|
}
|
|
212
|
-
return
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
[c]: node[c]
|
|
218
|
-
}), {});
|
|
215
|
+
return {
|
|
216
|
+
name: node.name,
|
|
217
|
+
children: node.children,
|
|
218
|
+
attributes: node.attributes
|
|
219
|
+
};
|
|
219
220
|
}
|
|
220
221
|
function parse(src) {
|
|
221
222
|
const tokens = tokenize(src);
|
|
222
223
|
const stack = [];
|
|
223
224
|
const tree = {
|
|
224
225
|
type: 'root',
|
|
225
|
-
children: []
|
|
226
|
+
children: [],
|
|
227
|
+
name: 'root',
|
|
228
|
+
attributes: {}
|
|
226
229
|
};
|
|
227
230
|
stack.push(tree);
|
|
228
231
|
while(!isEmpty(stack) && !isEmpty(tokens)){
|
|
@@ -245,7 +248,7 @@ function parse(src) {
|
|
|
245
248
|
const node = stack.pop();
|
|
246
249
|
appendChild(getTop(stack), node);
|
|
247
250
|
}
|
|
248
|
-
return tree.children;
|
|
251
|
+
return tree.children || [];
|
|
249
252
|
}
|
|
250
253
|
|
|
251
254
|
function html2any(html, rule) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html2any",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "understand html with flexible transform",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html",
|
|
@@ -15,12 +15,18 @@
|
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "
|
|
18
|
+
"url": "https://github.com/huozhi/html2any"
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
|
21
21
|
"main": "dist/index.js",
|
|
22
|
+
"bin": {
|
|
23
|
+
"html2any": "dist/bin/html2any.js",
|
|
24
|
+
"html2": "dist/bin/html2.js"
|
|
25
|
+
},
|
|
22
26
|
"scripts": {
|
|
23
27
|
"test": "bun test",
|
|
28
|
+
"typecheck": "tsgo --noEmit",
|
|
29
|
+
"benchmark": "bun benchmark/run.mjs",
|
|
24
30
|
"build": "bunchee",
|
|
25
31
|
"prepublishOnly": "bun run build",
|
|
26
32
|
"web:dev": "next dev web",
|
|
@@ -29,22 +35,22 @@
|
|
|
29
35
|
"web:start": "next start web"
|
|
30
36
|
},
|
|
31
37
|
"files": [
|
|
32
|
-
"*.md",
|
|
33
38
|
"dist"
|
|
34
39
|
],
|
|
35
40
|
"author": "huozhi",
|
|
36
41
|
"license": "MIT",
|
|
37
42
|
"devDependencies": {
|
|
43
|
+
"@tailwindcss/postcss": "^4.3.0",
|
|
44
|
+
"@types/bun": "^1.3.14",
|
|
45
|
+
"@types/node": "^25.9.1",
|
|
46
|
+
"@types/react": "^19.2.15",
|
|
47
|
+
"@types/react-dom": "^19.2.3",
|
|
48
|
+
"@typescript/native-preview": "^7.0.0-dev.20260523.1",
|
|
38
49
|
"bunchee": "^6.10.0",
|
|
39
|
-
"react": "^19.2.6",
|
|
40
50
|
"next": "^16.2.6",
|
|
51
|
+
"react": "^19.2.6",
|
|
41
52
|
"react-dom": "^19.2.6",
|
|
42
|
-
"tailwindcss": "^4.3.0",
|
|
43
|
-
"@tailwindcss/postcss": "^4.3.0",
|
|
44
53
|
"sugar-high": "^1.2.0",
|
|
45
|
-
"
|
|
46
|
-
"@types/node": "^25.9.1",
|
|
47
|
-
"@types/react": "^19.2.15",
|
|
48
|
-
"@types/react-dom": "^19.2.3"
|
|
54
|
+
"tailwindcss": "^4.3.0"
|
|
49
55
|
}
|
|
50
56
|
}
|