@aiquants/html-to-markdown 0.1.2 → 0.1.3
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 +15 -3
- package/dist/{core-D07ieSmY.js → core-0q2nkcWH.js} +6 -4
- package/dist/core-DUdcm-c8.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.js +25 -9
- package/dist/src/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/core-C3IjbMzg.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e}),Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./core-
|
|
1
|
+
const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e}),Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./core-DUdcm-c8.cjs");exports.getMessage=o.getMessage,exports.htmlToMarkdown=o.htmlToMarkdown;
|
package/dist/index.js
CHANGED
package/dist/main.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./core-
|
|
2
|
+
Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./core-DUdcm-c8.cjs");var r="undefined"!=typeof document?document.currentScript:null;(async()=>{(("undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("main.cjs",document.baseURI).href).endsWith(process.argv[1])||process.argv[1]&&process.argv[1].includes("vite-node"))&&(async()=>{const e=(await import("yargs-parser")).default,r=await import("node:fs"),o=await import("node:path"),c=e(process.argv.slice(2),{string:["locale","output"],alias:{output:["o"]},default:{locale:"en-US"}}),s=c._[0],n=c.locale,a=c.output;s||process.exit(1);try{new URL(s)}catch(i){process.exit(1)}try{const e=await t.htmlToMarkdown(s,{locale:n});let c;if(a){c=o.resolve(process.cwd(),a);const e=o.dirname(c);r.existsSync(e)||r.mkdirSync(e,{recursive:!0})}else{const e=`${s.replace(/https?:\/\//,"").replace(/[^a-zA-Z0-9]/g,"_")}_${Date.now()}.md`,t=o.join(process.cwd(),".outputs","raw");r.existsSync(t)||r.mkdirSync(t,{recursive:!0}),c=o.join(t,e)}r.writeFileSync(c,e)}catch(i){process.exit(1)}})()})();
|
package/dist/main.js
CHANGED
|
@@ -6,13 +6,16 @@ Object.assign(global, {
|
|
|
6
6
|
window,
|
|
7
7
|
self: window
|
|
8
8
|
});
|
|
9
|
-
import { g as getMessage, h as htmlToMarkdown } from "./core-
|
|
9
|
+
import { g as getMessage, h as htmlToMarkdown } from "./core-0q2nkcWH.js";
|
|
10
10
|
const runCli = async () => {
|
|
11
11
|
const yargsParser = (await import("yargs-parser")).default;
|
|
12
12
|
const fs = await import("node:fs");
|
|
13
13
|
const path = await import("node:path");
|
|
14
14
|
const argv = yargsParser(process.argv.slice(2), {
|
|
15
|
-
string: ["locale"],
|
|
15
|
+
string: ["locale", "output"],
|
|
16
|
+
alias: {
|
|
17
|
+
output: ["o"]
|
|
18
|
+
},
|
|
16
19
|
default: {
|
|
17
20
|
locale: "en-US"
|
|
18
21
|
// デフォルトのロケール
|
|
@@ -20,6 +23,7 @@ const runCli = async () => {
|
|
|
20
23
|
});
|
|
21
24
|
const targetUrl = argv._[0];
|
|
22
25
|
const locale = argv.locale;
|
|
26
|
+
const outputFile = argv.output;
|
|
23
27
|
if (!targetUrl) {
|
|
24
28
|
console.error(getMessage(locale, "error_url_required"));
|
|
25
29
|
console.info(getMessage(locale, "usage"));
|
|
@@ -37,15 +41,27 @@ const runCli = async () => {
|
|
|
37
41
|
${getMessage(locale, "cli_start")}`);
|
|
38
42
|
console.info(getMessage(locale, "cli_url", { url: targetUrl }));
|
|
39
43
|
console.info(getMessage(locale, "cli_locale", { locale }));
|
|
44
|
+
if (outputFile) {
|
|
45
|
+
console.info(getMessage(locale, "cli_output", { path: outputFile }));
|
|
46
|
+
}
|
|
40
47
|
const markdown = await htmlToMarkdown(targetUrl, { locale });
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
let filePath;
|
|
49
|
+
if (outputFile) {
|
|
50
|
+
filePath = path.resolve(process.cwd(), outputFile);
|
|
51
|
+
const outputDir = path.dirname(filePath);
|
|
52
|
+
if (!fs.existsSync(outputDir)) {
|
|
53
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
const safeFileName = targetUrl.replace(/https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
57
|
+
const timestamp = Date.now();
|
|
58
|
+
const fileName = `${safeFileName}_${timestamp}.md`;
|
|
59
|
+
const outputDir = path.join(process.cwd(), ".outputs", "raw");
|
|
60
|
+
if (!fs.existsSync(outputDir)) {
|
|
61
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
filePath = path.join(outputDir, fileName);
|
|
47
64
|
}
|
|
48
|
-
const filePath = path.join(outputDir, fileName);
|
|
49
65
|
fs.writeFileSync(filePath, markdown);
|
|
50
66
|
console.info(`
|
|
51
67
|
${getMessage(locale, "success_save")}`);
|
package/dist/src/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface HtmlToMarkdownOptions {
|
|
|
19
19
|
* Message keys for i18n.
|
|
20
20
|
* i18n 用のメッセージキー
|
|
21
21
|
*/
|
|
22
|
-
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" | "url_parse_error";
|
|
22
|
+
export type MessageKey = "error_url_required" | "usage" | "example" | "cli_start" | "cli_url" | "cli_locale" | "cli_output" | "success_save" | "success_path" | "error_app" | "playwright_launch" | "playwright_goto" | "playwright_get_content" | "playwright_close" | "playwright_error" | "convert_start" | "convert_success" | "url_parse_error";
|
|
23
23
|
/**
|
|
24
24
|
* Supported locales.
|
|
25
25
|
* サポートされているロケール
|