Add --dump-markdown flag

Add a new module to handle HTML-to-Markdown conversion and
integrate it into the fetch command via a new CLI flag.
This commit is contained in:
Adrià Arrufat
2026-02-15 23:15:56 +09:00
parent c9433782d8
commit 1b5efea6eb
4 changed files with 306 additions and 2 deletions

View File

@@ -166,6 +166,7 @@ pub const Serve = struct {
pub const Fetch = struct {
url: [:0]const u8,
dump: bool = false,
dump_markdown: bool = false,
common: Common = .{},
withbase: bool = false,
strip: dump.Opts.Strip = .{},
@@ -308,6 +309,9 @@ pub fn printUsageAndExit(self: *const Config, success: bool) void {
\\--dump Dumps document to stdout.
\\ Defaults to false.
\\
\\--dump-markdown Dumps document to stdout as Markdown.
\\ Defaults to false.
\\
\\--strip_mode Comma separated list of tag groups to remove from dump
\\ the dump. e.g. --strip_mode js,css
\\ - "js" script and link[as=script, rel=preload]
@@ -410,6 +414,10 @@ fn inferMode(opt: []const u8) ?RunMode {
return .fetch;
}
if (std.mem.eql(u8, opt, "--dump-markdown")) {
return .fetch;
}
if (std.mem.eql(u8, opt, "--noscript")) {
return .fetch;
}
@@ -547,6 +555,7 @@ fn parseFetchArgs(
args: *std.process.ArgIterator,
) !Fetch {
var fetch_dump: bool = false;
var fetch_dump_markdown: bool = false;
var withbase: bool = false;
var url: ?[:0]const u8 = null;
var common: Common = .{};
@@ -558,6 +567,11 @@ fn parseFetchArgs(
continue;
}
if (std.mem.eql(u8, "--dump-markdown", opt)) {
fetch_dump_markdown = true;
continue;
}
if (std.mem.eql(u8, "--noscript", opt)) {
log.warn(.app, "deprecation warning", .{
.feature = "--noscript argument",
@@ -622,6 +636,7 @@ fn parseFetchArgs(
return .{
.url = url.?,
.dump = fetch_dump,
.dump_markdown = fetch_dump_markdown,
.strip = strip,
.common = common,
.withbase = withbase,