@aiquants/html-to-markdown 0.1.0 → 0.1.2

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/index.cjs CHANGED
@@ -1 +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;
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-C3IjbMzg.cjs");exports.getMessage=o.getMessage,exports.htmlToMarkdown=o.htmlToMarkdown;
package/dist/index.js CHANGED
@@ -1,4 +1,11 @@
1
- import { g, h } from "./core-C45e4gDg.js";
1
+ import { Window } from "happy-dom";
2
+ const window = new Window();
3
+ Object.assign(global, {
4
+ document: window.document,
5
+ window,
6
+ self: window
7
+ });
8
+ import { g, h } from "./core-D07ieSmY.js";
2
9
  export {
3
10
  g as getMessage,
4
11
  h as htmlToMarkdown
package/dist/main.cjs CHANGED
@@ -1,2 +1,2 @@
1
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)}})();
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-C3IjbMzg.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"),c=await import("node:path"),o=e(process.argv.slice(2),{string:["locale"],default:{locale:"en-US"}}),s=o._[0],a=o.locale;s||process.exit(1);try{new URL(s)}catch(n){process.exit(1)}try{const e=await t.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,e)}catch(n){process.exit(1)}})()})();
package/dist/main.js CHANGED
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { g as getMessage, h as htmlToMarkdown } from "./core-C45e4gDg.js";
2
+ import { Window } from "happy-dom";
3
+ const window = new Window();
4
+ Object.assign(global, {
5
+ document: window.document,
6
+ window,
7
+ self: window
8
+ });
9
+ import { g as getMessage, h as htmlToMarkdown } from "./core-D07ieSmY.js";
3
10
  const runCli = async () => {
4
11
  const yargsParser = (await import("yargs-parser")).default;
5
12
  const fs = await import("node:fs");
@@ -19,6 +26,12 @@ const runCli = async () => {
19
26
  console.info(getMessage(locale, "example"));
20
27
  process.exit(1);
21
28
  }
29
+ try {
30
+ new URL(targetUrl);
31
+ } catch (error) {
32
+ console.error(getMessage(locale, "error_app"), error);
33
+ process.exit(1);
34
+ }
22
35
  try {
23
36
  console.info(`
24
37
  ${getMessage(locale, "cli_start")}`);
@@ -43,11 +56,14 @@ ${getMessage(locale, "error_app")}`, error);
43
56
  process.exit(1);
44
57
  }
45
58
  };
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
- }
59
+ const main = async () => {
60
+ const isDirectRun = (
61
+ // `node dist/main.js` や `npx` 経由での実行を判定
62
+ import.meta.url.endsWith(process.argv[1]) || // `vite-node main.ts` 経由での実行を判定
63
+ process.argv[1] && process.argv[1].includes("vite-node")
64
+ );
65
+ if (isDirectRun) {
66
+ runCli();
67
+ }
68
+ };
69
+ main();
@@ -3,10 +3,12 @@
3
3
  * HTML から Markdown への変換モジュール
4
4
  */
5
5
  /**
6
- * HTML文字列をMarkdownに変換する
7
- * @param html HTMLコンテンツ
8
- * @param baseUrl リンクを絶対パスに変換するためのベースURL
9
- * @param locale ロケール
10
- * @returns Markdownテキスト
6
+ * Convert HTML string to Markdown format.
7
+ * HTML 文字列を Markdown 形式に変換する。
8
+ *
9
+ * @param html - The HTML content to convert / 変換する HTML コンテンツ
10
+ * @param baseUrl - Base URL for converting links to absolute paths / リンクを絶対パスに変換するためのベース URL
11
+ * @param locale - Locale setting for internationalization / 国際化のためのロケール設定
12
+ * @returns Promise resolving to Markdown text / Markdown テキストを返す Promise
11
13
  */
12
14
  export declare const convertHtmlToMarkdown: (html: string, baseUrl: string, locale: string) => Promise<string>;
@@ -3,5 +3,5 @@
3
3
  * htmlToMarkdown ライブラリのメインエクスポートモジュール
4
4
  */
5
5
  export { htmlToMarkdown } from './core.js';
6
- export type { HtmlToMarkdownOptions } from './types.js';
7
6
  export { getMessage } from './i18n.js';
7
+ export type { HtmlToMarkdownOptions } from './types.js';
@@ -2,6 +2,6 @@
2
2
  * Rehype plugins index.
3
3
  * Rehype プラグインのインデックス
4
4
  */
5
- export { rehypeSanitizeHtml } from './rehype-sanitize-html.js';
6
5
  export { rehypeAbsoluteLinks } from './rehype-absolute-links.js';
6
+ export { rehypeSanitizeHtml } from './rehype-sanitize-html.js';
7
7
  export { rehypeWikipediaFootnotes } from './rehype-wikipedia-footnotes.js';
@@ -1,3 +1,5 @@
1
+ import { Element, Nodes, Parents } from 'hast';
2
+ import { BlockContent as MdastBlockContent, DefinitionContent as MdastDefinitionContent, Nodes as MdastNodes, Parents as MdastParents, RootContent as MdastRootContent } from 'mdast';
1
3
  /**
2
4
  * Type definitions for htmlToMarkdown module.
3
5
  * htmlToMarkdown モジュールの型定義
@@ -17,9 +19,51 @@ export interface HtmlToMarkdownOptions {
17
19
  * Message keys for i18n.
18
20
  * i18n 用のメッセージキー
19
21
  */
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";
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";
21
23
  /**
22
24
  * Supported locales.
23
25
  * サポートされているロケール
24
26
  */
25
27
  export type SupportedLocale = "ja-JP" | "en-US";
28
+ /**
29
+ * The following types are based on the type definitions of `hast-util-to-mdast`.
30
+ * `hast-util-to-mdast` の型定義に基づいた型。
31
+ *
32
+ * @see https://github.com/syntax-tree/hast-util-to-mdast/blob/main/lib/state.js
33
+ */
34
+ export type State = {
35
+ all: All;
36
+ baseFound: boolean;
37
+ elementById: Map<string, Element>;
38
+ frozenBaseUrl: string | undefined;
39
+ handlers: Record<string, Handle>;
40
+ inTable: boolean;
41
+ nodeHandlers: Record<string, NodeHandle>;
42
+ one: One;
43
+ options: Options;
44
+ patch: Patch;
45
+ qNesting: number;
46
+ resolve: Resolve;
47
+ toFlow: ToFlow;
48
+ toSpecificContent: ToSpecificContent;
49
+ };
50
+ export type MdastFlowContent = MdastBlockContent | MdastDefinitionContent;
51
+ export type All = (parent: Parents) => MdastRootContent[];
52
+ export type Handle = (state: State, element: Element, parent: Parents | undefined) => Array<MdastNodes> | MdastNodes | undefined | void;
53
+ export type NodeHandle = (state: State, node: Nodes, parent: Parents | undefined) => Array<MdastNodes> | MdastNodes | undefined | void;
54
+ export type One = (node: Nodes, parent: Parents | undefined) => Array<MdastNodes> | MdastNodes | undefined;
55
+ export type Options = {
56
+ checked?: string | null;
57
+ document?: boolean | null;
58
+ handlers?: Record<string, Handle | null | undefined> | null;
59
+ newlines?: boolean | null;
60
+ nodeHandlers?: Record<string, NodeHandle | null | undefined> | null;
61
+ quotes?: Array<string> | null;
62
+ unchecked?: string | null;
63
+ };
64
+ export type Patch = (from: Nodes, to: MdastNodes) => undefined;
65
+ export type Resolve = (url: string | null | undefined) => string;
66
+ export type ToFlow = (nodes: MdastRootContent[]) => MdastFlowContent[];
67
+ export type ToSpecificContent = <ChildType extends MdastNodes, ParentType extends MdastParents & {
68
+ children: Array<ChildType>;
69
+ }>(nodes: MdastRootContent[], build: () => ParentType) => ParentType[];
@@ -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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/html-to-markdown",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "HTML to Markdown converter",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,7 +51,8 @@
51
51
  "remark-stringify": "^11.0.0",
52
52
  "unified": "^11.0.5",
53
53
  "unist-util-visit": "^5.0.0",
54
- "yargs-parser": "^22.0.0"
54
+ "yargs-parser": "^22.0.0",
55
+ "happy-dom": "^18.0.1"
55
56
  },
56
57
  "devDependencies": {
57
58
  "@biomejs/biome": "^2.1.3",
@@ -61,7 +62,6 @@
61
62
  "@types/node": "^22.16.5",
62
63
  "@types/yargs-parser": "^21.0.3",
63
64
  "@vitest/coverage-v8": "^3.2.4",
64
- "happy-dom": "^18.0.1",
65
65
  "rehype-stringify": "^10.0.1",
66
66
  "terser": "^5.43.1",
67
67
  "typescript": "^5.8.3",