webforai 1.1.2 → 1.1.4
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/LICENSE +21 -21
- package/README.md +74 -74
- package/dist/cjs/extract-hast/index.js +22 -0
- package/dist/cjs/{extract-hast.js → extract-hast/strongly.js} +35 -9
- package/dist/cjs/html-to-mdast.js +2 -1
- package/dist/cjs/loaders/playwright.js +1 -1
- package/dist/cjs/mdast-handlers/custom-a-handler.js +1 -2
- package/dist/cjs/mdast-handlers/custom-div-handler.js +6 -3
- package/dist/cjs/mdast-to-markdown.js +2 -2
- package/dist/cjs/package.json +1 -1
- package/dist/extract-hast/index.js +2 -0
- package/dist/extract-hast/strongly.js +52 -0
- package/dist/html-to-mdast.js +3 -2
- package/dist/loaders/playwright.js +1 -1
- package/dist/mdast-handlers/custom-a-handler.js +1 -2
- package/dist/mdast-handlers/custom-div-handler.js +6 -3
- package/dist/mdast-to-markdown.js +2 -2
- package/dist/types/extract-hast/index.d.ts +1 -0
- package/dist/types/extract-hast/index.js.map +1 -0
- package/dist/types/extract-hast/strongly.d.ts +2 -0
- package/dist/types/extract-hast/strongly.js.map +1 -0
- package/dist/types/html-to-markdown.d.ts +1 -1
- package/dist/types/html-to-mdast.d.ts +1 -1
- package/dist/types/html-to-mdast.js.map +1 -1
- package/dist/types/loaders/playwright.js.map +1 -1
- package/dist/types/mdast-handlers/custom-a-handler.js.map +1 -1
- package/dist/types/mdast-handlers/custom-div-handler.js.map +1 -1
- package/dist/types/mdast-to-markdown.d.ts +1 -1
- package/dist/types/mdast-to-markdown.js.map +1 -1
- package/dist/types/package.json +1 -1
- package/package.json +2 -5
- package/dist/extract-hast.js +0 -26
- package/dist/types/extract-hast.d.ts +0 -2
- package/dist/types/extract-hast.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 inaridiy
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 inaridiy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
# Web for AI
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
A library that provides a web interface for AI
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- Ultra-precise HTML2Markdown conversion
|
|
10
|
-
- Ultra-precise Markdown segmentation based on AST
|
|
11
|
-
- Ultra-precise HTML retrieval functions using headless browsers
|
|
12
|
-
- The core functionality is edge-native (runs on Cloudflare Workers!!!)
|
|
13
|
-
|
|
14
|
-
## Demo
|
|
15
|
-
|
|
16
|
-
There is a demo API for Html2Markdown deployed on CloudflareWorker. Please access the following link
|
|
17
|
-
|
|
18
|
-
- [https://
|
|
19
|
-
- [https://
|
|
20
|
-
|
|
21
|
-
## Quick Start
|
|
22
|
-
|
|
23
|
-
Just install and execute scripts
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
pnpm i webforai playwright
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
import { promises as fs } from "fs";
|
|
31
|
-
import { htmlToMarkdown, htmlToMdast } from "webforai";
|
|
32
|
-
import { loadHtml } from "webforai/loaders/playwright";
|
|
33
|
-
|
|
34
|
-
const url = "https://www.npmjs.com/package/webforai";
|
|
35
|
-
const html = await loadHtml(url);
|
|
36
|
-
|
|
37
|
-
const markdown = htmlToMarkdown(html, { solveLinks: url });
|
|
38
|
-
|
|
39
|
-
await fs.writeFile("output.md", markdown);
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
other examples are in [examples](./examples/src/index.ts)
|
|
43
|
-
|
|
44
|
-
## Usage
|
|
45
|
-
|
|
46
|
-
### Main Functions
|
|
47
|
-
|
|
48
|
-
**`htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions): string`**
|
|
49
|
-
Convert HTML to Markdown. By default, unnecessary HTML is excluded and processed.
|
|
50
|
-
If `solveLinks` is specified, the relative links in the Mdast will be resolved.
|
|
51
|
-
This function just calls htmlToMdast and mdastToMarkdown in that order internally.
|
|
52
|
-
|
|
53
|
-
**`htmlToMdast(html: string, options?: HtmlToMdastOptions): Mdast`**
|
|
54
|
-
This project uses Hast and Mdast as defined by syntax-tree internally.
|
|
55
|
-
This function converts HTML to Mdast, an intermediate representation, which is required when using `mdastSplitter`, etc.
|
|
56
|
-
|
|
57
|
-
**`mdastToMarkdown(mdast: Mdast | RootContent[], options?: { solveLinks?: string }): string`**
|
|
58
|
-
Convert Mdast to Markdown. If `solveLinks` is specified, the relative links in the Mdast will be resolved.
|
|
59
|
-
|
|
60
|
-
### Loader Functions
|
|
61
|
-
|
|
62
|
-
**`loadHtml(url: string, options?: LoadHtmlOptions): Promise<string>`**
|
|
63
|
-
Load HTML from the specified URL. This function uses Playwright internally.
|
|
64
|
-
|
|
65
|
-
## Early Users
|
|
66
|
-
|
|
67
|
-
### Voice Genius - Explanatory video generation by AI
|
|
68
|
-
|
|
69
|
-
<img src="https://github.com/inaridiy/webforai/blob/main/images/voice-genius.png" width="300px">
|
|
70
|
-
|
|
71
|
-
by [@moons14](https://twitter.com/moons_dev)
|
|
72
|
-
|
|
73
|
-
AI can be used to automatically generate highly accurate commentary videos.
|
|
74
|
-
Supports conversations and presentations using synthesized voice, embedding of images in videos, etc.
|
|
1
|
+
# Web for AI
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
A library that provides a web interface for AI
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Ultra-precise HTML2Markdown conversion
|
|
10
|
+
- Ultra-precise Markdown segmentation based on AST
|
|
11
|
+
- Ultra-precise HTML retrieval functions using headless browsers
|
|
12
|
+
- The core functionality is edge-native (runs on Cloudflare Workers!!!)
|
|
13
|
+
|
|
14
|
+
## Demo
|
|
15
|
+
|
|
16
|
+
There is a demo API for Html2Markdown deployed on CloudflareWorker. Please access the following link
|
|
17
|
+
|
|
18
|
+
- [https://webforai.inaridiy.workers.dev/?url=https://www.npmjs.com/package/webforai](https://webforai.inaridiy.workers.dev/?url=https://www.npmjs.com/package/webforai)
|
|
19
|
+
- [https://webforai.inaridiy.workers.dev/?html=%3Ch1%3EHello%20World%3C/h1%3E](https://webforai.inaridiy.workers.dev/?html=%3Ch1%3EHello%20World%3C/h1%3E)
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
Just install and execute scripts
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm i webforai playwright
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { promises as fs } from "fs";
|
|
31
|
+
import { htmlToMarkdown, htmlToMdast } from "webforai";
|
|
32
|
+
import { loadHtml } from "webforai/loaders/playwright";
|
|
33
|
+
|
|
34
|
+
const url = "https://www.npmjs.com/package/webforai";
|
|
35
|
+
const html = await loadHtml(url);
|
|
36
|
+
|
|
37
|
+
const markdown = htmlToMarkdown(html, { solveLinks: url });
|
|
38
|
+
|
|
39
|
+
await fs.writeFile("output.md", markdown);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
other examples are in [examples](./examples/simple/src/index.ts)
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### Main Functions
|
|
47
|
+
|
|
48
|
+
**`htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions): string`**
|
|
49
|
+
Convert HTML to Markdown. By default, unnecessary HTML is excluded and processed.
|
|
50
|
+
If `solveLinks` is specified, the relative links in the Mdast will be resolved.
|
|
51
|
+
This function just calls htmlToMdast and mdastToMarkdown in that order internally.
|
|
52
|
+
|
|
53
|
+
**`htmlToMdast(html: string, options?: HtmlToMdastOptions): Mdast`**
|
|
54
|
+
This project uses Hast and Mdast as defined by syntax-tree internally.
|
|
55
|
+
This function converts HTML to Mdast, an intermediate representation, which is required when using `mdastSplitter`, etc.
|
|
56
|
+
|
|
57
|
+
**`mdastToMarkdown(mdast: Mdast | RootContent[], options?: { solveLinks?: string }): string`**
|
|
58
|
+
Convert Mdast to Markdown. If `solveLinks` is specified, the relative links in the Mdast will be resolved.
|
|
59
|
+
|
|
60
|
+
### Loader Functions
|
|
61
|
+
|
|
62
|
+
**`loadHtml(url: string, options?: LoadHtmlOptions): Promise<string>`**
|
|
63
|
+
Load HTML from the specified URL. This function uses Playwright internally.
|
|
64
|
+
|
|
65
|
+
## Early Users
|
|
66
|
+
|
|
67
|
+
### Voice Genius - Explanatory video generation by AI
|
|
68
|
+
|
|
69
|
+
<img src="https://github.com/inaridiy/webforai/blob/main/images/voice-genius.png" width="300px">
|
|
70
|
+
|
|
71
|
+
by [@moons14](https://twitter.com/moons_dev)
|
|
72
|
+
|
|
73
|
+
AI can be used to automatically generate highly accurate commentary videos.
|
|
74
|
+
Supports conversations and presentations using synthesized voice, embedding of images in videos, etc.
|
|
@@ -0,0 +1,22 @@
|
|
|
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 extract_hast_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(extract_hast_exports);
|
|
18
|
+
__reExport(extract_hast_exports, require("./strongly"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./strongly")
|
|
22
|
+
});
|
|
@@ -16,16 +16,34 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var strongly_exports = {};
|
|
20
|
+
__export(strongly_exports, {
|
|
21
|
+
stronglyExtractHast: () => stronglyExtractHast
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(strongly_exports);
|
|
24
24
|
var import_hast_util_select = require("hast-util-select");
|
|
25
|
+
var import_hast_util_to_text = require("hast-util-to-text");
|
|
25
26
|
var import_unist_util_filter = require("unist-util-filter");
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const evaluateTextComplexity = (text) => {
|
|
28
|
+
const words = text.trim().split(/\s+/);
|
|
29
|
+
const wordCount = words.length;
|
|
30
|
+
const charCount = text.length;
|
|
31
|
+
const avgWordLength = charCount / wordCount;
|
|
32
|
+
const uniqueWords = new Set(words);
|
|
33
|
+
const uniqueWordCount = uniqueWords.size;
|
|
34
|
+
const complexityScore = avgWordLength * 0.4 + uniqueWordCount / wordCount * 100 * 0.6;
|
|
35
|
+
return {
|
|
36
|
+
wordCount,
|
|
37
|
+
charCount,
|
|
38
|
+
avgWordLength,
|
|
39
|
+
uniqueWordCount,
|
|
40
|
+
complexityScore
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const REMOVE_REGEX = /icon|header|nav|speechify-ignore|assist|-ad-|banner|combx|comment|com-|contact|foot|footer|footnote|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|assist|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i;
|
|
44
|
+
const HIDDEN_REGEX = /hidden|^hid$| hid$| hid |^hid /i;
|
|
45
|
+
const stronglyExtractHast = (hast) => {
|
|
46
|
+
const selectors = ["article", "#article", "#content", "main", "div.container"];
|
|
29
47
|
let selectedElement = hast;
|
|
30
48
|
for (const selector of selectors) {
|
|
31
49
|
const element = (0, import_hast_util_select.select)(selector, hast);
|
|
@@ -35,15 +53,23 @@ const extractHast = (hast) => {
|
|
|
35
53
|
}
|
|
36
54
|
}
|
|
37
55
|
const removedElements = (0, import_unist_util_filter.filter)(selectedElement, (node) => {
|
|
56
|
+
if (node.type === "comment")
|
|
57
|
+
return false;
|
|
38
58
|
if (node.type !== "element")
|
|
39
59
|
return true;
|
|
40
60
|
const element = node;
|
|
41
61
|
const elementName = `${element.tagName} ${element.properties.id} ${element.properties.className}`;
|
|
42
|
-
|
|
62
|
+
if (REMOVE_REGEX.test(elementName))
|
|
63
|
+
return false;
|
|
64
|
+
const isHidden = HIDDEN_REGEX.test(elementName);
|
|
65
|
+
const complexity = evaluateTextComplexity((0, import_hast_util_to_text.toText)(element));
|
|
66
|
+
if (isHidden && complexity.complexityScore < 40)
|
|
67
|
+
return false;
|
|
68
|
+
return true;
|
|
43
69
|
});
|
|
44
70
|
return removedElements;
|
|
45
71
|
};
|
|
46
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
73
|
0 && (module.exports = {
|
|
48
|
-
|
|
74
|
+
stronglyExtractHast
|
|
49
75
|
});
|
|
@@ -28,8 +28,9 @@ var import_custom_a_handler = require("./mdast-handlers/custom-a-handler");
|
|
|
28
28
|
var import_custom_div_handler = require("./mdast-handlers/custom-div-handler");
|
|
29
29
|
var import_math_handler = require("./mdast-handlers/math-handler");
|
|
30
30
|
const htmlToMdast = (html, options) => {
|
|
31
|
+
const { extractHast = "strongly" } = options || {};
|
|
31
32
|
const hast = (0, import_hast_util_from_html.fromHtml)(html, { fragment: true });
|
|
32
|
-
const extractedHast =
|
|
33
|
+
const extractedHast = extractHast === "strongly" ? (0, import_extract_hast.stronglyExtractHast)(hast) : typeof extractHast === "function" ? extractHast(hast) : hast;
|
|
33
34
|
const mdast = (0, import_hast_util_to_mdast.toMdast)(extractedHast, {
|
|
34
35
|
handlers: { div: import_custom_div_handler.customDivHandler, math: import_math_handler.mathHandler, a: import_custom_a_handler.customAHandler, br: () => {
|
|
35
36
|
} }
|
|
@@ -37,7 +37,7 @@ const loadHtml = async (url, context) => {
|
|
|
37
37
|
let _browser = null;
|
|
38
38
|
let _context;
|
|
39
39
|
if (!context) {
|
|
40
|
-
_browser = await playwright.chromium.launch();
|
|
40
|
+
_browser = await playwright.chromium.launch({ headless: false });
|
|
41
41
|
_context = await _browser.newContext();
|
|
42
42
|
} else {
|
|
43
43
|
_context = context;
|
|
@@ -26,8 +26,7 @@ const customAHandler = (state, node) => {
|
|
|
26
26
|
const link = import_hast_util_to_mdast.defaultHandlers.a(state, node);
|
|
27
27
|
if (link.children.length > 0)
|
|
28
28
|
return link;
|
|
29
|
-
|
|
30
|
-
return void 0;
|
|
29
|
+
return void 0;
|
|
31
30
|
};
|
|
32
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
32
|
0 && (module.exports = {
|
|
@@ -31,13 +31,16 @@ const customDivHandler = (state, node) => {
|
|
|
31
31
|
if (String(className) === "highlight-text-html-basic") {
|
|
32
32
|
highlightLanguage = "html";
|
|
33
33
|
break;
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
|
+
if (String(className).includes("highlight-source-")) {
|
|
35
36
|
highlightLanguage = String(className).slice("highlight-source-".length);
|
|
36
37
|
break;
|
|
37
|
-
}
|
|
38
|
+
}
|
|
39
|
+
if (String(className).includes("language-")) {
|
|
38
40
|
highlightLanguage = String(className).slice("language-".length);
|
|
39
41
|
break;
|
|
40
|
-
}
|
|
42
|
+
}
|
|
43
|
+
if (String(className).includes("code-block_wrapper")) {
|
|
41
44
|
const text = (0, import_hast_util_to_text.toText)(node);
|
|
42
45
|
if (!text.includes("."))
|
|
43
46
|
break;
|
|
@@ -30,8 +30,8 @@ const mdastToMarkdown = (mdast, options) => {
|
|
|
30
30
|
let markdown = (0, import_mdast_util_to_markdown.toMarkdown)((0, import_mdast_utils.warpRoot)(mdast), {
|
|
31
31
|
extensions: [(0, import_mdast_util_gfm.gfmToMarkdown)(), (0, import_mdast_util_math.mathToMarkdown)()]
|
|
32
32
|
});
|
|
33
|
-
if (options?.
|
|
34
|
-
markdown = (0, import_link_replacer.linkReplacer)(markdown, options.
|
|
33
|
+
if (options?.url)
|
|
34
|
+
markdown = (0, import_link_replacer.linkReplacer)(markdown, options.url);
|
|
35
35
|
return markdown;
|
|
36
36
|
};
|
|
37
37
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/package.json
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/extract-hast/strongly.ts
|
|
2
|
+
import { select } from "hast-util-select";
|
|
3
|
+
import { toText } from "hast-util-to-text";
|
|
4
|
+
import { filter } from "unist-util-filter";
|
|
5
|
+
var evaluateTextComplexity = (text) => {
|
|
6
|
+
const words = text.trim().split(/\s+/);
|
|
7
|
+
const wordCount = words.length;
|
|
8
|
+
const charCount = text.length;
|
|
9
|
+
const avgWordLength = charCount / wordCount;
|
|
10
|
+
const uniqueWords = new Set(words);
|
|
11
|
+
const uniqueWordCount = uniqueWords.size;
|
|
12
|
+
const complexityScore = avgWordLength * 0.4 + uniqueWordCount / wordCount * 100 * 0.6;
|
|
13
|
+
return {
|
|
14
|
+
wordCount,
|
|
15
|
+
charCount,
|
|
16
|
+
avgWordLength,
|
|
17
|
+
uniqueWordCount,
|
|
18
|
+
complexityScore
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var REMOVE_REGEX = /icon|header|nav|speechify-ignore|assist|-ad-|banner|combx|comment|com-|contact|foot|footer|footnote|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|assist|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i;
|
|
22
|
+
var HIDDEN_REGEX = /hidden|^hid$| hid$| hid |^hid /i;
|
|
23
|
+
var stronglyExtractHast = (hast) => {
|
|
24
|
+
const selectors = ["article", "#article", "#content", "main", "div.container"];
|
|
25
|
+
let selectedElement = hast;
|
|
26
|
+
for (const selector of selectors) {
|
|
27
|
+
const element = select(selector, hast);
|
|
28
|
+
if (element) {
|
|
29
|
+
selectedElement = element;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const removedElements = filter(selectedElement, (node) => {
|
|
34
|
+
if (node.type === "comment")
|
|
35
|
+
return false;
|
|
36
|
+
if (node.type !== "element")
|
|
37
|
+
return true;
|
|
38
|
+
const element = node;
|
|
39
|
+
const elementName = `${element.tagName} ${element.properties.id} ${element.properties.className}`;
|
|
40
|
+
if (REMOVE_REGEX.test(elementName))
|
|
41
|
+
return false;
|
|
42
|
+
const isHidden = HIDDEN_REGEX.test(elementName);
|
|
43
|
+
const complexity = evaluateTextComplexity(toText(element));
|
|
44
|
+
if (isHidden && complexity.complexityScore < 40)
|
|
45
|
+
return false;
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
return removedElements;
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
stronglyExtractHast
|
|
52
|
+
};
|
package/dist/html-to-mdast.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// src/html-to-mdast.ts
|
|
2
2
|
import { fromHtml } from "hast-util-from-html";
|
|
3
3
|
import { toMdast } from "hast-util-to-mdast";
|
|
4
|
-
import {
|
|
4
|
+
import { stronglyExtractHast } from "./extract-hast/index.js";
|
|
5
5
|
import { customAHandler } from "./mdast-handlers/custom-a-handler.js";
|
|
6
6
|
import { customDivHandler } from "./mdast-handlers/custom-div-handler.js";
|
|
7
7
|
import { mathHandler } from "./mdast-handlers/math-handler.js";
|
|
8
8
|
var htmlToMdast = (html, options) => {
|
|
9
|
+
const { extractHast = "strongly" } = options || {};
|
|
9
10
|
const hast = fromHtml(html, { fragment: true });
|
|
10
|
-
const extractedHast =
|
|
11
|
+
const extractedHast = extractHast === "strongly" ? stronglyExtractHast(hast) : typeof extractHast === "function" ? extractHast(hast) : hast;
|
|
11
12
|
const mdast = toMdast(extractedHast, {
|
|
12
13
|
handlers: { div: customDivHandler, math: mathHandler, a: customAHandler, br: () => {
|
|
13
14
|
} }
|
|
@@ -5,7 +5,7 @@ var loadHtml = async (url, context) => {
|
|
|
5
5
|
let _browser = null;
|
|
6
6
|
let _context;
|
|
7
7
|
if (!context) {
|
|
8
|
-
_browser = await playwright.chromium.launch();
|
|
8
|
+
_browser = await playwright.chromium.launch({ headless: false });
|
|
9
9
|
_context = await _browser.newContext();
|
|
10
10
|
} else {
|
|
11
11
|
_context = context;
|
|
@@ -9,13 +9,16 @@ var customDivHandler = (state, node) => {
|
|
|
9
9
|
if (String(className) === "highlight-text-html-basic") {
|
|
10
10
|
highlightLanguage = "html";
|
|
11
11
|
break;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
if (String(className).includes("highlight-source-")) {
|
|
13
14
|
highlightLanguage = String(className).slice("highlight-source-".length);
|
|
14
15
|
break;
|
|
15
|
-
}
|
|
16
|
+
}
|
|
17
|
+
if (String(className).includes("language-")) {
|
|
16
18
|
highlightLanguage = String(className).slice("language-".length);
|
|
17
19
|
break;
|
|
18
|
-
}
|
|
20
|
+
}
|
|
21
|
+
if (String(className).includes("code-block_wrapper")) {
|
|
19
22
|
const text = toText(node);
|
|
20
23
|
if (!text.includes("."))
|
|
21
24
|
break;
|
|
@@ -8,8 +8,8 @@ var mdastToMarkdown = (mdast, options) => {
|
|
|
8
8
|
let markdown = toMarkdown(warpRoot(mdast), {
|
|
9
9
|
extensions: [gfmToMarkdown(), mathToMarkdown()]
|
|
10
10
|
});
|
|
11
|
-
if (options?.
|
|
12
|
-
markdown = linkReplacer(markdown, options.
|
|
11
|
+
if (options?.url)
|
|
12
|
+
markdown = linkReplacer(markdown, options.url);
|
|
13
13
|
return markdown;
|
|
14
14
|
};
|
|
15
15
|
export {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./strongly";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extract-hast/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongly.js","sourceRoot":"","sources":["../../../src/extract-hast/strongly.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;IAE/B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;IAE9B,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,CAAC;IAE5C,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,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Y,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3D,IAAI,QAAQ,IAAI,UAAU,CAAC,eAAe,GAAG,EAAE;YAAE,OAAO,KAAK,CAAC;QAC9D,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,OAAO,eAAuB,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Root as Hast } from "hast";
|
|
2
2
|
export interface HtmlToMarkdownOptions {
|
|
3
3
|
extractHast?: false | ((hast: Hast) => Hast);
|
|
4
|
-
|
|
4
|
+
url?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare const htmlToMarkdown: (html: string, options?: HtmlToMarkdownOptions) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Root as Hast } from "hast";
|
|
2
2
|
import type { Nodes as Mdast } from "mdast";
|
|
3
3
|
export type HtmlToMdastOptions = {
|
|
4
|
-
extractHast?: false | ((hast: Hast) => Hast);
|
|
4
|
+
extractHast?: false | ((hast: Hast) => Hast) | "strongly";
|
|
5
5
|
};
|
|
6
6
|
export declare const htmlToMdast: (html: string, options?: HtmlToMdastOptions) => Mdast;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-to-mdast.js","sourceRoot":"","sources":["../../src/html-to-mdast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"html-to-mdast.js","sourceRoot":"","sources":["../../src/html-to-mdast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7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AAE,CAAC;IACnB,IAAI,QAAQ;QAAE,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IACrC,OAAO,IAAI,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-a-handler.js","sourceRoot":"","sources":["../../../src/mdast-handlers/custom-a-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElE,MAAM,CAAC,MAAM,cAAc,GAAW,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACrD,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC
|
|
1
|
+
{"version":3,"file":"custom-a-handler.js","sourceRoot":"","sources":["../../../src/mdast-handlers/custom-a-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElE,MAAM,CAAC,MAAM,cAAc,GAAW,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACrD,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-div-handler.js","sourceRoot":"","sources":["../../../src/mdast-handlers/custom-div-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,CAAC,MAAM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AAO,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdast-to-markdown.js","sourceRoot":"","sources":["../../src/mdast-to-markdown.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAA4B,EAAE,
|
|
1
|
+
{"version":3,"file":"mdast-to-markdown.js","sourceRoot":"","sources":["../../src/mdast-to-markdown.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAA4B,EAAE,OAA0B,EAAU,EAAE;IACnG,IAAI,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC1C,UAAU,EAAE,CAAC,aAAa,EAAE,EAAE,cAAc,EAAE,CAAC;KAC/C,CAAC,CAAC;IAEH,IAAI,OAAO,EAAE,GAAG;QAAE,QAAQ,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAEjE,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
|
package/dist/types/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webforai",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "A library that provides a web interface for AI",
|
|
5
5
|
"author": "inaridiy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"playwright": "^1.
|
|
57
|
+
"playwright": "^1.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"playwright": {
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"unist-util-remove": "^4.0.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@biomejs/biome": "1.3.3",
|
|
81
80
|
"@tsconfig/recommended": "^1.0.3",
|
|
82
81
|
"@types/hast": "^3.0.2",
|
|
83
82
|
"@types/mdast": "^4.0.2",
|
|
@@ -97,8 +96,6 @@
|
|
|
97
96
|
"clean": "rimraf dist",
|
|
98
97
|
"build": "pnpm clean && tsx ./build.ts && pnpm copy:package.cjs.json",
|
|
99
98
|
"test": "echo \"Error: no test specified\"",
|
|
100
|
-
"format": "biome format . --write",
|
|
101
|
-
"lint": "biome check .",
|
|
102
99
|
"prerelease": "pnpm build",
|
|
103
100
|
"release": "np"
|
|
104
101
|
}
|
package/dist/extract-hast.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// src/extract-hast.ts
|
|
2
|
-
import { select } from "hast-util-select";
|
|
3
|
-
import { filter } from "unist-util-filter";
|
|
4
|
-
var REMOVE_REGEX = /header|nav|speechify-ignore|assist|-ad-|hidden|^hid$| hid$| hid |^hid |banner|combx|comment|com-|contact|foot|footer|footnote|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|assist|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i;
|
|
5
|
-
var extractHast = (hast) => {
|
|
6
|
-
const selectors = ["article", "div#article", "main", "div.container"];
|
|
7
|
-
let selectedElement = hast;
|
|
8
|
-
for (const selector of selectors) {
|
|
9
|
-
const element = select(selector, hast);
|
|
10
|
-
if (element) {
|
|
11
|
-
selectedElement = element;
|
|
12
|
-
break;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const removedElements = filter(selectedElement, (node) => {
|
|
16
|
-
if (node.type !== "element")
|
|
17
|
-
return true;
|
|
18
|
-
const element = node;
|
|
19
|
-
const elementName = `${element.tagName} ${element.properties.id} ${element.properties.className}`;
|
|
20
|
-
return !REMOVE_REGEX.test(elementName);
|
|
21
|
-
});
|
|
22
|
-
return removedElements;
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
extractHast
|
|
26
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract-hast.js","sourceRoot":"","sources":["../../src/extract-hast.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,YAAY,GACjB,kQAAkQ,CAAC;AAEpQ,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAU,EAAE,EAAE;IACzC,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;IACtE,IAAI,eAAe,GAAG,IAAI,CAAC;IAC3B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACvC,IAAI,OAAO,EAAE,CAAC;YACb,eAAe,GAAG,OAAO,CAAC;YAC1B,MAAM;QACP,CAAC;IACF,CAAC;IAED,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;QACxD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACzC,MAAM,OAAO,GAAG,IAAe,CAAC;QAChC,MAAM,WAAW,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,EAAE,IAAI,OAAO,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAClG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC;AACxB,CAAC,CAAC"}
|