@thi.ng/hiccup-html-parse 0.3.41 → 0.3.43
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/CHANGELOG.md +7 -1
- package/README.md +1 -1
- package/index.js +16 -28
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [0.3.43](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-html-parse@0.3.43) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
### [0.3.5](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-html-parse@0.3.5) (2023-11-09)
|
|
13
19
|
|
|
14
20
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
package/index.js
CHANGED
|
@@ -34,8 +34,7 @@ const parseRaw = (src, opts) => {
|
|
|
34
34
|
return { result: lang.rules.main(ctx), ctx };
|
|
35
35
|
};
|
|
36
36
|
const parseHtml = (src, opts) => {
|
|
37
|
-
if (!src)
|
|
38
|
-
return { type: "success", result: [] };
|
|
37
|
+
if (!src) return { type: "success", result: [] };
|
|
39
38
|
opts = {
|
|
40
39
|
debug: false,
|
|
41
40
|
collapse: true,
|
|
@@ -55,7 +54,7 @@ const parseHtml = (src, opts) => {
|
|
|
55
54
|
};
|
|
56
55
|
if (result) {
|
|
57
56
|
const acc = [];
|
|
58
|
-
|
|
57
|
+
__transformScope(ctx.root, opts, acc);
|
|
59
58
|
return {
|
|
60
59
|
type: ctx.done ? "success" : "partial",
|
|
61
60
|
result: acc,
|
|
@@ -68,7 +67,7 @@ const parseHtml = (src, opts) => {
|
|
|
68
67
|
return { type: "error", err: e };
|
|
69
68
|
}
|
|
70
69
|
};
|
|
71
|
-
const
|
|
70
|
+
const __transformScope = defmulti(
|
|
72
71
|
(x) => x.id,
|
|
73
72
|
{ cdata_el: "el", void_el: "el" },
|
|
74
73
|
{
|
|
@@ -77,28 +76,25 @@ const transformScope = defmulti(
|
|
|
77
76
|
},
|
|
78
77
|
// root node of the parse tree
|
|
79
78
|
root: ({ children }, opts, acc) => {
|
|
80
|
-
if (!children)
|
|
81
|
-
return;
|
|
79
|
+
if (!children) return;
|
|
82
80
|
children = children[0].children;
|
|
83
81
|
if (opts.doctype && children?.[0]) {
|
|
84
82
|
acc.push(["!DOCTYPE", children[0].result]);
|
|
85
83
|
}
|
|
86
84
|
for (let x of children[1].children)
|
|
87
|
-
|
|
85
|
+
__transformScope(x, opts, acc);
|
|
88
86
|
},
|
|
89
87
|
node: ({ children }, opts, acc) => {
|
|
90
|
-
|
|
88
|
+
__transformScope(children[0], opts, acc);
|
|
91
89
|
},
|
|
92
90
|
comment: ({ result }, opts, acc) => {
|
|
93
|
-
if (opts.comments)
|
|
94
|
-
acc.push(["__COMMENT__", result.trim()]);
|
|
91
|
+
if (opts.comments) acc.push(["__COMMENT__", result.trim()]);
|
|
95
92
|
},
|
|
96
93
|
// element node transformer, collects & filters attributes/children
|
|
97
94
|
// adds resulting hiccup element to accumulator array
|
|
98
95
|
el: ({ children }, opts, acc) => {
|
|
99
96
|
const [name, { children: $attribs }, body] = children;
|
|
100
|
-
if (opts.ignoreElements?.includes(name.result))
|
|
101
|
-
return;
|
|
97
|
+
if (opts.ignoreElements?.includes(name.result)) return;
|
|
102
98
|
const attribs = {};
|
|
103
99
|
const el = [name.result, attribs];
|
|
104
100
|
if ($attribs) {
|
|
@@ -106,12 +102,10 @@ const transformScope = defmulti(
|
|
|
106
102
|
const name2 = a.children[0].result;
|
|
107
103
|
if (opts.dataAttribs === false && name2.startsWith("data-"))
|
|
108
104
|
continue;
|
|
109
|
-
if (opts.ignoreAttribs?.includes(name2))
|
|
110
|
-
continue;
|
|
105
|
+
if (opts.ignoreAttribs?.includes(name2)) continue;
|
|
111
106
|
if (a.children[1].children) {
|
|
112
107
|
const val = a.children[1].children[0].result;
|
|
113
|
-
if (val != null)
|
|
114
|
-
attribs[name2] = unescapeEntities(val);
|
|
108
|
+
if (val != null) attribs[name2] = unescapeEntities(val);
|
|
115
109
|
} else {
|
|
116
110
|
attribs[name2] = true;
|
|
117
111
|
}
|
|
@@ -121,25 +115,19 @@ const transformScope = defmulti(
|
|
|
121
115
|
if (body.result) {
|
|
122
116
|
el.push(body.result.trim());
|
|
123
117
|
} else if (body.children) {
|
|
124
|
-
for (let x of body.children)
|
|
125
|
-
transformScope(x, opts, el);
|
|
118
|
+
for (let x of body.children) __transformScope(x, opts, el);
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
121
|
const result = opts.tx ? opts.tx(el) : el;
|
|
129
|
-
if (result != null)
|
|
130
|
-
acc.push(result);
|
|
122
|
+
if (result != null) acc.push(result);
|
|
131
123
|
},
|
|
132
124
|
// plain text transform (by default only resolves HTML entities)
|
|
133
125
|
body: ({ result }, opts, acc) => {
|
|
134
|
-
if (!opts.whitespace && /^\s+$/.test(result))
|
|
135
|
-
|
|
136
|
-
if (opts.
|
|
137
|
-
result = result.replace(/\s+/gm, " ");
|
|
138
|
-
if (opts.unescape)
|
|
139
|
-
result = unescapeEntities(result);
|
|
126
|
+
if (!opts.whitespace && /^\s+$/.test(result)) return;
|
|
127
|
+
if (opts.collapse) result = result.replace(/\s+/gm, " ");
|
|
128
|
+
if (opts.unescape) result = unescapeEntities(result);
|
|
140
129
|
result = opts.txBody ? opts.txBody(result) : result;
|
|
141
|
-
if (result != null)
|
|
142
|
-
acc.push(result);
|
|
130
|
+
if (result != null) acc.push(result);
|
|
143
131
|
}
|
|
144
132
|
}
|
|
145
133
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup-html-parse",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.43",
|
|
4
4
|
"description": "Well-formed HTML parsing and customizable transformation to nested JS arrays in @thi.ng/hiccup format",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/hiccup-html-parse",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/defmulti": "^3.0.
|
|
41
|
-
"@thi.ng/parse": "^2.4.
|
|
42
|
-
"@thi.ng/strings": "^3.7.
|
|
39
|
+
"@thi.ng/api": "^8.11.3",
|
|
40
|
+
"@thi.ng/defmulti": "^3.0.40",
|
|
41
|
+
"@thi.ng/parse": "^2.4.43",
|
|
42
|
+
"@thi.ng/strings": "^3.7.34"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.
|
|
46
|
-
"esbuild": "^0.
|
|
47
|
-
"typedoc": "^0.25.
|
|
48
|
-
"typescript": "^5.
|
|
45
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
46
|
+
"esbuild": "^0.21.5",
|
|
47
|
+
"typedoc": "^0.25.13",
|
|
48
|
+
"typescript": "^5.5.2"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"ast",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"status": "alpha",
|
|
86
86
|
"year": 2023
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
89
89
|
}
|