SuperAPI AI 工具集

markitdown

办公与效率

查看项目

更新于 10-15 22:39

技能介绍

用途:把非 Markdown 格式的内容(PDF 报告、Office 文件、网页、数据文件、电子书、图片、音频等)转换为结构清晰的 Markdown,便于阅读或作为 LLM 输入。若文件本身是 .txt、.md 或源码,可直接读取,无需使用本工具。

主要能力:保留标题、表格、列表、链接等结构,而非抓取扁平文本。支持 Office(.docx、.pptx、.xlsx、.xls)、PDF、EPUB、HTML、CSV、JSON、XML、RSS/Atom、Wikipedia 页面、YouTube URL(提取字幕)、图片(EXIF 元数据与 OCR)、音频(元数据与语音转写)、ZIP(递归内容)及 Outlook .msg。转换质量因来源而异,干净的电子版 PDF 与 Office 文件效果较好,扫描件和复杂多栏排版建议使用 Azure Document Intelligence。

使用方式:先检查是否可用:markitdown --version(预期 markitdown 0.1.x)。缺失时用 pip 安装,基础包支持 HTML、CSV/JSON/XML 和基本 Office 文件,[all] 额外支持 PDF、图片 OCR、音频转写等:pip install "markitdown[all]" 或 pip install markitdown。CLI 用法示例:markitdown report.pdf -o report.md、markitdown report.pdf > report.md、markitdown report.pdf、cat report.pdf | markitdown。从 stdin 读取时需用 -x 指定扩展名或用 -m 指定 MIME 类型,否则可能误判格式。常用参数包括 -o/--output、-x/--extension、-m/--mime-type、-c/--charset、-d/--use-docintel、-e/--endpoint、-p/--use-plugins、--list-plugins、--keep-data-uris。无内置递归模式,批量转换可用 shell 循环,例如 find . -name '*.pdf' -print0 | while IFS= read -r -d '' f; do markitdown "$f" -o "${f%.pdf}.md"; done。Python API 示例:from markitdown import MarkItDown; md = MarkItDown(); result = md.convert("report.pdf"); print(result.text_content)。convert() 返回 DocumentConverterResult,Markdown 在 .text_content 中。

高级选项:可传入 OpenAI 兼容客户端生成图片描述(需 OPENAI_API_KEY,会调用付费 API 并发送图片);扫描件或复杂排版可用 Azure Document Intelligence(需 markitdown[az-doc-intel] 与 Azure 凭据)。第三方插件默认未安装,可用 --list-plugins 查看,-p 或 enable_plugins=True 启用。

限制与注意:stdin 必须提供格式提示;出现“no converter for this format”通常说明缺少 [all] 扩展;密钥应放在环境变量中,不要硬编码,未经用户同意不要将敏感文档发送到外部服务;转换后应检查输出,扫描 PDF 和特殊排版可能产生乱码或空内容,需向用户说明。