pyproject.toml 宣告 entry-point:[project.entry-points."markitdown.plugin"]。__plugin_interface_version__ 與 register_converters(markitdown, **kwargs)。MarkItDown 實例時,若 enable_plugins=True(或 CLI --use-plugins),
會 entry_points(group="markitdown.plugin") 載入全部已安裝外掛,呼叫 register_converters()。register_converter(converter, priority=...) 在任何優先級插入 converter——包括搶在內建 converter 之前。# 列出已安裝外掛
markitdown --list-plugins
# 使用外掛
markitdown --use-plugins path-to-file.pdf
# Python API
md = MarkItDown(enable_plugins=True)
result = md.convert("path-to-file.rtf")
warn() 並跳過——所以裝了外掛但沒生效時,先檢查 --list-plugins。用 LLM Vision 抽取 PDF、DOCX、PPTX、XLSX 中「內嵌圖片」的文字(OCR),
不需要新 ML 函式庫——沿用核心既有的 llm_client / llm_model 模式。
pip install markitdown-ocr pip install openai markitdown document.pdf --use-plugins --llm-client openai --llm-model gpt-4o
重點行為:
*[Image OCR]...<文字>[End OCR]*,就地插入不破壞文件流程。llm_client 時外掛仍載入但「靜默略過」,退回內建 converter。以 RtfConverter 為例,三步完成:
# 1. 實作 DocumentConverter
class RtfConverter(DocumentConverter):
def accepts(self, file_stream, stream_info, **kwargs) -> bool:
... # 判斷是不是 RTF
def convert(self, file_stream, stream_info, **kwargs) -> DocumentConverterResult:
... # 轉成 Markdown
# 2. 匯出外掛協定
__plugin_interface_version__ = 1
def register_converters(markitdown: MarkItDown, **kwargs):
markitdown.register_converter(RtfConverter())
# 3. pyproject.toml 宣告 entry-point
# [project.entry-points."markitdown.plugin"]
# sample_plugin = "markitdown_sample_plugin"
完整註解範例見 程式碼對照 · OCR / 外掛套件。
#markitdown-plugin 標籤可找到社群外掛。