webforai 0.0.17 → 0.0.19

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.
Files changed (64) hide show
  1. package/dist/cjs/extract-hast.js +45 -0
  2. package/dist/cjs/html-to-markdown.js +34 -0
  3. package/dist/cjs/html-to-mdast.js +41 -0
  4. package/dist/cjs/index.js +28 -0
  5. package/dist/cjs/link-replacer.js +35 -0
  6. package/dist/cjs/loaders/playwright.js +57 -0
  7. package/dist/cjs/md-splitter.js +54 -0
  8. package/dist/cjs/mdast-handlers/custom-div-handler.js +65 -0
  9. package/dist/cjs/mdast-handlers/math-handler.js +36 -0
  10. package/dist/cjs/mdast-to-markdown.js +40 -0
  11. package/dist/cjs/package.json +3 -0
  12. package/dist/cjs/utils/common.js +36 -0
  13. package/dist/cjs/utils/mdast-utils.js +46 -0
  14. package/dist/extract-hast.js +18 -15
  15. package/dist/html-to-markdown.js +10 -7
  16. package/dist/html-to-mdast.js +15 -11
  17. package/dist/index.js +5 -5
  18. package/dist/link-replacer.js +11 -8
  19. package/dist/loaders/playwright.js +23 -21
  20. package/dist/md-splitter.js +28 -27
  21. package/dist/mdast-handlers/custom-div-handler.js +37 -37
  22. package/dist/mdast-handlers/math-handler.js +10 -7
  23. package/dist/mdast-to-markdown.js +13 -10
  24. package/dist/types/extract-hast.d.ts +2 -0
  25. package/dist/types/package.json +3 -0
  26. package/dist/utils/common.js +12 -9
  27. package/dist/utils/mdast-utils.js +18 -13
  28. package/package.json +45 -22
  29. package/dist/extract-hast.d.ts +0 -2
  30. package/dist/extract-hast.js.map +0 -1
  31. package/dist/html-to-markdown.js.map +0 -1
  32. package/dist/html-to-mdast.js.map +0 -1
  33. package/dist/index.js.map +0 -1
  34. package/dist/link-replacer.js.map +0 -1
  35. package/dist/loaders/playwright.js.map +0 -1
  36. package/dist/md-splitter.js.map +0 -1
  37. package/dist/mdast-handlers/custom-div-handler.js.map +0 -1
  38. package/dist/mdast-handlers/math-handler.js.map +0 -1
  39. package/dist/mdast-to-markdown.js.map +0 -1
  40. package/dist/utils/common.js.map +0 -1
  41. package/dist/utils/mdast-utils.js.map +0 -1
  42. package/src/extract-hast.ts +0 -23
  43. package/src/html-to-markdown.ts +0 -14
  44. package/src/html-to-mdast.ts +0 -23
  45. package/src/index.ts +0 -4
  46. package/src/link-replacer.ts +0 -7
  47. package/src/loaders/playwright.ts +0 -22
  48. package/src/md-splitter.ts +0 -43
  49. package/src/mdast-handlers/custom-div-handler.ts +0 -43
  50. package/src/mdast-handlers/math-handler.ts +0 -12
  51. package/src/mdast-to-markdown.ts +0 -18
  52. package/src/utils/common.ts +0 -9
  53. package/src/utils/mdast-utils.ts +0 -16
  54. /package/dist/{html-to-markdown.d.ts → types/html-to-markdown.d.ts} +0 -0
  55. /package/dist/{html-to-mdast.d.ts → types/html-to-mdast.d.ts} +0 -0
  56. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  57. /package/dist/{link-replacer.d.ts → types/link-replacer.d.ts} +0 -0
  58. /package/dist/{loaders → types/loaders}/playwright.d.ts +0 -0
  59. /package/dist/{md-splitter.d.ts → types/md-splitter.d.ts} +0 -0
  60. /package/dist/{mdast-handlers → types/mdast-handlers}/custom-div-handler.d.ts +0 -0
  61. /package/dist/{mdast-handlers → types/mdast-handlers}/math-handler.d.ts +0 -0
  62. /package/dist/{mdast-to-markdown.d.ts → types/mdast-to-markdown.d.ts} +0 -0
  63. /package/dist/{utils → types/utils}/common.d.ts +0 -0
  64. /package/dist/{utils → types/utils}/mdast-utils.d.ts +0 -0
@@ -0,0 +1,45 @@
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 extract_hast_exports = {};
20
+ __export(extract_hast_exports, {
21
+ extractHast: () => extractHast
22
+ });
23
+ module.exports = __toCommonJS(extract_hast_exports);
24
+ var import_hast_util_select = require("hast-util-select");
25
+ var import_unist_util_remove = require("unist-util-remove");
26
+ const extractHast = (hast) => {
27
+ const removeSelectors = ["header", "footer", "nav", "speechify-ignore"];
28
+ for (const selector of removeSelectors) {
29
+ const matchedNodes = (0, import_hast_util_select.selectAll)(selector, hast);
30
+ for (const node of matchedNodes) {
31
+ (0, import_unist_util_remove.remove)(hast, { type: node.type, tagName: node.tagName });
32
+ }
33
+ }
34
+ const selectors = ["article", "div#article", "main", "div.container"];
35
+ for (const selector of selectors) {
36
+ const element = (0, import_hast_util_select.select)(selector, hast);
37
+ if (element)
38
+ return element;
39
+ }
40
+ return hast;
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ extractHast
45
+ });
@@ -0,0 +1,34 @@
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 html_to_markdown_exports = {};
20
+ __export(html_to_markdown_exports, {
21
+ htmlToMarkdown: () => htmlToMarkdown
22
+ });
23
+ module.exports = __toCommonJS(html_to_markdown_exports);
24
+ var import_html_to_mdast = require("./html-to-mdast");
25
+ var import_mdast_to_markdown = require("./mdast-to-markdown");
26
+ const htmlToMarkdown = (html, options) => {
27
+ const mdast = (0, import_html_to_mdast.htmlToMdast)(html, options);
28
+ const markdown = (0, import_mdast_to_markdown.mdastToMarkdown)(mdast, options);
29
+ return markdown;
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ htmlToMarkdown
34
+ });
@@ -0,0 +1,41 @@
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 html_to_mdast_exports = {};
20
+ __export(html_to_mdast_exports, {
21
+ htmlToMdast: () => htmlToMdast
22
+ });
23
+ module.exports = __toCommonJS(html_to_mdast_exports);
24
+ var import_hast_util_from_html = require("hast-util-from-html");
25
+ var import_hast_util_to_mdast = require("hast-util-to-mdast");
26
+ var import_extract_hast = require("./extract-hast");
27
+ var import_custom_div_handler = require("./mdast-handlers/custom-div-handler");
28
+ var import_math_handler = require("./mdast-handlers/math-handler");
29
+ const htmlToMdast = (html, options) => {
30
+ const hast = (0, import_hast_util_from_html.fromHtml)(html, { fragment: true });
31
+ const extractedHast = options?.extractHast ? options.extractHast(hast) : (0, import_extract_hast.extractHast)(hast);
32
+ const mdast = (0, import_hast_util_to_mdast.toMdast)(extractedHast, {
33
+ handlers: { div: import_custom_div_handler.customDivHandler, math: import_math_handler.mathHandler, br: () => {
34
+ } }
35
+ });
36
+ return mdast;
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ htmlToMdast
41
+ });
@@ -0,0 +1,28 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./html-to-markdown"), module.exports);
19
+ __reExport(src_exports, require("./md-splitter"), module.exports);
20
+ __reExport(src_exports, require("./html-to-mdast"), module.exports);
21
+ __reExport(src_exports, require("./mdast-to-markdown"), module.exports);
22
+ // Annotate the CommonJS export names for ESM import in node:
23
+ 0 && (module.exports = {
24
+ ...require("./html-to-markdown"),
25
+ ...require("./md-splitter"),
26
+ ...require("./html-to-mdast"),
27
+ ...require("./mdast-to-markdown")
28
+ });
@@ -0,0 +1,35 @@
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 link_replacer_exports = {};
20
+ __export(link_replacer_exports, {
21
+ linkReplacer: () => linkReplacer
22
+ });
23
+ module.exports = __toCommonJS(link_replacer_exports);
24
+ const linkReplacer = (markdown, link) => {
25
+ const regex = /(!?\[.*?\]\()(.+?)(\))/g;
26
+ return markdown.replace(regex, (match, pre, thisUrl, post) => {
27
+ if (thisUrl.startsWith("http") || thisUrl.startsWith("#"))
28
+ return match;
29
+ return `${pre}${new URL(thisUrl, link).href}${post}`;
30
+ });
31
+ };
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ linkReplacer
35
+ });
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var playwright_exports = {};
30
+ __export(playwright_exports, {
31
+ loadHtml: () => loadHtml
32
+ });
33
+ module.exports = __toCommonJS(playwright_exports);
34
+ var playwright = __toESM(require("playwright"), 1);
35
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
36
+ const loadHtml = async (url, context) => {
37
+ let _browser = null;
38
+ let _context;
39
+ if (!context) {
40
+ _browser = await playwright.chromium.launch();
41
+ _context = await _browser.newContext();
42
+ } else {
43
+ _context = context;
44
+ }
45
+ const page = await _context.newPage();
46
+ await page.goto(url);
47
+ await Promise.race([page.waitForLoadState("networkidle"), sleep(1e4)]);
48
+ const html = await page.content();
49
+ await page.close();
50
+ if (_browser)
51
+ await _browser.close();
52
+ return html;
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ loadHtml
57
+ });
@@ -0,0 +1,54 @@
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 md_splitter_exports = {};
20
+ __export(md_splitter_exports, {
21
+ mdastSplitter: () => mdastSplitter
22
+ });
23
+ module.exports = __toCommonJS(md_splitter_exports);
24
+ var import_mdast_to_markdown = require("./mdast-to-markdown");
25
+ var import_common = require("./utils/common");
26
+ var import_mdast_utils = require("./utils/mdast-utils");
27
+ const PRIORITY_SPLITTERS = ["h1", "h2", "h3", "h4", "h5", "h6", "list", "table", "code"];
28
+ const getSplitterGenerator = function* () {
29
+ for (const splitter of PRIORITY_SPLITTERS)
30
+ yield splitter;
31
+ };
32
+ const _mdastSplitter = async (contents, checker, splitterGenerator) => {
33
+ const markdown = (0, import_mdast_to_markdown.mdastToMarkdown)((0, import_mdast_utils.warpRoot)(contents));
34
+ if (await checker(markdown) || 3 > contents.length)
35
+ return [contents];
36
+ const splitter = splitterGenerator.next().value;
37
+ const chunked = splitter ? contents.reduce((acc, content) => {
38
+ if ((0, import_mdast_utils.internalType)(content) === splitter || acc.length === 0) {
39
+ acc.push([content]);
40
+ return acc;
41
+ }
42
+ acc[acc.length - 1].push(content);
43
+ return acc;
44
+ }, []) : (0, import_common.chunk)(contents, 3);
45
+ const splitting = chunked.map((chunk2) => _mdastSplitter(chunk2, checker, splitterGenerator));
46
+ return Promise.all(splitting).then((chunks) => chunks.flat());
47
+ };
48
+ const mdastSplitter = async (mdast, checker, options) => {
49
+ return _mdastSplitter((0, import_mdast_utils.unwarpRoot)(mdast), checker, getSplitterGenerator());
50
+ };
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ mdastSplitter
54
+ });
@@ -0,0 +1,65 @@
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 custom_div_handler_exports = {};
20
+ __export(custom_div_handler_exports, {
21
+ customDivHandler: () => customDivHandler
22
+ });
23
+ module.exports = __toCommonJS(custom_div_handler_exports);
24
+ var import_hast_util_to_mdast = require("hast-util-to-mdast");
25
+ var import_hast_util_to_text = require("hast-util-to-text");
26
+ var import_trim_trailing_lines = require("trim-trailing-lines");
27
+ const customDivHandler = (state, node) => {
28
+ const classNames = Array.isArray(node.properties.className) ? node.properties.className : [];
29
+ let highlightLanguage;
30
+ for (const className of classNames) {
31
+ if (String(className) === "highlight-text-html-basic") {
32
+ highlightLanguage = "html";
33
+ break;
34
+ } else if (String(className).includes("highlight-source-")) {
35
+ highlightLanguage = String(className).slice("highlight-source-".length);
36
+ break;
37
+ } else if (String(className).includes("language-")) {
38
+ highlightLanguage = String(className).slice("language-".length);
39
+ break;
40
+ } else if (String(className).includes("code-block_wrapper")) {
41
+ const text = (0, import_hast_util_to_text.toText)(node);
42
+ if (!text.includes("."))
43
+ break;
44
+ const lang = (0, import_hast_util_to_text.toText)(node).split("\n")[0].split(".").slice(-1)[0];
45
+ highlightLanguage = lang;
46
+ break;
47
+ }
48
+ }
49
+ if (highlightLanguage !== void 0) {
50
+ const code = node.children.find((child) => child.type === "element" && child.tagName === "pre") || node;
51
+ const result = {
52
+ type: "code",
53
+ lang: highlightLanguage,
54
+ meta: null,
55
+ value: (0, import_trim_trailing_lines.trimTrailingLines)((0, import_hast_util_to_text.toText)(code)).trim()
56
+ };
57
+ state.patch(node, result);
58
+ return result;
59
+ }
60
+ return import_hast_util_to_mdast.defaultHandlers.div(state, node);
61
+ };
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ customDivHandler
65
+ });
@@ -0,0 +1,36 @@
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 math_handler_exports = {};
20
+ __export(math_handler_exports, {
21
+ mathHandler: () => mathHandler
22
+ });
23
+ module.exports = __toCommonJS(math_handler_exports);
24
+ var import_hast_util_to_html = require("hast-util-to-html");
25
+ var import_mathml_to_latex = require("mathml-to-latex");
26
+ const mathHandler = (state, node) => {
27
+ const mathMl = (0, import_hast_util_to_html.toHtml)(node);
28
+ const latex = import_mathml_to_latex.MathMLToLaTeX.convert(mathMl);
29
+ const result = { type: "inlineMath", value: latex };
30
+ state.patch(node, result);
31
+ return result;
32
+ };
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ mathHandler
36
+ });
@@ -0,0 +1,40 @@
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 mdast_to_markdown_exports = {};
20
+ __export(mdast_to_markdown_exports, {
21
+ mdastToMarkdown: () => mdastToMarkdown
22
+ });
23
+ module.exports = __toCommonJS(mdast_to_markdown_exports);
24
+ var import_mdast_util_gfm = require("mdast-util-gfm");
25
+ var import_mdast_util_math = require("mdast-util-math");
26
+ var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
27
+ var import_link_replacer = require("./link-replacer");
28
+ var import_mdast_utils = require("./utils/mdast-utils");
29
+ const mdastToMarkdown = (mdast, options) => {
30
+ let markdown = (0, import_mdast_util_to_markdown.toMarkdown)((0, import_mdast_utils.warpRoot)(mdast), {
31
+ extensions: [(0, import_mdast_util_gfm.gfmToMarkdown)(), (0, import_mdast_util_math.mathToMarkdown)()]
32
+ });
33
+ if (options?.solveLinks)
34
+ markdown = (0, import_link_replacer.linkReplacer)(markdown, options.solveLinks);
35
+ return markdown;
36
+ };
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ mdastToMarkdown
40
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,36 @@
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 common_exports = {};
20
+ __export(common_exports, {
21
+ chunk: () => chunk
22
+ });
23
+ module.exports = __toCommonJS(common_exports);
24
+ const chunk = (array, size) => {
25
+ return array.reduce((acc, _, index) => {
26
+ if (index % size === 0) {
27
+ acc.push(array.slice(index, index + size));
28
+ return acc;
29
+ }
30
+ return acc;
31
+ }, []);
32
+ };
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ chunk
36
+ });
@@ -0,0 +1,46 @@
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 mdast_utils_exports = {};
20
+ __export(mdast_utils_exports, {
21
+ internalType: () => internalType,
22
+ unwarpRoot: () => unwarpRoot,
23
+ warpRoot: () => warpRoot
24
+ });
25
+ module.exports = __toCommonJS(mdast_utils_exports);
26
+ const unwarpRoot = (mdast) => {
27
+ if (mdast.type === "root")
28
+ return mdast.children;
29
+ return [mdast];
30
+ };
31
+ const warpRoot = (mdast) => {
32
+ if (Array.isArray(mdast))
33
+ return { type: "root", children: mdast };
34
+ return mdast;
35
+ };
36
+ const internalType = (content) => {
37
+ if (content.type === "heading")
38
+ return `h${content.depth}`;
39
+ return content.type;
40
+ };
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ internalType,
44
+ unwarpRoot,
45
+ warpRoot
46
+ });
@@ -1,19 +1,22 @@
1
+ // src/extract-hast.ts
1
2
  import { select, selectAll } from "hast-util-select";
2
3
  import { remove } from "unist-util-remove";
3
- export const extractHast = (hast) => {
4
- const removeSelectors = ["header", "footer", "nav", "speechify-ignore"];
5
- for (const selector of removeSelectors) {
6
- const matchedNodes = selectAll(selector, hast);
7
- for (const node of matchedNodes) {
8
- remove(hast, { type: node.type, tagName: node.tagName });
9
- }
4
+ var extractHast = (hast) => {
5
+ const removeSelectors = ["header", "footer", "nav", "speechify-ignore"];
6
+ for (const selector of removeSelectors) {
7
+ const matchedNodes = selectAll(selector, hast);
8
+ for (const node of matchedNodes) {
9
+ remove(hast, { type: node.type, tagName: node.tagName });
10
10
  }
11
- const selectors = ["article", "div#article", "main", "div.container"];
12
- for (const selector of selectors) {
13
- const element = select(selector, hast);
14
- if (element)
15
- return element;
16
- }
17
- return hast;
11
+ }
12
+ const selectors = ["article", "div#article", "main", "div.container"];
13
+ for (const selector of selectors) {
14
+ const element = select(selector, hast);
15
+ if (element)
16
+ return element;
17
+ }
18
+ return hast;
19
+ };
20
+ export {
21
+ extractHast
18
22
  };
19
- //# sourceMappingURL=extract-hast.js.map
@@ -1,8 +1,11 @@
1
- import { htmlToMdast } from "./html-to-mdast";
2
- import { mdastToMarkdown } from "./mdast-to-markdown";
3
- export const htmlToMarkdown = (html, options) => {
4
- const mdast = htmlToMdast(html, options);
5
- const markdown = mdastToMarkdown(mdast, options);
6
- return markdown;
1
+ // src/html-to-markdown.ts
2
+ import { htmlToMdast } from "./html-to-mdast.js";
3
+ import { mdastToMarkdown } from "./mdast-to-markdown.js";
4
+ var htmlToMarkdown = (html, options) => {
5
+ const mdast = htmlToMdast(html, options);
6
+ const markdown = mdastToMarkdown(mdast, options);
7
+ return markdown;
8
+ };
9
+ export {
10
+ htmlToMarkdown
7
11
  };
8
- //# sourceMappingURL=html-to-markdown.js.map
@@ -1,14 +1,18 @@
1
+ // src/html-to-mdast.ts
1
2
  import { fromHtml } from "hast-util-from-html";
2
3
  import { toMdast } from "hast-util-to-mdast";
3
- import { extractHast } from "./extract-hast";
4
- import { customDivHandler } from "./mdast-handlers/custom-div-handler";
5
- import { mathHandler } from "./mdast-handlers/math-handler";
6
- export const htmlToMdast = (html, options) => {
7
- const hast = fromHtml(html, { fragment: true });
8
- const extractedHast = options?.extractHast ? options.extractHast(hast) : extractHast(hast);
9
- const mdast = toMdast(extractedHast, {
10
- handlers: { div: customDivHandler, math: mathHandler, br: () => { } },
11
- });
12
- return mdast;
4
+ import { extractHast } from "./extract-hast.js";
5
+ import { customDivHandler } from "./mdast-handlers/custom-div-handler.js";
6
+ import { mathHandler } from "./mdast-handlers/math-handler.js";
7
+ var htmlToMdast = (html, options) => {
8
+ const hast = fromHtml(html, { fragment: true });
9
+ const extractedHast = options?.extractHast ? options.extractHast(hast) : extractHast(hast);
10
+ const mdast = toMdast(extractedHast, {
11
+ handlers: { div: customDivHandler, math: mathHandler, br: () => {
12
+ } }
13
+ });
14
+ return mdast;
15
+ };
16
+ export {
17
+ htmlToMdast
13
18
  };
14
- //# sourceMappingURL=html-to-mdast.js.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./html-to-markdown";
2
- export * from "./md-splitter";
3
- export * from "./html-to-mdast";
4
- export * from "./mdast-to-markdown";
5
- //# sourceMappingURL=index.js.map
1
+ // src/index.ts
2
+ export * from "./html-to-markdown.js";
3
+ export * from "./md-splitter.js";
4
+ export * from "./html-to-mdast.js";
5
+ export * from "./mdast-to-markdown.js";
@@ -1,9 +1,12 @@
1
- export const linkReplacer = (markdown, link) => {
2
- const regex = /(!?\[.*?\]\()(.+?)(\))/g;
3
- return markdown.replace(regex, (match, pre, thisUrl, post) => {
4
- if (thisUrl.startsWith("http") || thisUrl.startsWith("#"))
5
- return match;
6
- return `${pre}${new URL(thisUrl, link).href}${post}`;
7
- });
1
+ // src/link-replacer.ts
2
+ var linkReplacer = (markdown, link) => {
3
+ const regex = /(!?\[.*?\]\()(.+?)(\))/g;
4
+ return markdown.replace(regex, (match, pre, thisUrl, post) => {
5
+ if (thisUrl.startsWith("http") || thisUrl.startsWith("#"))
6
+ return match;
7
+ return `${pre}${new URL(thisUrl, link).href}${post}`;
8
+ });
9
+ };
10
+ export {
11
+ linkReplacer
8
12
  };
9
- //# sourceMappingURL=link-replacer.js.map