packages/markitdown/src/markitdown/__main__.py(281 行)· 由 pyproject [project.scripts] markitdown = "markitdown.__main__:main" 掛載CLI 是 MarkItDown 類別的薄殼:解析旗標 → 把 -x/-m/-c 轉成
StreamInfo 提示 → 依雲端旗標選 docintel/cu/內建 建實例 → 轉換 → 寫檔或印 stdout。
沒有獨立的轉換邏輯——所有格式知識都在核心。
依序:
dedent 寫成 SYNTAX/EXAMPLE 教學式說明。.、mimetype 必須含 /、
charset 用 codecs.lookup 驗證,非法即 _exit_with_error。StreamInfo 提示。--list-plugins 印出 entry-point 清單後 sys.exit(0)。-d 需 -e;--use-cu 需
--cu-endpoint;--cu-file-types 解析成
ContentUnderstandingFileType 列舉。sys.stdin.buffer(convert_stream);有 → convert。有 -o 就開檔寫 result.markdown;否則印 stdout 時用
encode(errors="replace").decode() 避免 Windows 終端編碼炸掉。
CLI 參數錯誤(缺端點、mimetype 格式錯、charset 未知)的統一出口。