@verbaly/compiler 0.51.0 → 0.52.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 +3 -1
- package/dist/cli.js +37 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.js +37 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2188,6 +2188,10 @@ function renderHtml(html, options) {
|
|
|
2188
2188
|
if (tagName === "a" || tagName === "area") {
|
|
2189
2189
|
const inside = mirroredHref(attrs.get("href"), mirror);
|
|
2190
2190
|
if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, "href", inside);
|
|
2191
|
+
} else if (tagName === "form" || tagName === "button" || tagName === "input") {
|
|
2192
|
+
const name = tagName === "form" ? "action" : "formaction";
|
|
2193
|
+
const inside = mirroredHref(attrs.get(name), mirror);
|
|
2194
|
+
if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, name, inside);
|
|
2191
2195
|
} else if (tagName === "meta" && attrs.get("http-equiv")?.toLowerCase() === "refresh") {
|
|
2192
2196
|
const content = attrs.get("content") ?? "";
|
|
2193
2197
|
const url = /^([^;]*;\s*url\s*=\s*)(.*)$/i.exec(decodeEntities(content));
|
|
@@ -2207,11 +2211,17 @@ function renderHtml(html, options) {
|
|
|
2207
2211
|
if (close) {
|
|
2208
2212
|
const text = t(key, args);
|
|
2209
2213
|
const own = parseArgs(attrs.get(linksAttr));
|
|
2210
|
-
const
|
|
2214
|
+
const merged = own ? globalLinks ? {
|
|
2211
2215
|
...globalLinks,
|
|
2212
2216
|
...own
|
|
2213
2217
|
} : own : globalLinks;
|
|
2214
|
-
const
|
|
2218
|
+
const links = mirror ? mirroredLinks(merged, mirror) : merged;
|
|
2219
|
+
const nodes = attrs.has(richAttr) ? parseTags(text) : [];
|
|
2220
|
+
if (mirror && links) {
|
|
2221
|
+
const carried = usedLinks(nodes, links);
|
|
2222
|
+
if (carried && JSON.stringify(carried) !== JSON.stringify(own)) setAttribute(ms, html, chunkStart, openEnd, attrChunk, linksAttr, JSON.stringify(carried));
|
|
2223
|
+
}
|
|
2224
|
+
const content = attrs.has(richAttr) ? richToHtml(nodes, richTags, links) : escapeHtml(text);
|
|
2215
2225
|
if (html.slice(openEnd, close.contentEnd) !== content) {
|
|
2216
2226
|
if (openEnd === close.contentEnd) ms.appendLeft(openEnd, content);
|
|
2217
2227
|
else ms.overwrite(openEnd, close.contentEnd, content);
|
|
@@ -2258,6 +2268,31 @@ function publicPath(rel) {
|
|
|
2258
2268
|
const path = `/${rel.replace(/(^|\/)index\.html$/, "$1")}`;
|
|
2259
2269
|
return path.length > 1 ? path.replace(/\/+$/, "") : path;
|
|
2260
2270
|
}
|
|
2271
|
+
function usedLinks(nodes, links) {
|
|
2272
|
+
const out = {};
|
|
2273
|
+
const walk = (list) => {
|
|
2274
|
+
for (const node of list) {
|
|
2275
|
+
if (typeof node === "string") continue;
|
|
2276
|
+
if (links[node.name] !== void 0) out[node.name] = links[node.name];
|
|
2277
|
+
walk(node.children);
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
walk(nodes);
|
|
2281
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
2282
|
+
}
|
|
2283
|
+
function mirroredLinks(links, mirror) {
|
|
2284
|
+
if (!links) return links;
|
|
2285
|
+
const out = {};
|
|
2286
|
+
for (const [name, link] of Object.entries(links)) {
|
|
2287
|
+
const inside = mirroredHref(typeof link === "string" ? link : link.href, mirror);
|
|
2288
|
+
if (inside === void 0) out[name] = link;
|
|
2289
|
+
else out[name] = typeof link === "string" ? inside : {
|
|
2290
|
+
...link,
|
|
2291
|
+
href: inside
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
return out;
|
|
2295
|
+
}
|
|
2261
2296
|
function mirroredHref(raw, mirror) {
|
|
2262
2297
|
if (raw === void 0) return void 0;
|
|
2263
2298
|
const href = decodeEntities(raw);
|