@aiquants/html-to-markdown 0.1.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/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/core-C45e4gDg.js +20745 -0
- package/dist/core-D1CksXT5.cjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +5 -0
- package/dist/main.cjs +2 -0
- package/dist/main.d.ts +6 -0
- package/dist/main.js +53 -0
- package/dist/src/browser.d.ts +11 -0
- package/dist/src/cli.d.ts +9 -0
- package/dist/src/converter.d.ts +12 -0
- package/dist/src/core.d.ts +10 -0
- package/dist/src/i18n.d.ts +12 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/plugins/index.d.ts +7 -0
- package/dist/src/plugins/rehype-absolute-links.d.ts +9 -0
- package/dist/src/plugins/rehype-sanitize-html.d.ts +7 -0
- package/dist/src/plugins/rehype-wikipedia-footnotes.d.ts +6 -0
- package/dist/src/types.d.ts +25 -0
- package/dist/tests/100-percent-coverage.test.d.ts +1 -0
- package/dist/tests/100-percent-final.test.d.ts +1 -0
- package/dist/tests/absolute-final-coverage.test.d.ts +1 -0
- package/dist/tests/browser.test.d.ts +1 -0
- package/dist/tests/cli.test.d.ts +1 -0
- package/dist/tests/converter.test.d.ts +1 -0
- package/dist/tests/core.test.d.ts +1 -0
- package/dist/tests/coverage-edge-cases.test.d.ts +1 -0
- package/dist/tests/direct-coverage.test.d.ts +1 -0
- package/dist/tests/final-100-percent.test.d.ts +1 -0
- package/dist/tests/final-coverage.test.d.ts +1 -0
- package/dist/tests/i18n.test.d.ts +1 -0
- package/dist/tests/index.test.d.ts +1 -0
- package/dist/tests/line-70-coverage.test.d.ts +1 -0
- package/dist/tests/main.test.d.ts +1 -0
- package/dist/tests/plugins.test.d.ts +1 -0
- package/dist/tests/rehype-absolute-links.test.d.ts +1 -0
- package/dist/tests/rehype-sanitize-html.test.d.ts +1 -0
- package/dist/tests/rehype-wikipedia-footnotes.test.d.ts +1 -0
- package/dist/tests/types.test.d.ts +1 -0
- package/dist/tests/ultimate-coverage.test.d.ts +1 -0
- package/dist/vite.config.d.ts +2 -0
- package/dist/vitest.config.d.ts +2 -0
- package/package.json +74 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-D1CksXT5.cjs");exports.getMessage=e.getMessage,exports.htmlToMarkdown=e.htmlToMarkdown;
|
package/dist/index.js
ADDED
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;const e=require("./core-D1CksXT5.cjs");var t="undefined"!=typeof document?document.currentScript:null;(("undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("main.cjs",document.baseURI).href).endsWith(process.argv[1])||process.argv[1]&&process.argv[1].includes("vite-node"))&&(async()=>{const t=(await import("yargs-parser")).default,r=await import("node:fs"),c=await import("node:path"),o=t(process.argv.slice(2),{string:["locale"],default:{locale:"en-US"}}),s=o._[0],a=o.locale;s||process.exit(1);try{const t=await e.htmlToMarkdown(s,{locale:a}),o=`${s.replace(/https?:\/\//,"").replace(/[^a-zA-Z0-9]/g,"_")}_${Date.now()}.md`,n=c.join(process.cwd(),".outputs","raw");r.existsSync(n)||r.mkdirSync(n,{recursive:!0});const i=c.join(n,o);r.writeFileSync(i,t)}catch(n){process.exit(1)}})();
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { g as getMessage, h as htmlToMarkdown } from "./core-C45e4gDg.js";
|
|
3
|
+
const runCli = async () => {
|
|
4
|
+
const yargsParser = (await import("yargs-parser")).default;
|
|
5
|
+
const fs = await import("node:fs");
|
|
6
|
+
const path = await import("node:path");
|
|
7
|
+
const argv = yargsParser(process.argv.slice(2), {
|
|
8
|
+
string: ["locale"],
|
|
9
|
+
default: {
|
|
10
|
+
locale: "en-US"
|
|
11
|
+
// デフォルトのロケール
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const targetUrl = argv._[0];
|
|
15
|
+
const locale = argv.locale;
|
|
16
|
+
if (!targetUrl) {
|
|
17
|
+
console.error(getMessage(locale, "error_url_required"));
|
|
18
|
+
console.info(getMessage(locale, "usage"));
|
|
19
|
+
console.info(getMessage(locale, "example"));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
console.info(`
|
|
24
|
+
${getMessage(locale, "cli_start")}`);
|
|
25
|
+
console.info(getMessage(locale, "cli_url", { url: targetUrl }));
|
|
26
|
+
console.info(getMessage(locale, "cli_locale", { locale }));
|
|
27
|
+
const markdown = await htmlToMarkdown(targetUrl, { locale });
|
|
28
|
+
const safeFileName = targetUrl.replace(/https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
29
|
+
const timestamp = Date.now();
|
|
30
|
+
const fileName = `${safeFileName}_${timestamp}.md`;
|
|
31
|
+
const outputDir = path.join(process.cwd(), ".outputs", "raw");
|
|
32
|
+
if (!fs.existsSync(outputDir)) {
|
|
33
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
const filePath = path.join(outputDir, fileName);
|
|
36
|
+
fs.writeFileSync(filePath, markdown);
|
|
37
|
+
console.info(`
|
|
38
|
+
${getMessage(locale, "success_save")}`);
|
|
39
|
+
console.info(getMessage(locale, "success_path", { path: filePath }));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(`
|
|
42
|
+
${getMessage(locale, "error_app")}`, error);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const isDirectRun = (
|
|
47
|
+
// `node dist/main.js` や `npx` 経由での実行を判定
|
|
48
|
+
import.meta.url.endsWith(process.argv[1]) || // `vite-node main.ts` 経由での実行を判定
|
|
49
|
+
process.argv[1] && process.argv[1].includes("vite-node")
|
|
50
|
+
);
|
|
51
|
+
if (isDirectRun) {
|
|
52
|
+
runCli();
|
|
53
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser automation module using Playwright.
|
|
3
|
+
* Playwright を使用したブラウザ自動化モジュール
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Playwrightを使用してURLから動的にレンダリングされたHTMLを取得する
|
|
7
|
+
* @param url 取得対象のURL
|
|
8
|
+
* @param locale ブラウザのロケール
|
|
9
|
+
* @returns HTMLコンテンツ
|
|
10
|
+
*/
|
|
11
|
+
export declare const getHtmlWithPlaywright: (url: string, locale: string) => Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to Markdown conversion module.
|
|
3
|
+
* HTML から Markdown への変換モジュール
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* HTML文字列をMarkdownに変換する
|
|
7
|
+
* @param html HTMLコンテンツ
|
|
8
|
+
* @param baseUrl リンクを絶対パスに変換するためのベースURL
|
|
9
|
+
* @param locale ロケール
|
|
10
|
+
* @returns Markdownテキスト
|
|
11
|
+
*/
|
|
12
|
+
export declare const convertHtmlToMarkdown: (html: string, baseUrl: string, locale: string) => Promise<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HtmlToMarkdownOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts the HTML content of a given URL to Markdown.
|
|
4
|
+
* 指定されたURLのHTMLコンテンツをMarkdownに変換します。
|
|
5
|
+
*
|
|
6
|
+
* @param url The URL of the web page to convert. / 変換対象のWebページのURL。
|
|
7
|
+
* @param options Options for the conversion process. / 変換プロセスのオプション。
|
|
8
|
+
* @returns A promise that resolves to the Markdown string. / Markdown文字列を解決するPromise。
|
|
9
|
+
*/
|
|
10
|
+
export declare const htmlToMarkdown: (url: string, options?: HtmlToMarkdownOptions) => Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MessageKey } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Gets a localized message.
|
|
4
|
+
* ローカライズされたメッセージを取得します。
|
|
5
|
+
* @param locale The locale to use.
|
|
6
|
+
* @param key The message key.
|
|
7
|
+
* @param replacements Optional replacements for placeholders.
|
|
8
|
+
* @returns The localized message string.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getMessage: (locale: string, key: MessageKey, replacements?: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}) => string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rehype plugins index.
|
|
3
|
+
* Rehype プラグインのインデックス
|
|
4
|
+
*/
|
|
5
|
+
export { rehypeSanitizeHtml } from './rehype-sanitize-html.js';
|
|
6
|
+
export { rehypeAbsoluteLinks } from './rehype-absolute-links.js';
|
|
7
|
+
export { rehypeWikipediaFootnotes } from './rehype-wikipedia-footnotes.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Root } from 'hast';
|
|
2
|
+
/**
|
|
3
|
+
* A custom rehype plugin to make relative links absolute for various tags.
|
|
4
|
+
* @param options - The base URL to prepend to relative links.
|
|
5
|
+
* @returns A unified transformer function.
|
|
6
|
+
*/
|
|
7
|
+
export declare const rehypeAbsoluteLinks: (options: {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
}) => (tree: Root) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for htmlToMarkdown module.
|
|
3
|
+
* htmlToMarkdown モジュールの型定義
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Options for the htmlToMarkdown function.
|
|
7
|
+
* htmlToMarkdown 関数のオプション
|
|
8
|
+
*/
|
|
9
|
+
export interface HtmlToMarkdownOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The locale to use for the browser context. Defaults to 'en-US'.
|
|
12
|
+
* ブラウザコンテキストで使用するロケール。デフォルトは 'en-US' です。
|
|
13
|
+
*/
|
|
14
|
+
locale?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Message keys for i18n.
|
|
18
|
+
* i18n 用のメッセージキー
|
|
19
|
+
*/
|
|
20
|
+
export type MessageKey = "error_url_required" | "usage" | "example" | "cli_start" | "cli_url" | "cli_locale" | "success_save" | "success_path" | "error_app" | "playwright_launch" | "playwright_goto" | "playwright_get_content" | "playwright_close" | "playwright_error" | "convert_start" | "convert_success";
|
|
21
|
+
/**
|
|
22
|
+
* Supported locales.
|
|
23
|
+
* サポートされているロケール
|
|
24
|
+
*/
|
|
25
|
+
export type SupportedLocale = "ja-JP" | "en-US";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiquants/html-to-markdown",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "HTML to Markdown converter",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"bin": "./dist/main.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"package.json",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "vite-node main.ts",
|
|
24
|
+
"build": "vite build",
|
|
25
|
+
"lint": "biome lint app/",
|
|
26
|
+
"format": "biome format --write",
|
|
27
|
+
"check": "biome check --fix src/",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"coverage": "vitest run --coverage"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"html",
|
|
33
|
+
"markdown",
|
|
34
|
+
"converter"
|
|
35
|
+
],
|
|
36
|
+
"author": {
|
|
37
|
+
"name": "fehde-k",
|
|
38
|
+
"url": "https://github.com/fehde-k"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"github-slugger": "^2.0.0",
|
|
43
|
+
"hast": "^1.0.0",
|
|
44
|
+
"hast-util-to-html": "^9.0.5",
|
|
45
|
+
"playwright": "^1.54.1",
|
|
46
|
+
"rehype-parse": "^9.0.1",
|
|
47
|
+
"rehype-raw": "^7.0.0",
|
|
48
|
+
"rehype-remark": "^10.0.1",
|
|
49
|
+
"rehype-slug": "^6.0.0",
|
|
50
|
+
"remark-gfm": "^4.0.1",
|
|
51
|
+
"remark-stringify": "^11.0.0",
|
|
52
|
+
"unified": "^11.0.5",
|
|
53
|
+
"unist-util-visit": "^5.0.0",
|
|
54
|
+
"yargs-parser": "^22.0.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@biomejs/biome": "^2.1.3",
|
|
58
|
+
"@types/github-slugger": "^2.0.0",
|
|
59
|
+
"@types/hast": "^3.0.4",
|
|
60
|
+
"@types/mdast": "^4.0.4",
|
|
61
|
+
"@types/node": "^22.16.5",
|
|
62
|
+
"@types/yargs-parser": "^21.0.3",
|
|
63
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
64
|
+
"happy-dom": "^18.0.1",
|
|
65
|
+
"rehype-stringify": "^10.0.1",
|
|
66
|
+
"terser": "^5.43.1",
|
|
67
|
+
"typescript": "^5.8.3",
|
|
68
|
+
"vite": "^7.0.6",
|
|
69
|
+
"vite-node": "^3.2.4",
|
|
70
|
+
"vite-plugin-dts": "^4.5.4",
|
|
71
|
+
"vitest": "^3.2.4",
|
|
72
|
+
"vitest-tsconfig-paths": "^3.4.1"
|
|
73
|
+
}
|
|
74
|
+
}
|