webforai 1.3.0 → 1.3.1

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 CHANGED
@@ -15,8 +15,8 @@ A library that provides a web interface for AI
15
15
 
16
16
  There is a demo API for Html2Markdown deployed on CloudflareWorker. Please access the following link
17
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)
18
+ - [NPM Package page](https://webforai.inaridiy.workers.dev/?url=https://www.npmjs.com/package/webforai)
19
+ - [Wikipedia of Cloudflare (AI Mode)](https://webforai.inaridiy.workers.dev/?url=https://en.wikipedia.org/wiki/Cloudflare&mode=ai)
20
20
 
21
21
  ## Quick Start
22
22
 
@@ -34,13 +34,20 @@ import { loadHtml } from "webforai/loaders/playwright";
34
34
  const url = "https://www.npmjs.com/package/webforai";
35
35
  const html = await loadHtml(url);
36
36
 
37
- const markdown = htmlToMarkdown(html, { solveLinks: url });
37
+ const markdown = htmlToMarkdown(html, { baseUrl: url });
38
38
 
39
39
  await fs.writeFile("output.md", markdown);
40
40
  ```
41
41
 
42
42
  other examples are in [examples](./examples/simple/src/index.ts)
43
43
 
44
+ ## Examples
45
+
46
+ - [Simple Example](https://github.com/inaridiy/webforai/tree/main/examples/simple/src/index.ts)
47
+ - [Scraping With ChatGPT API](https://github.com/inaridiy/webforai/blob/main/examples/scraping/src/index.ts)
48
+ - [Translate Markdown with Splitter](https://github.com/inaridiy/webforai/tree/main/examples/translate)
49
+ - [Cloudflare Worker with puppeteer & DO](https://github.com/inaridiy/webforai/tree/main/examples/worker)
50
+
44
51
  ## Usage
45
52
 
46
53
  ### Main Functions
@@ -61,14 +68,3 @@ Convert Mdast to Markdown. If `solveLinks` is specified, the relative links in t
61
68
 
62
69
  **`loadHtml(url: string, options?: LoadHtmlOptions): Promise<string>`**
63
70
  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,26 @@
1
+ "use strict";
2
+ var import_fastest_levenshtein = require("fastest-levenshtein");
3
+ var import_vitest = require("vitest");
4
+ var import_html_to_markdown = require("./html-to-markdown");
5
+ const html = `
6
+ <h1>Hello, world!</h1>
7
+ <p>This is a paragraph.</p>
8
+ <ul>
9
+ <li>Item 1</li>
10
+ <li>Item 2</li>
11
+ </ul>
12
+ `;
13
+ const expected = `# Hello, world!
14
+
15
+ This is a paragraph.
16
+
17
+ * Item 1
18
+ * Item 2
19
+ `;
20
+ (0, import_vitest.describe)("htmlToMarkdown", () => {
21
+ (0, import_vitest.it)("should convert HTML to Markdown", () => {
22
+ const markdown = (0, import_html_to_markdown.htmlToMarkdown)(html, { extractors: false });
23
+ const d = (0, import_fastest_levenshtein.distance)(markdown, expected);
24
+ (0, import_vitest.expect)(d).lte(2);
25
+ });
26
+ });
@@ -0,0 +1,26 @@
1
+ // src/html-to-markdown.test.ts
2
+ import { distance } from "fastest-levenshtein";
3
+ import { describe, expect, it } from "vitest";
4
+ import { htmlToMarkdown } from "./html-to-markdown.js";
5
+ var html = `
6
+ <h1>Hello, world!</h1>
7
+ <p>This is a paragraph.</p>
8
+ <ul>
9
+ <li>Item 1</li>
10
+ <li>Item 2</li>
11
+ </ul>
12
+ `;
13
+ var expected = `# Hello, world!
14
+
15
+ This is a paragraph.
16
+
17
+ * Item 1
18
+ * Item 2
19
+ `;
20
+ describe("htmlToMarkdown", () => {
21
+ it("should convert HTML to Markdown", () => {
22
+ const markdown = htmlToMarkdown(html, { extractors: false });
23
+ const d = distance(markdown, expected);
24
+ expect(d).lte(2);
25
+ });
26
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webforai",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "A library that provides a web interface for AI",
5
5
  "author": "inaridiy",
6
6
  "license": "MIT",
@@ -74,6 +74,7 @@
74
74
  }
75
75
  },
76
76
  "dependencies": {
77
+ "fastest-levenshtein": "^1.0.16",
77
78
  "hast-util-from-html": "^2.0.1",
78
79
  "hast-util-select": "^6.0.1",
79
80
  "hast-util-to-html": "^9.0.0",