在处理大量文档时,尤其是在构建知识库、进行文档分析或训练大语言模型(LLM)时,将各种格式的文件(如 PDF、Word、Excel、PPT、HTML 等)转换为统一的 Markdown 格式,能够显著提高处理效率和兼容性。Microsoft 的开源项目 MarkItDown 正是为此目的而生。

什么是 MarkItDown?

MarkItDown 是一个轻量级的 Python 工具,旨在将多种文件格式转换为 Markdown 格式,特别适用于 LLM 和相关的文本分析管道。与 Pandoc 等工具相比,MarkItDown 更加专注于保留文档的结构和内容,如标题、列表、表格、链接等,输出的 Markdown 格式既适合人类阅读,也适合机器处理

为什么选择 MarkItDown?

1. 多格式支持

MarkItDown 支持从多种格式转换为 Markdown,包括:

  • PDF

  • PowerPoint(PPTX)

  • Word(DOCX)

  • Excel(XLSX)

  • 图片(包括 EXIF 元数据和 OCR)

  • 音频(包括 EXIF 元数据和语音转录)

  • HTML

  • 文本格式(如 CSV、JSON、XML)

  • ZIP 文件(迭代处理其中的内容)

  • YouTube URL

  • EPUB

  • 以及更多

这种广泛的格式支持使得 MarkItDown 成为处理各种文档的利器。

html -> md ,内部转换是markdownify

2. 专为 LLM 优化

MarkItDown 输出的 Markdown 格式经过优化,适合用于 LLM 的输入,能够有效利用 LLM 的上下文窗口。此外,MarkItDown 还提供了 MCP(Model Context Protocol)服务器,支持与 LLM 的实时集成,例如与 Claude Desktop 的集成。

3. 强大的插件系统

MarkItDown 提供了插件系统,用户可以根据需要扩展功能。例如,有用户开发了插件来处理 DOCX 文件,并将其中的图片提取到指定文件夹中。

如何使用 MarkItDown?

安装 MarkItDown

使用 pip 安装:

pip install markitdown

如果想安装全部功能(支持更多格式和插件):

pip install 'markitdown[all]'

基本用法

假设你有一个 Word 文件 example.docx,想把它转换为 Markdown:

markitdown example.docx

输出内容会在终端显示。如果想保存为文件:

markitdown example.docx > example.md

python 代码

from markitdown import MarkItDownmd = MarkItDown(enable_plugins=False) # Set to True to enable plugins
result = md.convert("example.docx")
print(result.text_content)

example.docx

转换成的example.md

# Sample DocumentThis document was created using accessibility techniques for headings, lists, image alternate text, tables, and columns. It should be completely accessible using assistive technologies such as screen readers.## HeadingsThere are eight section headings in this document. At the beginning, "Sample Document" is a level 1 heading. The main section headings, such as "Headings" and "Lists" are level 2 headings. The Tables section contains two sub-headings, "Simple Table" and "Complex Table," which are both level 3 headings.## ListsThe following outline of the sections of this document is an ordered (numbered) list with six items. The fifth item, "Tables," contains a nested unordered (bulleted) list with two items.1. Headings
2. Lists
3. Links
4. Images
5. Tables* Simple Tables
* Complex Tables1. Columns## LinksIn web documents, links can point different locations on the page, different pages, or even downloadable documents, such as Word documents or PDFs:[Top of this Page](#_top)
[Sample Document](http://www.dhs.state.il.us/page.aspx?item=67072)
[Sample Document (docx)](http://www.dhs.state.il.us/OneNetLibrary/27897/documents/Initiatives/IITAA/Sample-Document.docx)## Images![Web Access Symbol](data:image/gif;base64...)Documents may contain images. For example, there is an image of the web accessibility symbol to the left of this paragraph. Its alternate text is "Web Access Symbol".Alt text should communicate what an image means, not how it looks.![Chart of Screen Reader Market Share. (Unfortunately, there isn't a way in Word or PDF to include rich formatting, such as a table, in alternate text.)](data:image/png;base64...)Some images, such as charts or graphs, require long descriptions, but not all document types allow that. In web pages, long descriptions may be provided in several ways: on the page below the image, via a link below the image, or via a link on the image.## Tables### Simple TablesSimple tables have a uniform number of columns and rows, without any merged cells:| **Screen Reader** | **Responses** | **Share** |
| --- | --- | --- |
| JAWS | 853 | 49% |
| NVDA | 238 | 14% |
| Window-Eyes | 214 | 12% |
| System Access | 181 | 10% |
| VoiceOver | 159 | 9% |### Complex TablesThe following is a complex table, using merged cells as headers for sections within the table. This can't be made accessible in all types of documents:|  |  |  |  |  |
| --- | --- | --- | --- | --- |
|  | **May 2012** | | **September 2010** | |
| **Screen Reader** | **Responses** | **Share** | **Responses** | **Share** |
| JAWS | 853 | 49% | 727 | 59% |
| NVDA | 238 | 14% | 105 | 9% |
| Window-Eyes | 214 | 12% | 138 | 11% |
| System Access | 181 | 10% | 58 | 5% |
| VoiceOver | 159 | 9% | 120 | 10% |## ColumnsThis is an example of columns. With columns, the page is split into two or more horizontal sections. Unlike tables, in which you usually read across a row and then down to the next, in columns, you read down a column and then across to the next.When columns are not created correctly, screen readers may run lines together, reading the first line of the first column, then the first line of the second column, then the second line of the first column, and so on. Obviously, that is not accessible.Process finished with exit code 0

转换多种格式示例

1. PDF 转 Markdown

markitdown document.pdf > document.md

MarkItDown 会尝试保留标题、列表、表格和链接。

2. PPTX 转 Markdown

markitdown slides.pptx > slides.md

每一张幻灯片的内容会转换为 Markdown 的标题和列表结构。

3. Excel 转 Markdown

markitdown data.xlsx > data.md

表格会被保留为 Markdown 表格格式,便于在笔记或 GitHub 上阅读。

4. ZIP 文件批量处理

如果有一个 ZIP 包含多个文件:

markitdown archive.zip

MarkItDown 会自动遍历 ZIP 内所有文件并生成 Markdown 输出。

高级示例:带图片和音频

MarkItDown 可以处理图片和音频文件,并尝试提取 EXIF 元数据或进行语音转录:

# 图片
markitdown photo.jpg > photo.md# 音频
markitdown audio.mp3 > audio.md

在 LLM 工作流中的应用

MarkItDown 特别适合与大语言模型(LLM)结合使用。你可以:

  • 先将各种文档统一转换为 Markdown;

  • 再将 Markdown 作为输入喂给模型进行问答或摘要;

  • 保留结构化内容(标题、列表、表格),提升 LLM 的理解能力。

GitHub - microsoft/markitdown: Python tool for converting files and office documents to Markdown.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/95567.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/95567.shtml
英文地址,请注明出处:http://en.pswp.cn/bicheng/95567.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LVGL9.3 vscode 模拟环境搭建

1、git 克隆: git clone -b release/v9.3 https://github.com/lvgl/lv_port_pc_vscode.git 2、cmake 和 mingw 环境搭建 cmake: https://blog.csdn.net/qq_51355375/article/details/139186681?spm1011.2415.3001.5331 mingw: https://bl…

投影矩阵:计算机图形学中的三维到二维转换

投影矩阵是计算机图形学中的核心概念之一,它负责将三维场景中的几何数据投影到二维屏幕上,从而实现三维到二维的转换。无论是游戏开发、虚拟现实,还是3D建模,投影矩阵都扮演着不可或缺的角色。本文将深入探讨投影矩阵的基本原理、…

10.2 工程学中的矩阵(2)

十、例题 【例3】求由弹簧连接的 100100100 个质点的位移 u(1),u(2),...,u(100)u(1),u(2),...,u(100)u(1),u(2),...,u(100), 弹性系数均为 c1c 1c1, 每个质点受到的外力均为 f(i)0.01f(i)0.01f(i)0.01. 画出两端固定和固定-自由这两种情形 u 的图形。 解: % 参数设…

Mysql主从复制之延时同步

1.延时同步概念通过人为配置从库和主库延时N小时可以实现延时同步,延时同步可以解决数据库故障出现的数据丢失问题(物理损坏如直接使用rm删除数据库数据和逻辑损坏如使用drop命令删除数据库)2.延时同步实操2.1先配置从库延时同步,并且设置sql线程300秒后…

【QT特性技术讲解】QPrinter、QPdf

前言 QT对打印和PDF应用场景,做了简单的封装,复杂的功能还是得用第三方库,打印功能简单的文本可以不用PDF,涉及图形的基本都要用到PDF。 Linux打印 随着国产信创项目替换基于Linux的桌面系统国产信创系统,Linux桌面系…

【大数据技术实战】Flink+DS+Dinky 自动化构建数仓平台

一、背景:企业数仓建设的现状与挑战在数字化转型进入深水区的今天,数据已成为企业核心生产要素,而实时数仓作为 “数据驱动决策” 的关键载体,其建设水平直接决定企业在市场竞争中的响应速度与决策精度。根据 IDC《2024 年全球大数…

Python开篇:撬动未来的万能钥匙 —— 从入门到架构的全链路指南

Python:撬动未来的万能钥匙——从入门到架构的全链路指南 在技术的星空中,Python 是那颗永不陨落的超新星——它用简洁的语法点燃创造之火,以庞大的生态铺就革新之路。无论你身处哪个领域,这把钥匙正在打开下一个时代的大门。2024…

【QT随笔】事件过滤器(installEventFilter 和 eventFilter 的组合)之生命周期管理详解

【QT随笔】事件过滤器(installEventFilter 和 eventFilter 的组合)之生命周期管理详解 上一章节中提到事件过滤器(Event Filter),用于处理特定事件。其中第二小节中提到了事件过滤器生命周期管理。本文将详细解析事件过滤器生命周期管理这一部分的内容。 (关注不迷路哈!…

关于linux软件编程12——网络编程3

一、单循环服务器 特点:1.可以处理多个客户端 (不能同时)2.效率不高//单循环服务器: socket bind listen while (1) {connfd accept();//通信 }特点:简单 可以处理多客户端 不能同时 二、并发服务器 --- 同时可以处理多个客户端1、设置一个选项(开启一个功能) ---让地址重…

thinkphp6通过workerman使用websocket

安装workerman依赖 composer require topthink/think-worker composer require topthink/think-worker1.0.* # 指定兼容版本‌:ml-citation{ref"1,7" data"citationList"}config配置 config/worker.php <?php return [// 扩展自身需要的配置host …

Rust SQLx 开发指南:利用 Tokio 进行性能优化

在当今高并发的应用开发环境中&#xff0c;数据库操作往往是性能瓶颈的主要来源之一。SQLx 作为一个纯 Rust 编写的异步 SQL 客户端库&#xff0c;通过与 Tokio 运行时深度集成&#xff0c;为开发者提供了处理数据库 I/O 密集型操作的强大工具。本文将带您深入了解如何利用这两…

嵌入式硬件电路分析---AD采集电路

文章目录摘要AD采集电路1AD采集电路2R77的真正作用是什么&#xff1f;理想与现实&#xff1a;为什么通常可以忽略R77的影响&#xff1f;摘要 AD采集 AD采集电路1 这是个人画的简化后的AD采集电路 这是一个AD检测电路&#xff0c;R1是一个可变电阻&#xff0c;R2是根据R1的常用…

Python爬取nc数据

1、单文件爬取爬取该网站下的crupre.nc数据&#xff0c;如下使用requests库&#xff0c;然后填写网站的url&#xff1a;"http://clima-dods.ictp.it/regcm4/CLM45/crudata/"和需要下载的文件名&#xff1a;"crupre.nc"import requests import osdef downlo…

策略模式 + 工厂模式

策略模式&#xff1a;简单来说解决的行为的封装与选择。如HandlerMapping&#xff0c;将 HTTP 请求映射到对应的处理器&#xff08;Controller 或方法&#xff09;。工厂模式&#xff1a;解决的是具有相同属性的对象创建问题&#xff0c;如BeanFactory创建bean对象。解决的代码…

Diamond基础3:在线逻辑分析仪Reveal的使用

文章目录1. 与ILA的区别2. 使用Reveal步骤3.Reveal注意事项4.传送门1. 与ILA的区别 Reveal是Lattice Diamond集成开发环境用于在线监测信号的工具&#xff0c;ILA是xilinx的Vivado集成开发工具的在线逻辑分析仪&#xff0c;同Reveal一样&#xff0c;均可以在项目运行过程中&am…

超适合程序员做知识整理的 AI 网站

这次要给大家分享一个超适合程序员做知识整理的 AI 网站 ——Notion AI&#xff0c;网址是Notion&#xff0c;它能把你随手记的杂乱笔记、代码片段、技术文档&#xff0c;一键梳理成逻辑清晰的结构化内容&#xff0c;小索奇我用它整理 “Python 爬虫知识点” 时&#xff0c;原本…

【 Selenium 爬虫】2025年8月25日-pixabay 图片采集

无恶意采集&#xff0c;取部分图片用来做相册测试的&#x1f604; 效果图import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.la.selenium.utils.SeleniumUtil; import lombok.extern.slf4j.Slf4j; import o…

服务器托管需要注意什么事项?

服务器托管是企业IT基础设施的关键环节&#xff0c;其稳定性和安全性直接影响业务连续性。需要注意下面这几点&#xff01; 一、服务商与机房选择 服务商资质 选择持有ISP证书的合法服务商&#xff0c;优先考虑运营超5年、市场口碑佳的老牌公司&#xff0c;技术团队需具备72…

微信小程序备忘

1.按钮事件中想切换到tabBar中的链接用switchTab&#xff0c;不能用navigateTo&#xff1a;agentPage: function() { wx.switchTab({url: /pages/agent/agent}) },特别注意&#xff1a;微信小程序中所谓的自定义&#xff0c;并不是完全的自定义&#xff0c;在app.json中定义&a…

虚拟机NAT模式通过宿主机(Windows)上网不稳定解决办法(无法上网)(将宿主机设置固定ip并配置dns)

文章目录问题描述解决办法分析**1. 问题的根本原因****(1) 宿主机动态IP的DNS配置问题****(2) NAT模式下的网络依赖****(3) 自习室WiFi的潜在限制****2. 用户操作的合理性分析****(1) 固定IP的作用****(2) 手动指定公共DNS的作用****3. 用户怀疑的正确性****4. 其他可能原因的排…