用途:把已有的 HTML(字符串、文件或单个 URL)一次性转换为 CommonMark Markdown、Djot 或纯文本,并可按需做结构化提取。不涉及 OCR、文档解析或爬取,非 HTML 文档应使用 xberg,批量抓取多页面应使用 crawlberg。
主要能力:单遍转换;约 30 个转换选项(标题样式、代码块样式、输出格式、换行与宽度等);默认提取元数据(标题、描述、语言、charset、Open Graph、headers、链接、图片、JSON-LD/Microdata/RDFa 结构化数据);提取表格(预渲染 Markdown 与结构化单元格网格);提取文档结构树(heading、paragraph、list、table、image、code、quote 等节点);提取内联图片(data URI、SVG);HTML 预处理以清理广告、导航、表单。
使用方式:CLI 一次转换,如 html-to-markdown input.html、-o 输出、从 stdin 读取、--url 抓取 URL;--json 输出完整 ConversionResult,--include-structure 加结构树,--no-content 仅提取,--preprocess --preset aggressive 做清理。SDK 在各语言中以 convert(html, options) 调用,返回统一 ConversionResult(content、metadata、tables、images、document、warnings)。安装可用 brew install xberg-io/tap/html-to-markdown、npx @xberg-io/html-to-markdown-cli、cargo install html-to-markdown-cli,或 pip/npm/cargo/gem/composer/go/dotnet 等包管理器安装对应 SDK。MCP 服务通过 html-to-markdown mcp 暴露 convert_html 与 extract_metadata 工具。
限制:convert() 返回结果对象而非字符串,需访问 .content;--json 输出 JSON 而非 Markdown,需纯 Markdown 时不要加该参数;--include-structure、--extract-inline-images、--no-content 必须配合 --json;转换 CLI 仅支持标志,FILE 为位置参数,唯一子命令是 mcp;--preset、--keep-navigation、--keep-forms 需配合 --preprocess。各语言选项与返回值尽量保持一致,具体签名以官方参考为准。资料未提供收费与价格信息。