為什么要用 MarkItDown?以及如何使用它

在處理大量文檔時,尤其是在構建知識庫、進行文檔分析或訓練大語言模型(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. 其他可能原因的排…