@xberg-io/opencode-html-to-markdown 3.10.4 → 3.11.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.
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
// AI-RULEZ :: GENERATED FILE — DO NOT EDIT
|
|
2
|
-
// Content-Hash: blake3:
|
|
3
|
-
// Source-Hash: blake3:
|
|
2
|
+
// Content-Hash: blake3:764d1087e8dcd39db2f82f8f114e99aab9be9dddce1565d99b6b6b5015c8d6de
|
|
3
|
+
// Source-Hash: blake3:81720b7b3cde96617ee6bd29d153e9486d6b150d1d5e98b94930a16a414f8730
|
|
4
4
|
// Schema-Version: v1
|
|
5
5
|
|
|
6
|
-
import {tool} from "@opencode-ai/plugin";
|
|
7
|
-
import {spawn} from "node:child_process";
|
|
6
|
+
import { tool } from "@opencode-ai/plugin";
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
8
|
|
|
9
9
|
const schema = tool.schema;
|
|
10
10
|
|
|
11
|
-
const headingStyle = schema
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const headingStyle = schema
|
|
12
|
+
.enum(["atx", "underlined", "atx-closed"])
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Markdown heading style. Default: atx.");
|
|
14
15
|
|
|
15
|
-
const codeBlockStyle =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const codeBlockStyle = schema
|
|
17
|
+
.enum(["backticks", "indented", "tildes"])
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("Code block fence style. Default: backticks.");
|
|
19
20
|
|
|
20
|
-
const outputFormat = schema.enum([
|
|
21
|
-
.optional()
|
|
22
|
-
.describe("Output markup format. Default: markdown.");
|
|
21
|
+
const outputFormat = schema.enum(["markdown", "djot"]).optional().describe("Output markup format. Default: markdown.");
|
|
23
22
|
|
|
24
|
-
const preset =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"Preprocessing aggressiveness. Requires `preprocess`. Default: standard.");
|
|
23
|
+
const preset = schema
|
|
24
|
+
.enum(["minimal", "standard", "aggressive"])
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("Preprocessing aggressiveness. Requires `preprocess`. Default: standard.");
|
|
29
27
|
|
|
30
28
|
function hasValue(value) {
|
|
31
29
|
return value !== undefined && value !== null && value !== "";
|
|
@@ -48,10 +46,10 @@ function runCli(args, context, stdin) {
|
|
|
48
46
|
|
|
49
47
|
return new Promise((resolve, reject) => {
|
|
50
48
|
const child = spawn("html-to-markdown", args, {
|
|
51
|
-
cwd
|
|
52
|
-
env
|
|
53
|
-
signal
|
|
54
|
-
stdio
|
|
49
|
+
cwd: directory,
|
|
50
|
+
env: process.env,
|
|
51
|
+
signal: context?.abort,
|
|
52
|
+
stdio: [stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
55
53
|
});
|
|
56
54
|
|
|
57
55
|
const stdout = [];
|
|
@@ -62,10 +60,10 @@ function runCli(args, context, stdin) {
|
|
|
62
60
|
child.on("error", (error) => {
|
|
63
61
|
if (error.code === "ENOENT") {
|
|
64
62
|
resolve({
|
|
65
|
-
title
|
|
66
|
-
output
|
|
67
|
-
|
|
68
|
-
metadata
|
|
63
|
+
title: "html-to-markdown CLI not found",
|
|
64
|
+
output:
|
|
65
|
+
"Install the html-to-markdown CLI with `brew install xberg-io/tap/html-to-markdown`, or run it via `npx -y @xberg-io/html-to-markdown-cli` / `uvx --from html-to-markdown-cli html-to-markdown`.",
|
|
66
|
+
metadata: { exitCode: 127, command: "html-to-markdown" },
|
|
69
67
|
});
|
|
70
68
|
return;
|
|
71
69
|
}
|
|
@@ -74,14 +72,12 @@ function runCli(args, context, stdin) {
|
|
|
74
72
|
child.on("close", (exitCode, signal) => {
|
|
75
73
|
const stdoutText = Buffer.concat(stdout).toString("utf8").trim();
|
|
76
74
|
const stderrText = Buffer.concat(stderr).toString("utf8").trim();
|
|
77
|
-
const output = [
|
|
78
|
-
stdoutText, stderrText && `stderr:\n${stderrText}`
|
|
79
|
-
].filter(Boolean).join("\n\n");
|
|
75
|
+
const output = [stdoutText, stderrText && `stderr:\n${stderrText}`].filter(Boolean).join("\n\n");
|
|
80
76
|
|
|
81
77
|
resolve({
|
|
82
|
-
title
|
|
83
|
-
output
|
|
84
|
-
metadata
|
|
78
|
+
title: exitCode === 0 ? "html-to-markdown" : "html-to-markdown failed",
|
|
79
|
+
output: output || "(no output)",
|
|
80
|
+
metadata: { exitCode, signal, command: "html-to-markdown" },
|
|
85
81
|
});
|
|
86
82
|
});
|
|
87
83
|
|
|
@@ -101,20 +97,17 @@ function styleArgs(args, params) {
|
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
export const HtmlToMarkdownPlugin = async () => ({
|
|
104
|
-
tool
|
|
105
|
-
html_to_markdown_convert
|
|
106
|
-
description
|
|
107
|
-
|
|
108
|
-
args
|
|
109
|
-
path
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
output_format : outputFormat,
|
|
116
|
-
preprocess : schema.boolean().optional().describe(
|
|
117
|
-
"Strip navigation, ads, and forms before converting."),
|
|
100
|
+
tool: {
|
|
101
|
+
html_to_markdown_convert: tool({
|
|
102
|
+
description:
|
|
103
|
+
"Convert an HTML file or HTML string to Markdown (or Djot) with the html-to-markdown CLI. Provide either `path` or `html`.",
|
|
104
|
+
args: {
|
|
105
|
+
path: schema.string().min(1).optional().describe("Path to a local HTML file."),
|
|
106
|
+
html: schema.string().min(1).optional().describe("Inline HTML to convert (used when `path` is omitted)."),
|
|
107
|
+
heading_style: headingStyle,
|
|
108
|
+
code_block_style: codeBlockStyle,
|
|
109
|
+
output_format: outputFormat,
|
|
110
|
+
preprocess: schema.boolean().optional().describe("Strip navigation, ads, and forms before converting."),
|
|
118
111
|
preset,
|
|
119
112
|
},
|
|
120
113
|
async execute(args, context) {
|
|
@@ -131,44 +124,46 @@ export const HtmlToMarkdownPlugin = async () => ({
|
|
|
131
124
|
throw new Error("Provide either `path` or `html`.");
|
|
132
125
|
},
|
|
133
126
|
}),
|
|
134
|
-
html_to_markdown_fetch_url
|
|
135
|
-
description
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
preprocess : schema.boolean().optional().describe(
|
|
143
|
-
"Strip navigation, ads, and forms before converting."),
|
|
127
|
+
html_to_markdown_fetch_url: tool({
|
|
128
|
+
description: "Fetch a URL and convert its HTML to Markdown (or Djot) with the html-to-markdown CLI.",
|
|
129
|
+
args: {
|
|
130
|
+
url: schema.string().min(1).describe("URL to fetch and convert."),
|
|
131
|
+
heading_style: headingStyle,
|
|
132
|
+
code_block_style: codeBlockStyle,
|
|
133
|
+
output_format: outputFormat,
|
|
134
|
+
preprocess: schema.boolean().optional().describe("Strip navigation, ads, and forms before converting."),
|
|
144
135
|
preset,
|
|
145
|
-
user_agent
|
|
146
|
-
"Custom User-Agent header for the fetch."),
|
|
136
|
+
user_agent: schema.string().min(1).optional().describe("Custom User-Agent header for the fetch."),
|
|
147
137
|
},
|
|
148
138
|
async execute(args, context) {
|
|
149
|
-
const cliArgs = [
|
|
139
|
+
const cliArgs = ["--url", args.url];
|
|
150
140
|
pushOption(cliArgs, "--user-agent", args.user_agent);
|
|
151
141
|
styleArgs(cliArgs, args);
|
|
152
142
|
return runCli(cliArgs, context);
|
|
153
143
|
},
|
|
154
144
|
}),
|
|
155
|
-
html_to_markdown_extract
|
|
156
|
-
description
|
|
157
|
-
|
|
158
|
-
args
|
|
159
|
-
path
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
145
|
+
html_to_markdown_extract: tool({
|
|
146
|
+
description:
|
|
147
|
+
"Extract structured metadata, tables, and (optionally) document structure from HTML as JSON. Returns the full ConversionResult. Provide `path`, `html`, or `url`.",
|
|
148
|
+
args: {
|
|
149
|
+
path: schema.string().min(1).optional().describe("Path to a local HTML file."),
|
|
150
|
+
html: schema
|
|
151
|
+
.string()
|
|
152
|
+
.min(1)
|
|
153
|
+
.optional()
|
|
154
|
+
.describe("Inline HTML to analyze (used when `path` and `url` are omitted)."),
|
|
155
|
+
url: schema.string().min(1).optional().describe("URL to fetch and analyze."),
|
|
156
|
+
include_structure: schema
|
|
157
|
+
.boolean()
|
|
158
|
+
.optional()
|
|
159
|
+
.describe("Include the document structure tree in the JSON output."),
|
|
160
|
+
no_content: schema
|
|
161
|
+
.boolean()
|
|
162
|
+
.optional()
|
|
163
|
+
.describe("Suppress the Markdown content field — return metadata/tables/images only."),
|
|
169
164
|
},
|
|
170
165
|
async execute(args, context) {
|
|
171
|
-
const cliArgs = [
|
|
166
|
+
const cliArgs = ["--json"];
|
|
172
167
|
pushFlag(cliArgs, "--include-structure", args.include_structure);
|
|
173
168
|
pushFlag(cliArgs, "--no-content", args.no_content);
|
|
174
169
|
|
package/package.json
CHANGED