webforai 2.1.1 → 4.0.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 +86 -4
- package/dist/adapters/index.js +58 -0
- package/dist/adapters/registry.js +149 -0
- package/dist/adapters/sites/declarative.js +178 -0
- package/dist/adapters/sites/hackernews.js +94 -0
- package/dist/adapters/sites/youtube.js +165 -0
- package/dist/adapters/types.js +0 -0
- package/dist/bin.js +4142 -549
- package/dist/cjs/adapters/index.js +86 -0
- package/dist/cjs/adapters/registry.js +178 -0
- package/dist/cjs/adapters/sites/declarative.js +202 -0
- package/dist/cjs/adapters/sites/hackernews.js +117 -0
- package/dist/cjs/adapters/sites/youtube.js +191 -0
- package/dist/cjs/adapters/types.js +16 -0
- package/dist/cjs/constants.js +2 -2
- package/dist/cjs/detect-client-shell.js +78 -0
- package/dist/cjs/extract-meta-refresh.js +71 -0
- package/dist/cjs/extractors/index.js +5 -0
- package/dist/cjs/extractors/lib/constants.js +186 -0
- package/dist/cjs/extractors/lib/sanitize.js +429 -0
- package/dist/cjs/extractors/lib/score.js +264 -0
- package/dist/cjs/extractors/lib/terminators.js +131 -0
- package/dist/cjs/extractors/lib/ui-chrome.js +119 -0
- package/dist/cjs/extractors/pipeExtractors.js +12 -9
- package/dist/cjs/extractors/presets/auto.js +44 -0
- package/dist/cjs/extractors/presets/minimal-filter.js +27 -48
- package/dist/cjs/extractors/presets/takumi.js +84 -122
- package/dist/cjs/html-to-markdown.js +44 -7
- package/dist/cjs/html-to-mdast.js +10 -1
- package/dist/cjs/index.js +43 -2
- package/dist/cjs/link-replacer.js +19 -13
- package/dist/cjs/loaders/cf-puppeteer.js +14 -7
- package/dist/cjs/loaders/fetch.js +14 -2
- package/dist/cjs/loaders/playwright.js +32 -30
- package/dist/cjs/loaders/puppeteer.js +14 -7
- package/dist/cjs/md-splitter.js +24 -11
- package/dist/cjs/mdast-handlers/custom-a-handler.js +25 -9
- package/dist/cjs/mdast-handlers/custom-code-handler.js +18 -7
- package/dist/cjs/mdast-handlers/custom-div-handler.js +12 -33
- package/dist/cjs/mdast-handlers/custom-img-handler.js +23 -1
- package/dist/cjs/mdast-handlers/custom-table-handler.js +16 -0
- package/dist/cjs/mdast-handlers/definition-list-handler.js +110 -0
- package/dist/cjs/mdast-handlers/math-handler.js +12 -3
- package/dist/cjs/mdast-handlers/sup-sub-handler.js +39 -0
- package/dist/cjs/mdast-to-markdown.js +2 -5
- package/dist/cjs/metadata/index.js +223 -0
- package/dist/cjs/normalize/index.js +177 -0
- package/dist/cjs/platform/client.js +204 -0
- package/dist/cjs/platform/error.js +36 -0
- package/dist/cjs/platform/fetch.js +37 -0
- package/dist/cjs/platform/index.js +44 -0
- package/dist/cjs/platform/types.js +40 -0
- package/dist/cjs/utils/hast-fast.js +284 -0
- package/dist/constants.js +2 -2
- package/dist/detect-client-shell.js +53 -0
- package/dist/extract-meta-refresh.js +47 -0
- package/dist/extractors/index.js +3 -0
- package/dist/extractors/lib/constants.js +150 -0
- package/dist/extractors/lib/sanitize.js +419 -0
- package/dist/extractors/lib/score.js +242 -0
- package/dist/extractors/lib/terminators.js +107 -0
- package/dist/extractors/lib/ui-chrome.js +96 -0
- package/dist/extractors/pipeExtractors.js +12 -9
- package/dist/extractors/presets/auto.js +20 -0
- package/dist/extractors/presets/minimal-filter.js +35 -47
- package/dist/extractors/presets/takumi.js +91 -122
- package/dist/html-to-markdown.js +42 -6
- package/dist/html-to-mdast.js +10 -1
- package/dist/index.js +45 -2
- package/dist/link-replacer.js +19 -13
- package/dist/loaders/cf-puppeteer.js +15 -8
- package/dist/loaders/fetch.js +14 -2
- package/dist/loaders/playwright.js +32 -30
- package/dist/loaders/puppeteer.js +15 -8
- package/dist/md-splitter.js +24 -11
- package/dist/mdast-handlers/custom-a-handler.js +25 -9
- package/dist/mdast-handlers/custom-code-handler.js +17 -7
- package/dist/mdast-handlers/custom-div-handler.js +12 -33
- package/dist/mdast-handlers/custom-img-handler.js +23 -1
- package/dist/mdast-handlers/custom-table-handler.js +16 -0
- package/dist/mdast-handlers/definition-list-handler.js +87 -0
- package/dist/mdast-handlers/math-handler.js +12 -3
- package/dist/mdast-handlers/sup-sub-handler.js +16 -0
- package/dist/mdast-to-markdown.js +2 -5
- package/dist/metadata/index.js +198 -0
- package/dist/normalize/index.js +159 -0
- package/dist/platform/client.js +182 -0
- package/dist/platform/error.js +13 -0
- package/dist/platform/fetch.js +14 -0
- package/dist/platform/index.js +23 -0
- package/dist/platform/types.js +13 -0
- package/dist/types/adapters/index.d.ts +24 -0
- package/dist/types/adapters/index.js.map +1 -0
- package/dist/types/adapters/registry.d.ts +35 -0
- package/dist/types/adapters/registry.js.map +1 -0
- package/dist/types/adapters/sites/declarative.d.ts +13 -0
- package/dist/types/adapters/sites/declarative.js.map +1 -0
- package/dist/types/adapters/sites/hackernews.d.ts +13 -0
- package/dist/types/adapters/sites/hackernews.js.map +1 -0
- package/dist/types/adapters/sites/youtube.d.ts +31 -0
- package/dist/types/adapters/sites/youtube.js.map +1 -0
- package/dist/types/adapters/types.d.ts +99 -0
- package/dist/types/adapters/types.js.map +1 -0
- package/dist/types/cli/bin.js.map +1 -1
- package/dist/types/cli/commands/jobs/files.d.ts +28 -0
- package/dist/types/cli/commands/jobs/files.js.map +1 -0
- package/dist/types/cli/commands/jobs/llms-txt.d.ts +33 -0
- package/dist/types/cli/commands/jobs/llms-txt.js.map +1 -0
- package/dist/types/cli/commands/jobs/options.d.ts +58 -0
- package/dist/types/cli/commands/jobs/options.js.map +1 -0
- package/dist/types/cli/commands/jobs/run.d.ts +44 -0
- package/dist/types/cli/commands/jobs/run.js.map +1 -0
- package/dist/types/cli/commands/skill/content.d.ts +9 -0
- package/dist/types/cli/commands/skill/content.js.map +1 -0
- package/dist/types/cli/commands/skill/index.d.ts +19 -0
- package/dist/types/cli/commands/skill/index.js.map +1 -0
- package/dist/types/cli/commands/webforai/interactive.d.ts +7 -0
- package/dist/types/cli/commands/webforai/interactive.js.map +1 -0
- package/dist/types/cli/commands/webforai/loadHtml.js.map +1 -1
- package/dist/types/cli/commands/webforai/options.d.ts +62 -0
- package/dist/types/cli/commands/webforai/options.js.map +1 -0
- package/dist/types/cli/commands/webforai/run.d.ts +10 -0
- package/dist/types/cli/commands/webforai/run.js.map +1 -0
- package/dist/types/cli/constants.d.ts +14 -4
- package/dist/types/cli/constants.js.map +1 -1
- package/dist/types/cli/helpers/selectExtractMode.js.map +1 -1
- package/dist/types/cli/helpers/selectLoader.js.map +1 -1
- package/dist/types/cli/utils.d.ts +8 -1
- package/dist/types/cli/utils.js.map +1 -1
- package/dist/types/constants.d.ts +7 -1
- package/dist/types/constants.js.map +1 -1
- package/dist/types/detect-client-shell.d.ts +24 -0
- package/dist/types/detect-client-shell.js.map +1 -0
- package/dist/types/extract-meta-refresh.d.ts +29 -0
- package/dist/types/extract-meta-refresh.js.map +1 -0
- package/dist/types/extractors/index.d.ts +1 -0
- package/dist/types/extractors/index.js.map +1 -1
- package/dist/types/extractors/lib/constants.d.ts +81 -0
- package/dist/types/extractors/lib/constants.js.map +1 -0
- package/dist/types/extractors/lib/sanitize.d.ts +66 -0
- package/dist/types/extractors/lib/sanitize.js.map +1 -0
- package/dist/types/extractors/lib/score.d.ts +85 -0
- package/dist/types/extractors/lib/score.js.map +1 -0
- package/dist/types/extractors/lib/terminators.d.ts +26 -0
- package/dist/types/extractors/lib/terminators.js.map +1 -0
- package/dist/types/extractors/lib/ui-chrome.d.ts +18 -0
- package/dist/types/extractors/lib/ui-chrome.js.map +1 -0
- package/dist/types/extractors/pipeExtractors.d.ts +5 -0
- package/dist/types/extractors/pipeExtractors.js.map +1 -1
- package/dist/types/extractors/presets/auto.d.ts +30 -0
- package/dist/types/extractors/presets/auto.js.map +1 -0
- package/dist/types/extractors/presets/minimal-filter.d.ts +10 -2
- package/dist/types/extractors/presets/minimal-filter.js.map +1 -1
- package/dist/types/extractors/presets/takumi.d.ts +19 -3
- package/dist/types/extractors/presets/takumi.js.map +1 -1
- package/dist/types/extractors/types.d.ts +8 -0
- package/dist/types/html-to-markdown.d.ts +38 -0
- package/dist/types/html-to-markdown.js.map +1 -1
- package/dist/types/html-to-mdast.d.ts +11 -0
- package/dist/types/html-to-mdast.js.map +1 -1
- package/dist/types/index.d.ts +8 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/link-replacer.d.ts +3 -1
- package/dist/types/link-replacer.js.map +1 -1
- package/dist/types/loaders/cf-puppeteer.js.map +1 -1
- package/dist/types/loaders/fetch.d.ts +4 -0
- package/dist/types/loaders/fetch.js.map +1 -1
- package/dist/types/loaders/playwright.js.map +1 -1
- package/dist/types/loaders/puppeteer.js.map +1 -1
- package/dist/types/md-splitter.d.ts +1 -1
- package/dist/types/md-splitter.js.map +1 -1
- package/dist/types/mdast-handlers/custom-a-handler.js.map +1 -1
- package/dist/types/mdast-handlers/custom-code-handler.d.ts +2 -0
- package/dist/types/mdast-handlers/custom-code-handler.js.map +1 -1
- package/dist/types/mdast-handlers/custom-div-handler.js.map +1 -1
- package/dist/types/mdast-handlers/custom-img-handler.js.map +1 -1
- package/dist/types/mdast-handlers/custom-table-handler.js.map +1 -1
- package/dist/types/mdast-handlers/definition-list-handler.d.ts +2 -0
- package/dist/types/mdast-handlers/definition-list-handler.js.map +1 -0
- package/dist/types/mdast-handlers/math-handler.js.map +1 -1
- package/dist/types/mdast-handlers/sup-sub-handler.d.ts +10 -0
- package/dist/types/mdast-handlers/sup-sub-handler.js.map +1 -0
- package/dist/types/mdast-to-markdown.js.map +1 -1
- package/dist/types/metadata/index.d.ts +47 -0
- package/dist/types/metadata/index.js.map +1 -0
- package/dist/types/normalize/index.d.ts +53 -0
- package/dist/types/normalize/index.js.map +1 -0
- package/dist/types/platform/client.d.ts +55 -0
- package/dist/types/platform/client.js.map +1 -0
- package/dist/types/platform/error.d.ts +22 -0
- package/dist/types/platform/error.js.map +1 -0
- package/dist/types/platform/fetch.d.ts +36 -0
- package/dist/types/platform/fetch.js.map +1 -0
- package/dist/types/platform/index.d.ts +4 -0
- package/dist/types/platform/index.js.map +1 -0
- package/dist/types/platform/types.d.ts +164 -0
- package/dist/types/platform/types.js.map +1 -0
- package/dist/types/utils/hast-fast.d.ts +101 -0
- package/dist/types/utils/hast-fast.js.map +1 -0
- package/dist/utils/hast-fast.js +246 -0
- package/package.json +25 -7
- package/dist/types/cli/commands/webforai/index.d.ts +0 -6
- package/dist/types/cli/commands/webforai/index.js.map +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var definition_list_handler_exports = {};
|
|
20
|
+
__export(definition_list_handler_exports, {
|
|
21
|
+
definitionListHandler: () => definitionListHandler
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(definition_list_handler_exports);
|
|
24
|
+
const hoistBoundaryWhitespace = (nodes) => {
|
|
25
|
+
const result = [];
|
|
26
|
+
for (const node of nodes) {
|
|
27
|
+
if (node.type !== "emphasis" && node.type !== "strong") {
|
|
28
|
+
result.push(node);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
node.children = hoistBoundaryWhitespace(node.children);
|
|
32
|
+
const first = node.children[0];
|
|
33
|
+
if (first?.type === "text" && /^\s/.test(first.value)) {
|
|
34
|
+
result.push({ type: "text", value: " " });
|
|
35
|
+
first.value = first.value.replace(/^\s+/, "");
|
|
36
|
+
}
|
|
37
|
+
let trailing = false;
|
|
38
|
+
const last = node.children[node.children.length - 1];
|
|
39
|
+
if (last?.type === "text" && /\s$/.test(last.value)) {
|
|
40
|
+
last.value = last.value.replace(/\s+$/, "");
|
|
41
|
+
trailing = true;
|
|
42
|
+
}
|
|
43
|
+
node.children = node.children.filter((child) => !(child.type === "text" && child.value.length === 0));
|
|
44
|
+
if (node.children.length > 0) {
|
|
45
|
+
result.push(node);
|
|
46
|
+
}
|
|
47
|
+
if (trailing) {
|
|
48
|
+
result.push({ type: "text", value: " " });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
const termsAndDefinitions = (parent) => {
|
|
54
|
+
const found = [];
|
|
55
|
+
for (const child of parent.children) {
|
|
56
|
+
if (child.type !== "element") {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (child.tagName === "dt" || child.tagName === "dd") {
|
|
60
|
+
found.push(child);
|
|
61
|
+
} else if (child.tagName === "div") {
|
|
62
|
+
found.push(...termsAndDefinitions(child));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return found;
|
|
66
|
+
};
|
|
67
|
+
const definitionListHandler = (state, node) => {
|
|
68
|
+
const items = [];
|
|
69
|
+
let current;
|
|
70
|
+
const flush = () => {
|
|
71
|
+
if (!current) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const heading = {
|
|
75
|
+
type: "paragraph",
|
|
76
|
+
children: current.term.length > 0 ? [{ type: "strong", children: current.term }] : []
|
|
77
|
+
};
|
|
78
|
+
items.push({ type: "listItem", spread: false, children: [heading, ...current.definitions] });
|
|
79
|
+
current = void 0;
|
|
80
|
+
};
|
|
81
|
+
for (const element of termsAndDefinitions(node)) {
|
|
82
|
+
if (element.tagName === "dt") {
|
|
83
|
+
if (current && current.definitions.length > 0) {
|
|
84
|
+
flush();
|
|
85
|
+
}
|
|
86
|
+
const phrasing = hoistBoundaryWhitespace(state.all(element));
|
|
87
|
+
current = current ? { term: [...current.term, { type: "text", value: ", " }, ...phrasing], definitions: [] } : { term: phrasing, definitions: [] };
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (element.tagName === "dd") {
|
|
91
|
+
if (!current) {
|
|
92
|
+
current = { term: [], definitions: [] };
|
|
93
|
+
}
|
|
94
|
+
const content = state.toFlow(state.all(element));
|
|
95
|
+
current.definitions.push(...content);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
flush();
|
|
99
|
+
if (items.length === 0) {
|
|
100
|
+
const fallback = state.toFlow(state.all(node));
|
|
101
|
+
return fallback.length > 0 ? fallback : void 0;
|
|
102
|
+
}
|
|
103
|
+
const result = { type: "list", ordered: false, spread: false, children: items };
|
|
104
|
+
state.patch(node, result);
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
definitionListHandler
|
|
110
|
+
});
|
|
@@ -23,10 +23,19 @@ __export(math_handler_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(math_handler_exports);
|
|
24
24
|
var import_hast_util_to_html = require("hast-util-to-html");
|
|
25
25
|
var import_mathml_to_latex = require("mathml-to-latex");
|
|
26
|
+
var import_hast_fast = require("../utils/hast-fast");
|
|
27
|
+
const readAnnotation = (node) => {
|
|
28
|
+
const alttext = (0, import_hast_fast.stringProperty)(node, "alttext");
|
|
29
|
+
if (!alttext) {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
const unwrapped = alttext.trim().replace(/^\{\\displaystyle\s*([\s\S]*)\}$/, "$1").trim();
|
|
33
|
+
return unwrapped.length > 0 ? unwrapped : void 0;
|
|
34
|
+
};
|
|
35
|
+
const isDisplayMath = (node) => (0, import_hast_fast.stringProperty)(node, "display") === "block";
|
|
26
36
|
const mathHandler = (state, node) => {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const result = { type: "inlineMath", value: latex };
|
|
37
|
+
const latex = readAnnotation(node) ?? import_mathml_to_latex.MathMLToLaTeX.convert((0, import_hast_util_to_html.toHtml)(node));
|
|
38
|
+
const result = isDisplayMath(node) ? { type: "math", value: latex, meta: null } : { type: "inlineMath", value: latex };
|
|
30
39
|
state.patch(node, result);
|
|
31
40
|
return result;
|
|
32
41
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sup_sub_handler_exports = {};
|
|
20
|
+
__export(sup_sub_handler_exports, {
|
|
21
|
+
supSubHandler: () => supSubHandler
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sup_sub_handler_exports);
|
|
24
|
+
var import_hast_util_to_string = require("hast-util-to-string");
|
|
25
|
+
const MAX_ANNOTATION_LENGTH = 32;
|
|
26
|
+
const supSubHandler = (tagName) => (state, node) => {
|
|
27
|
+
const inner = (0, import_hast_util_to_string.toString)(node).trim();
|
|
28
|
+
if (inner.length === 0 || inner.length > MAX_ANNOTATION_LENGTH) {
|
|
29
|
+
return state.all(node);
|
|
30
|
+
}
|
|
31
|
+
const escaped = inner.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
32
|
+
const result = { type: "html", value: `<${tagName}>${escaped}</${tagName}>` };
|
|
33
|
+
state.patch(node, result);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
supSubHandler
|
|
39
|
+
});
|
|
@@ -33,11 +33,8 @@ const DEFAULT_MDAST_TO_MARKDOWN_OPTIONS = {
|
|
|
33
33
|
};
|
|
34
34
|
const mdastToMarkdown = (mdast, options) => {
|
|
35
35
|
const { baseUrl, ...toMarkdownOptions } = { ...DEFAULT_MDAST_TO_MARKDOWN_OPTIONS, ...options };
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
markdown = (0, import_link_replacer.linkReplacer)(markdown, baseUrl);
|
|
39
|
-
}
|
|
40
|
-
return markdown;
|
|
36
|
+
const tree = (0, import_mdast_utils.warpRoot)(mdast);
|
|
37
|
+
return (0, import_mdast_util_to_markdown.toMarkdown)(baseUrl ? (0, import_link_replacer.linkReplacer)(tree, baseUrl) : tree, toMarkdownOptions);
|
|
41
38
|
};
|
|
42
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
40
|
0 && (module.exports = {
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var metadata_exports = {};
|
|
20
|
+
__export(metadata_exports, {
|
|
21
|
+
extractMetadata: () => extractMetadata,
|
|
22
|
+
readJsonLd: () => readJsonLd,
|
|
23
|
+
toFrontmatter: () => toFrontmatter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(metadata_exports);
|
|
26
|
+
var import_hast_fast = require("../utils/hast-fast");
|
|
27
|
+
const readMetaTags = (tree) => {
|
|
28
|
+
const tags = /* @__PURE__ */ new Map();
|
|
29
|
+
for (const meta of (0, import_hast_fast.collectElements)(tree, (element) => element.tagName === "meta")) {
|
|
30
|
+
const key = (0, import_hast_fast.stringProperty)(meta, "property") ?? (0, import_hast_fast.stringProperty)(meta, "name") ?? (0, import_hast_fast.stringProperty)(meta, "itemprop");
|
|
31
|
+
const content = (0, import_hast_fast.stringProperty)(meta, "content");
|
|
32
|
+
if (!(key && content)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const normalized = key.toLowerCase();
|
|
36
|
+
if (!tags.has(normalized)) {
|
|
37
|
+
tags.set(normalized, content);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return tags;
|
|
41
|
+
};
|
|
42
|
+
const readJsonLd = (tree) => {
|
|
43
|
+
const entries = [];
|
|
44
|
+
for (const script of (0, import_hast_fast.collectElements)(tree, (element) => element.tagName === "script")) {
|
|
45
|
+
const type = (0, import_hast_fast.stringProperty)(script, "type");
|
|
46
|
+
if (type?.toLowerCase() !== "application/ld+json") {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const source = script.children.map((child) => child.type === "text" ? child.value : "").join("").trim();
|
|
50
|
+
if (source.length === 0) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
let parsed;
|
|
54
|
+
try {
|
|
55
|
+
parsed = JSON.parse(source);
|
|
56
|
+
} catch {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
for (const entry of flattenJsonLd(parsed)) {
|
|
60
|
+
entries.push(entry);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return entries;
|
|
64
|
+
};
|
|
65
|
+
const flattenJsonLd = (value) => {
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return value.flatMap(flattenJsonLd);
|
|
68
|
+
}
|
|
69
|
+
if (typeof value !== "object" || value === null) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const record = value;
|
|
73
|
+
const graph = record["@graph"];
|
|
74
|
+
if (graph) {
|
|
75
|
+
return flattenJsonLd(graph);
|
|
76
|
+
}
|
|
77
|
+
return [record];
|
|
78
|
+
};
|
|
79
|
+
const ARTICLE_TYPES = /* @__PURE__ */ new Set([
|
|
80
|
+
"article",
|
|
81
|
+
"newsarticle",
|
|
82
|
+
"blogposting",
|
|
83
|
+
"techarticle",
|
|
84
|
+
"scholarlyarticle",
|
|
85
|
+
"report",
|
|
86
|
+
"webpage"
|
|
87
|
+
]);
|
|
88
|
+
const jsonLdType = (entry) => {
|
|
89
|
+
const type = entry["@type"];
|
|
90
|
+
if (typeof type === "string") {
|
|
91
|
+
return [type.toLowerCase()];
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(type)) {
|
|
94
|
+
return type.filter((value) => typeof value === "string").map((value) => value.toLowerCase());
|
|
95
|
+
}
|
|
96
|
+
return [];
|
|
97
|
+
};
|
|
98
|
+
const readName = (value) => {
|
|
99
|
+
if (typeof value === "string") {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
for (const entry of value) {
|
|
104
|
+
const name = readName(entry);
|
|
105
|
+
if (name) {
|
|
106
|
+
return name;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === "object" && value !== null) {
|
|
112
|
+
const name = value.name;
|
|
113
|
+
return typeof name === "string" ? name : void 0;
|
|
114
|
+
}
|
|
115
|
+
return void 0;
|
|
116
|
+
};
|
|
117
|
+
const asString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
118
|
+
const MAX_TITLE_LENGTH = 160;
|
|
119
|
+
const asTitle = (value) => {
|
|
120
|
+
const cleaned = clean(value);
|
|
121
|
+
return cleaned && cleaned.length <= MAX_TITLE_LENGTH ? cleaned : void 0;
|
|
122
|
+
};
|
|
123
|
+
const clean = (value) => {
|
|
124
|
+
if (value === void 0) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
const trimmed = value.replace(/\s+/g, " ").trim();
|
|
128
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
129
|
+
};
|
|
130
|
+
const documentTitle = (tree) => {
|
|
131
|
+
const title = (0, import_hast_fast.findElement)(tree, (element) => element.tagName === "title");
|
|
132
|
+
if (!title) {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
return title.children.map((child) => child.type === "text" ? child.value : "").join("");
|
|
136
|
+
};
|
|
137
|
+
const firstHeading = (tree) => {
|
|
138
|
+
const heading = (0, import_hast_fast.findElement)(tree, (element) => element.tagName === "h1");
|
|
139
|
+
if (!heading) {
|
|
140
|
+
return void 0;
|
|
141
|
+
}
|
|
142
|
+
let text = "";
|
|
143
|
+
(0, import_hast_fast.walk)(heading, (node) => {
|
|
144
|
+
if (node.type === "text") {
|
|
145
|
+
text += node.value;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return text;
|
|
149
|
+
};
|
|
150
|
+
const linkHref = (tree, rel) => {
|
|
151
|
+
const link = (0, import_hast_fast.findElement)(
|
|
152
|
+
tree,
|
|
153
|
+
(element) => element.tagName === "link" && ((0, import_hast_fast.stringProperty)(element, "rel") ?? "").toLowerCase().includes(rel)
|
|
154
|
+
);
|
|
155
|
+
return link ? (0, import_hast_fast.stringProperty)(link, "href") : void 0;
|
|
156
|
+
};
|
|
157
|
+
const documentLang = (tree) => {
|
|
158
|
+
const html = (0, import_hast_fast.findElement)(tree, (element) => element.tagName === "html");
|
|
159
|
+
if (html) {
|
|
160
|
+
const declared = (0, import_hast_fast.stringProperty)(html, "lang") ?? (0, import_hast_fast.stringProperty)(html, "xml:lang");
|
|
161
|
+
if (declared) {
|
|
162
|
+
return declared;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if ((0, import_hast_fast.isElement)(tree)) {
|
|
166
|
+
const own = (0, import_hast_fast.stringProperty)(tree, "lang");
|
|
167
|
+
if (own) {
|
|
168
|
+
return own;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const tagged = (0, import_hast_fast.findElement)(tree, (element) => Boolean((0, import_hast_fast.stringProperty)(element, "lang")));
|
|
172
|
+
return tagged ? (0, import_hast_fast.stringProperty)(tagged, "lang") : void 0;
|
|
173
|
+
};
|
|
174
|
+
const extractMetadata = (tree) => {
|
|
175
|
+
const meta = readMetaTags(tree);
|
|
176
|
+
const jsonLd = readJsonLd(tree);
|
|
177
|
+
const article = jsonLd.find((entry) => jsonLdType(entry).some((type) => ARTICLE_TYPES.has(type))) ?? jsonLd[0];
|
|
178
|
+
const get = (...keys) => {
|
|
179
|
+
for (const key of keys) {
|
|
180
|
+
const value = meta.get(key);
|
|
181
|
+
if (value) {
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return void 0;
|
|
186
|
+
};
|
|
187
|
+
const title = asTitle(get("og:title", "twitter:title")) ?? asTitle(asString(article?.headline)) ?? asTitle(asString(article?.name)) ?? asTitle(documentTitle(tree)) ?? asTitle(firstHeading(tree));
|
|
188
|
+
return {
|
|
189
|
+
title,
|
|
190
|
+
description: clean(get("og:description", "twitter:description", "description")) ?? clean(asString(article?.description)),
|
|
191
|
+
author: clean(readName(article?.author)) ?? clean(get("author", "article:author", "twitter:creator")),
|
|
192
|
+
published: clean(asString(article?.datePublished)) ?? clean(get("article:published_time", "date", "pubdate")),
|
|
193
|
+
modified: clean(asString(article?.dateModified)) ?? clean(get("article:modified_time", "og:updated_time")),
|
|
194
|
+
siteName: clean(get("og:site_name", "application-name")) ?? clean(readName(article?.publisher)),
|
|
195
|
+
canonicalUrl: clean(linkHref(tree, "canonical")) ?? clean(get("og:url", "twitter:url")),
|
|
196
|
+
lang: clean(documentLang(tree)),
|
|
197
|
+
image: clean(get("og:image", "twitter:image", "twitter:image:src")),
|
|
198
|
+
type: clean(get("og:type"))
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const yamlString = (value) => `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
202
|
+
const toFrontmatter = (metadata) => {
|
|
203
|
+
const lines = [];
|
|
204
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
205
|
+
if (typeof value === "string" && value.length > 0) {
|
|
206
|
+
lines.push(`${key}: ${yamlString(value)}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (lines.length === 0) {
|
|
210
|
+
return "";
|
|
211
|
+
}
|
|
212
|
+
return `---
|
|
213
|
+
${lines.join("\n")}
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
`;
|
|
217
|
+
};
|
|
218
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
219
|
+
0 && (module.exports = {
|
|
220
|
+
extractMetadata,
|
|
221
|
+
readJsonLd,
|
|
222
|
+
toFrontmatter
|
|
223
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var normalize_exports = {};
|
|
20
|
+
__export(normalize_exports, {
|
|
21
|
+
bestFromSrcset: () => bestFromSrcset,
|
|
22
|
+
dedupeRenderedMath: () => dedupeRenderedMath,
|
|
23
|
+
normalizeHast: () => normalizeHast,
|
|
24
|
+
promoteAriaHeadings: () => promoteAriaHeadings,
|
|
25
|
+
resolveImageSources: () => resolveImageSources
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(normalize_exports);
|
|
28
|
+
var import_hast_fast = require("../utils/hast-fast");
|
|
29
|
+
const LAZY_SRC_ATTRIBUTES = [
|
|
30
|
+
"data-src",
|
|
31
|
+
"data-original",
|
|
32
|
+
"data-lazy-src",
|
|
33
|
+
"data-original-src",
|
|
34
|
+
"data-actualsrc",
|
|
35
|
+
"data-hi-res-src",
|
|
36
|
+
"data-echo"
|
|
37
|
+
];
|
|
38
|
+
const PLACEHOLDER_SRC = /^$|^data:image\/|^about:blank$|spacer\.gif$|blank\.(gif|png)$/i;
|
|
39
|
+
const readSrcset = (element, attribute) => {
|
|
40
|
+
const raw = (0, import_hast_fast.property)(element, attribute);
|
|
41
|
+
if (typeof raw === "string") {
|
|
42
|
+
return raw;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(raw)) {
|
|
45
|
+
return raw.join(", ");
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
};
|
|
49
|
+
const bestFromSrcset = (srcset) => {
|
|
50
|
+
let best;
|
|
51
|
+
for (const entry of srcset.split(",")) {
|
|
52
|
+
const parts = entry.trim().split(/\s+/);
|
|
53
|
+
const url = parts[0];
|
|
54
|
+
if (!url) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const descriptor = parts[1];
|
|
58
|
+
let weight = 1;
|
|
59
|
+
if (descriptor?.endsWith("w")) {
|
|
60
|
+
weight = Number.parseFloat(descriptor) || 1;
|
|
61
|
+
} else if (descriptor?.endsWith("x")) {
|
|
62
|
+
weight = (Number.parseFloat(descriptor) || 1) * 1e3;
|
|
63
|
+
}
|
|
64
|
+
if (!best || weight > best.weight) {
|
|
65
|
+
best = { url, weight };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return best?.url;
|
|
69
|
+
};
|
|
70
|
+
const resolveImageSources = (tree) => {
|
|
71
|
+
(0, import_hast_fast.walk)(tree, (node) => {
|
|
72
|
+
if (!(0, import_hast_fast.isElement)(node) || node.tagName !== "img") {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const current = (0, import_hast_fast.stringProperty)(node, "src");
|
|
76
|
+
if (current && !PLACEHOLDER_SRC.test(current)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
for (const attribute of LAZY_SRC_ATTRIBUTES) {
|
|
80
|
+
const candidate = (0, import_hast_fast.stringProperty)(node, attribute);
|
|
81
|
+
if (candidate && !PLACEHOLDER_SRC.test(candidate)) {
|
|
82
|
+
node.properties.src = candidate;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const attribute of ["srcSet", "srcset", "data-srcset"]) {
|
|
87
|
+
const srcset = readSrcset(node, attribute);
|
|
88
|
+
const best = srcset ? bestFromSrcset(srcset) : void 0;
|
|
89
|
+
if (best) {
|
|
90
|
+
node.properties.src = best;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const katexDuplicates = (node) => {
|
|
97
|
+
const classes = (0, import_hast_fast.classList)(node);
|
|
98
|
+
if (!(classes.includes("katex") || classes.includes("katex-display"))) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const hasMathml = node.children.some(
|
|
102
|
+
(child) => (0, import_hast_fast.isElement)(child) && (0, import_hast_fast.classList)(child).includes("katex-mathml") && hasMathSource(child)
|
|
103
|
+
);
|
|
104
|
+
if (!hasMathml) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
return node.children.filter((child) => (0, import_hast_fast.isElement)(child) && (0, import_hast_fast.classList)(child).includes("katex-html"));
|
|
108
|
+
};
|
|
109
|
+
const mediawikiDuplicates = (node) => {
|
|
110
|
+
if (!(0, import_hast_fast.classList)(node).includes("mwe-math-element") || !hasMathSource(node)) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
return node.children.filter(
|
|
114
|
+
(child) => (0, import_hast_fast.isElement)(child) && (0, import_hast_fast.classList)(child).some((name) => name.startsWith("mwe-math-fallback-image"))
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
const mathjaxDuplicates = (node) => {
|
|
118
|
+
if (node.tagName !== "mjx-container") {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const hasMathml = node.children.some(
|
|
122
|
+
(child) => (0, import_hast_fast.isElement)(child) && child.tagName === "mjx-assistive-mml" && hasMathSource(child)
|
|
123
|
+
);
|
|
124
|
+
if (!hasMathml) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
return node.children.filter((child) => (0, import_hast_fast.isElement)(child) && child.tagName !== "mjx-assistive-mml");
|
|
128
|
+
};
|
|
129
|
+
const hasMathSource = (node) => Boolean((0, import_hast_fast.findElement)(node, (element) => element.tagName === "math" && element.children.length > 0));
|
|
130
|
+
const dedupeRenderedMath = (tree) => {
|
|
131
|
+
const doomed = /* @__PURE__ */ new Set();
|
|
132
|
+
(0, import_hast_fast.walk)(tree, (node) => {
|
|
133
|
+
if (!(0, import_hast_fast.isElement)(node)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
for (const duplicate of [...katexDuplicates(node), ...mathjaxDuplicates(node), ...mediawikiDuplicates(node)]) {
|
|
137
|
+
doomed.add(duplicate);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (doomed.size > 0) {
|
|
141
|
+
(0, import_hast_fast.pruneInPlace)(tree, (node) => !((0, import_hast_fast.isElement)(node) && doomed.has(node)));
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const promoteAriaHeadings = (tree) => {
|
|
145
|
+
(0, import_hast_fast.walk)(tree, (node) => {
|
|
146
|
+
if (!(0, import_hast_fast.isElement)(node) || (0, import_hast_fast.stringProperty)(node, "role") !== "heading") {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (/^h[1-6]$/.test(node.tagName)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const level = (0, import_hast_fast.numericProperty)(node, "aria-level") ?? 2;
|
|
153
|
+
const clamped = Math.min(6, Math.max(1, Math.round(level)));
|
|
154
|
+
node.tagName = `h${clamped}`;
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
const normalizeHast = (tree, options = {}) => {
|
|
158
|
+
const { images = true, math = true, ariaHeadings = true } = options;
|
|
159
|
+
if (images) {
|
|
160
|
+
resolveImageSources(tree);
|
|
161
|
+
}
|
|
162
|
+
if (math) {
|
|
163
|
+
dedupeRenderedMath(tree);
|
|
164
|
+
}
|
|
165
|
+
if (ariaHeadings) {
|
|
166
|
+
promoteAriaHeadings(tree);
|
|
167
|
+
}
|
|
168
|
+
return tree;
|
|
169
|
+
};
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
bestFromSrcset,
|
|
173
|
+
dedupeRenderedMath,
|
|
174
|
+
normalizeHast,
|
|
175
|
+
promoteAriaHeadings,
|
|
176
|
+
resolveImageSources
|
|
177
|
+
});
|