[note] MarkItDown:一個可順利將 docx 與 pptx 轉換為 markdown 的工具

註記:此頁為由 AI(gpt-5-mini-2025-08-07)自動翻譯自英文原文,可能含有少量不準確之處。

📌 介紹

這篇文章討論 MarkItDown,一個專為輕鬆將 docx 和 pptx 檔案轉換成 markdown 格式而設計的工具。它說明了在此轉換流程中會用到的各種 Python 函式庫,幫助使用者有效處理文件與多媒體內容。

🚀 快速開始

MarkItDown 如何運作?

以下列出 MarkItDown 使用的模組

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
dependencies = [
"beautifulsoup4",
"requests",
"mammoth",
"markdownify",
"numpy",
"python-pptx",
"pandas",
"openpyxl",
"pdfminer.six",
"puremagic",
"pydub",
"youtube-transcript-api",
"SpeechRecognition",
"pathvalidate",
]

mammoth

python-pptx

openpyxl

pdfminer

pydub

youtube-transcript-api

SpeechRecognition

markdownify

pathvalidate

puremagic

  • https://github.com/cdgriffith/puremagic/tree/master
  • Puremagic 是一個 檔案類型偵測工具,它能在不依賴副檔名的情況下識別輸入檔案的類型。由於副檔名可以輕易更改,僅靠副檔名來辨識檔案類型可能有風險。此模組定義一組規則來讀取檔案內容並判定其類型。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# puremagic/magic_data.json
{
"extension_only": [
["", 0, ".txt", "text/plain", "Text File"],
["", 0, ".log", "text/plain", "Logger File"],
["", 0, ".yaml", "application/x-yaml", "YAML File"],
["", 0, ".yml", "application/x-yaml", "YAML File"],
["", 0, ".toml", "application/toml", "TOML File"],
["", 0, ".py", "text/x-python", "Python File"],
["", 0, ".pyc", "application/x-python", "Python Complied File"],
["", 0, ".pyd", "application/x-python", "Python Complied File"],
["", 0, ".python_history", "text/plain", "Python History File"],
["", 0, ".bat", "application/x-script", "Windows BAT file"],
["", 0, ".gitconfig", "text/plain", "Git Ignore File"],
...

🔁 重點回顧

  • MarkItDown 可順利將 docx 與 pptx 檔案轉換為 markdown 格式。
  • 此轉換需要多種依賴項,包括處理文件、音訊與資料的函式庫。
  • 每個提到的函式庫都有其特定功能,例如將 Word 文件轉為 HTML 或讀取 Excel 檔案。

🔗 參考資料

[note] MarkItDown:一個可順利將 docx 與 pptx 轉換為 markdown 的工具

https://hsiangjenli.github.io/blog/note-markitdown-a-tool-for-smoothly-converting-docx-and-pptx-into-markdown.zh-TW/

作者

Hsiang-Jen Li & ChatGPT-4o Mini

發表於

2024-12-13

更新於

2025-02-28

許可協議