webforai 0.0.17 → 0.0.20
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/dist/cjs/extract-hast.js +45 -0
- package/dist/cjs/html-to-markdown.js +34 -0
- package/dist/cjs/html-to-mdast.js +41 -0
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/link-replacer.js +35 -0
- package/dist/cjs/loaders/playwright.js +57 -0
- package/dist/cjs/md-splitter.js +54 -0
- package/dist/cjs/mdast-handlers/custom-div-handler.js +65 -0
- package/dist/cjs/mdast-handlers/math-handler.js +36 -0
- package/dist/cjs/mdast-to-markdown.js +40 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/utils/common.js +36 -0
- package/dist/cjs/utils/mdast-utils.js +46 -0
- package/dist/extract-hast.js +18 -15
- package/dist/html-to-markdown.js +10 -7
- package/dist/html-to-mdast.js +15 -11
- package/dist/index.js +5 -5
- package/dist/link-replacer.js +11 -8
- package/dist/loaders/playwright.js +22 -20
- package/dist/md-splitter.js +28 -27
- package/dist/mdast-handlers/custom-div-handler.js +37 -37
- package/dist/mdast-handlers/math-handler.js +10 -7
- package/dist/mdast-to-markdown.js +13 -10
- package/dist/types/extract-hast.d.ts +2 -0
- package/dist/types/loaders/playwright.d.ts +1 -0
- package/dist/types/package.json +3 -0
- package/dist/utils/common.js +12 -9
- package/dist/utils/mdast-utils.js +18 -13
- package/package.json +45 -22
- package/dist/extract-hast.d.ts +0 -2
- package/dist/extract-hast.js.map +0 -1
- package/dist/html-to-markdown.js.map +0 -1
- package/dist/html-to-mdast.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/link-replacer.js.map +0 -1
- package/dist/loaders/playwright.d.ts +0 -2
- package/dist/loaders/playwright.js.map +0 -1
- package/dist/md-splitter.js.map +0 -1
- package/dist/mdast-handlers/custom-div-handler.js.map +0 -1
- package/dist/mdast-handlers/math-handler.js.map +0 -1
- package/dist/mdast-to-markdown.js.map +0 -1
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/mdast-utils.js.map +0 -1
- package/src/extract-hast.ts +0 -23
- package/src/html-to-markdown.ts +0 -14
- package/src/html-to-mdast.ts +0 -23
- package/src/index.ts +0 -4
- package/src/link-replacer.ts +0 -7
- package/src/loaders/playwright.ts +0 -22
- package/src/md-splitter.ts +0 -43
- package/src/mdast-handlers/custom-div-handler.ts +0 -43
- package/src/mdast-handlers/math-handler.ts +0 -12
- package/src/mdast-to-markdown.ts +0 -18
- package/src/utils/common.ts +0 -9
- package/src/utils/mdast-utils.ts +0 -16
- /package/dist/{html-to-markdown.d.ts → types/html-to-markdown.d.ts} +0 -0
- /package/dist/{html-to-mdast.d.ts → types/html-to-mdast.d.ts} +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{link-replacer.d.ts → types/link-replacer.d.ts} +0 -0
- /package/dist/{md-splitter.d.ts → types/md-splitter.d.ts} +0 -0
- /package/dist/{mdast-handlers → types/mdast-handlers}/custom-div-handler.d.ts +0 -0
- /package/dist/{mdast-handlers → types/mdast-handlers}/math-handler.d.ts +0 -0
- /package/dist/{mdast-to-markdown.d.ts → types/mdast-to-markdown.d.ts} +0 -0
- /package/dist/{utils → types/utils}/common.d.ts +0 -0
- /package/dist/{utils → types/utils}/mdast-utils.d.ts +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { type Handle, defaultHandlers } from "hast-util-to-mdast";
|
|
2
|
-
import { toText } from "hast-util-to-text";
|
|
3
|
-
import type { Code } from "mdast";
|
|
4
|
-
import { trimTrailingLines } from "trim-trailing-lines";
|
|
5
|
-
|
|
6
|
-
export const customDivHandler: Handle = (state, node) => {
|
|
7
|
-
const classNames = Array.isArray(node.properties.className) ? node.properties.className : [];
|
|
8
|
-
|
|
9
|
-
let highlightLanguage: string | undefined;
|
|
10
|
-
for (const className of classNames) {
|
|
11
|
-
if (String(className) === "highlight-text-html-basic") {
|
|
12
|
-
highlightLanguage = "html";
|
|
13
|
-
break;
|
|
14
|
-
} else if (String(className).includes("highlight-source-")) {
|
|
15
|
-
highlightLanguage = String(className).slice("highlight-source-".length);
|
|
16
|
-
break;
|
|
17
|
-
} else if (String(className).includes("language-")) {
|
|
18
|
-
highlightLanguage = String(className).slice("language-".length);
|
|
19
|
-
break;
|
|
20
|
-
} else if (String(className).includes("code-block_wrapper")) {
|
|
21
|
-
const text = toText(node);
|
|
22
|
-
if (!text.includes(".")) break;
|
|
23
|
-
const lang = toText(node).split("\n")[0].split(".").slice(-1)[0];
|
|
24
|
-
highlightLanguage = lang;
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (highlightLanguage !== undefined) {
|
|
30
|
-
const code = node.children.find((child) => child.type === "element" && child.tagName === "pre") || node;
|
|
31
|
-
|
|
32
|
-
const result: Code = {
|
|
33
|
-
type: "code",
|
|
34
|
-
lang: highlightLanguage,
|
|
35
|
-
meta: null,
|
|
36
|
-
value: trimTrailingLines(toText(code)).trim(),
|
|
37
|
-
};
|
|
38
|
-
state.patch(node, result);
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return defaultHandlers.div(state, node);
|
|
43
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { toHtml } from "hast-util-to-html";
|
|
2
|
-
import type { Handle } from "hast-util-to-mdast";
|
|
3
|
-
import { MathMLToLaTeX } from "mathml-to-latex";
|
|
4
|
-
import type { InlineMath, Math as MDMath } from "mdast-util-math";
|
|
5
|
-
|
|
6
|
-
export const mathHandler: Handle = (state, node) => {
|
|
7
|
-
const mathMl = toHtml(node);
|
|
8
|
-
const latex = MathMLToLaTeX.convert(mathMl);
|
|
9
|
-
const result: InlineMath | MDMath = { type: "inlineMath", value: latex };
|
|
10
|
-
state.patch(node, result);
|
|
11
|
-
return result;
|
|
12
|
-
};
|
package/src/mdast-to-markdown.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Nodes as Mdast, RootContent } from "mdast";
|
|
2
|
-
|
|
3
|
-
import { gfmToMarkdown } from "mdast-util-gfm";
|
|
4
|
-
import { mathToMarkdown } from "mdast-util-math";
|
|
5
|
-
import { toMarkdown } from "mdast-util-to-markdown";
|
|
6
|
-
|
|
7
|
-
import { linkReplacer } from "./link-replacer";
|
|
8
|
-
import { warpRoot } from "./utils/mdast-utils";
|
|
9
|
-
|
|
10
|
-
export const mdastToMarkdown = (mdast: Mdast | RootContent[], options?: { solveLinks?: string }): string => {
|
|
11
|
-
let markdown = toMarkdown(warpRoot(mdast), {
|
|
12
|
-
extensions: [gfmToMarkdown(), mathToMarkdown()],
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
if (options?.solveLinks) markdown = linkReplacer(markdown, options.solveLinks);
|
|
16
|
-
|
|
17
|
-
return markdown;
|
|
18
|
-
};
|
package/src/utils/common.ts
DELETED
package/src/utils/mdast-utils.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Nodes as Mdast, RootContent } from "mdast";
|
|
2
|
-
|
|
3
|
-
export const unwarpRoot = (mdast: Mdast): RootContent[] => {
|
|
4
|
-
if (mdast.type === "root") return mdast.children;
|
|
5
|
-
return [mdast];
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const warpRoot = (mdast: RootContent[] | Mdast): Mdast => {
|
|
9
|
-
if (Array.isArray(mdast)) return { type: "root", children: mdast };
|
|
10
|
-
return mdast;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const internalType = (content: RootContent): string => {
|
|
14
|
-
if (content.type === "heading") return `h${content.depth}`;
|
|
15
|
-
return content.type;
|
|
16
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|