多格式转 Markdown 工具:MarkItDown

-> % pipx install "markitdown[all]"
  installed package markitdown 0.1.5, installed using Python 3.14.4
  These apps are now available
    - markitdown
done! ✨ 🌟 ✨

MarkItDown 是微软开发的 Python 工具,用于将 Office 文档或者 PDF 文件转换为 Markdown 格式。

markitdown path-to-file.pdf > document.md
markitdown path-to-file.pdf -o document.md
cat path-to-file.pdf | markitdown
from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("test.xlsx")
print(result.text_content)
from markitdown import MarkItDown
from openai import OpenAI

client = OpenAI()
md = MarkItDown(llm_client=client, llm_model="gpt-4o")
result = md.convert("example.jpg")
print(result.text_content)

帮助文档:

-> % markitdown --help
usage: SYNTAX:

    markitdown <OPTIONAL: FILENAME>
    If FILENAME is empty, markitdown reads from stdin.

EXAMPLE:

    markitdown example.pdf

    OR

    cat example.pdf | markitdown

    OR

    markitdown < example.pdf

    OR to save to a file use

    markitdown example.pdf -o example.md

    OR

    markitdown example.pdf > example.md

Convert various file formats to markdown.

positional arguments:
  filename

options:
  -h, --help            show this help message and exit
  -v, --version         show the version number and exit
  -o, --output OUTPUT   Output file name. If not provided, output is written to stdout.
  -x, --extension EXTENSION
                        Provide a hint about the file extension (e.g., when reading from stdin).
  -m, --mime-type MIME_TYPE
                        Provide a hint about the file's MIME type.
  -c, --charset CHARSET
                        Provide a hint about the file's charset (e.g., UTF-8).
  -d, --use-docintel    Use Document Intelligence to extract text instead of offline conversion. Requires a valid Document Intelligence Endpoint.
  --use-cu, --use-content-understanding
                        Use Azure Content Understanding to extract text. Requires --cu-endpoint.
  -e, --endpoint ENDPOINT
                        Document Intelligence Endpoint. Required if using Document Intelligence.
  --cu-endpoint CU_ENDPOINT
                        Content Understanding Endpoint. Required if using --use-cu.
  --cu-analyzer CU_ANALYZER
                        Content Understanding analyzer ID. If not specified, auto-selects by file type.
  --cu-file-types CU_FILE_TYPES
                        Comma-separated list of file types to route to Content Understanding (e.g., pdf,jpeg,mp4). If omitted, all supported types are routed.
  -p, --use-plugins     Use 3rd-party plugins to convert files. Use --list-plugins to see installed plugins.
  --list-plugins        List installed 3rd-party plugins. Plugins are loaded when using the -p or --use-plugin option.
  --keep-data-uris      Keep data URIs (like base64-encoded images) in the output. By default, data URIs are truncated.
如果你有魔法,你可以看到一个评论框~