AI工具
MarkItDown
MarkItDown 是微软开源的文件转 Markdown 工具,支持 Office 文档、PDF、HTML、图片(OCR)等格式。test
安装
pip install markitdown
命令行用法
# 单文件转换
markitdown input.docx > output.md
markitdown presentation.pptx -o output.md
markitdown spreadsheet.xlsx > output.md
# PDF 转换
markitdown document.pdf > output.md
# 网页转换
markitdown https://example.com/page > output.md
# 图片 OCR(提取图片中的文字)
markitdown photo.jpg > output.md
# 批量转换目录
markitdown ./office-docs/ -o ./markdown-output/
支持的格式
| 格式 | 说明 |
|---|---|
.docx | Word 文档 |
.pptx | PowerPoint 演示 |
.xlsx | Excel 表格 |
.pdf | PDF 文档 |
.html / .htm | 网页 |
.csv | CSV 数据 |
.json | JSON 数据 |
.xml | XML 数据 |
.zip | 压缩包(递归处理内含文件) |
| 图片 | PNG/JPEG 等,通过 OCR 提取文字 |
Python API
from markitdown import MarkItDown
md = MarkItDown()
# 转换文件
result = md.convert("document.docx")
print(result.text_content)
# 转换 URL
result = md.convert("https://example.com/article")
print(result.text_content)
# 转换图片(自动 OCR)
result = md.convert("screenshot.png")
print(result.text_content)
# 流式转换(大文件友好)
for chunk in md.convert_stream("large-doc.pdf"):
print(chunk.text_content)
Pandoc
Pandoc 是通用文档转换器,支持 40+ 种格式之间的互转。
安装
# macOS
brew install pandoc
# Windows
winget install pandoc
# Linux (Debian/Ubuntu)
sudo apt install pandoc
# 如需 PDF 输出,还需安装 LaTeX 引擎
# macOS: brew install basictex
# Linux: sudo apt install texlive-xetex
基本命令格式
pandoc 输入文件 -o 输出文件 [选项]
常用转换
# Markdown → Word
pandoc doc.md -o doc.docx
# Markdown → PDF(需要 LaTeX)
pandoc doc.md -o doc.pdf --pdf-engine=xelatex
# Markdown → HTML
pandoc doc.md -o doc.html --standalone
# Word → Markdown
pandoc doc.docx -o doc.md --wrap=none
# HTML → Markdown
pandoc page.html -o page.md
# Markdown → 演示文稿(reveal.js)
pandoc slides.md -o slides.html -t revealjs --standalone
# Markdown → EPUB 电子书
pandoc book.md -o book.epub
常用选项
| 选项 | 作用 | 示例 |
|---|---|---|
-f / --from | 指定输入格式 | -f markdown |
-t / --to | 指定输出格式 | -t docx |
-o | 输出文件 | -o output.pdf |
--standalone | 生成完整文档(含 head/body) | 输出 HTML/PDF 时必备 |
--toc | 自动生成目录 | --toc --toc-depth=3 |
--metadata | 设置元数据 | --metadata title="标题" |
--template | 使用自定义模板 | --template=my.tex |
--pdf-engine | 指定 PDF 引擎 | --pdf-engine=xelatex |
--wrap | 控制换行方式 | --wrap=none(不硬换行) |
--resource-path | 资源搜索路径 | --resource-path=.:images |
--number-sections | 章节自动编号 | |
--listings | 代码块使用 listings 宏包 | 仅 LaTeX/PDF 输出 |
-V | 设置模板变量 | -V colorlinks=true |
Markdown → PDF 完整示例
pandoc doc.md \
-o doc.pdf \
--pdf-engine=xelatex \
--standalone \
--toc \
--toc-depth=3 \
--number-sections \
-V CJKmainfont="Noto Sans CJK SC" \
-V geometry:margin=2.5cm \
-V colorlinks=true \
--metadata title="文档标题"
Markdown → Word 完整示例
pandoc doc.md \
-o doc.docx \
--toc \
--toc-depth=3 \
--number-sections \
--reference-doc=template.docx \
--metadata title="文档标题"
--reference-doc可指定样式参考文档,用于控制输出的字体、颜色等样式。先用pandoc -o template.docx --print-default-data-file reference.docx导出默认模板。
批量转换
# 将目录下所有 .md 转为 .docx
for f in *.md; do
pandoc "$f" -o "${f%.md}.docx"
done
# 将目录下所有 .docx 转为 .md
for f in *.docx; do
pandoc "$f" -o "${f%.docx}.md" --wrap=none
done
合并多个文件
# 将多个 md 合并输出为一个文件
pandoc chapter1.md chapter2.md chapter3.md -o book.docx --toc
# 从文件列表合并
pandoc $(cat file-list.txt) -o merged.pdf --pdf-engine=xelatex
CodeGraph
CodeGraph 是 100% 本地的语义代码智能工具——将代码库构建为 SQLite 知识图谱,通过 MCP Server 暴露给 AI 编程助手。GitHub 50k+ stars,带来约 16% 成本降低、58% 工具调用减少。
安装
# 全局安装(推荐)
npm install -g @colbymchenry/codegraph
# 或一键脚本安装
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh # macOS/Linux
irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex # Windows
接入 AI Agent
# 交互式安装向导(自动配置 Claude Code / Cursor / Codex 等)
codegraph install
# 手动启动 MCP Server
codegraph serve --mcp
项目初始化
cd your-project
# 初始化并构建图谱
codegraph init -i # 创建 .codegraph/ + 构建索引
# 增量同步(监听文件变更自动更新)
codegraph sync
# 查看图谱统计
codegraph status
查询命令
# ── 符号搜索与定位 ──
codegraph query <keyword> # 按名称搜索符号(--kind, --limit, --json)
codegraph files [path] # 查看文件结构(--format, --filter, --max-depth)
# ── 调用关系 ──
codegraph callers <symbol> # 谁调用了这个符号(--limit, --json)
codegraph callees <symbol> # 这个符号调用了谁(--limit, --json)
# ── 上下文与影响分析 ──
codegraph context <task> # 构建 AI 上下文(入口点 + 相关符号 + 代码片段)
codegraph impact <symbol> # 符号变更的影响范围(--depth, --json)
codegraph affected [files...] # 查找受变更影响的测试文件
MCP 工具清单
启动 codegraph serve --mcp 后,AI Agent 获得以下工具:
| 工具 | 用途 |
|---|---|
codegraph_search | 全文搜索代码符号 |
codegraph_context | 构建任务上下文(入口点、依赖、代码片段) |
codegraph_callers | 查找调用者 |
codegraph_callees | 查找被调用者 |
codegraph_impact | 影响范围分析 |
codegraph_node | 获取符号节点详情 |
codegraph_status | 图谱统计信息 |
codegraph_files | 文件结构浏览 |
codegraph_explore | 探索代码结构 |
支持的 Agent
Claude Code、Cursor、Codex CLI、OpenCode、Hermes Agent、Gemini CLI、Antigravity IDE、Kiro
关键特性
| 特性 | 说明 |
|---|---|
| 20+ 语言 | TS/JS、Python、Go、Rust、Java、C#、PHP、Ruby、C/C++、Swift、Kotlin、Scala、Dart、Lua、Svelte、Vue、Astro、Liquid、Pascal/Delphi |
| 全文搜索 | SQLite FTS5 引擎,按名称秒搜全代码库 |
| 自动同步 | 原生文件监听(FSEvents/inotify/ReadDirectoryChangesW),零配置 |
| 框架感知路由 | 识别 17 种框架路由(Django、Flask、FastAPI、Express、NestJS、Laravel、Rails、Spring、Gin、Axum、ASP.NET、Vapor 等) |
| 跨平台移动 | Swift ↔ ObjC 桥接、React Native TurboModules、Expo Modules |
| 100% 本地 | 数据不出机器,无需 API Key,仅 SQLite |
速查对照
| 场景 | MarkItDown | Pandoc |
|---|---|---|
| Office → MD | ✅ 原生支持,效果最佳 | ⚠️ 需借助 --from docx |
| MD → Office | ❌ 不支持 | ✅ pandoc in.md -o out.docx |
| PDF → MD | ✅ 支持 | ⚠️ 效果一般 |
| MD → PDF | ❌ 不支持 | ✅ 需 LaTeX 引擎 |
| 网页 → MD | ✅ markitdown URL | ✅ pandoc URL -o out.md |
| 图片 OCR | ✅ 内置支持 | ❌ 不支持 |
| 批量处理 | ⚠️ 有限 | ✅ Shell 脚本 |
简单记:拿数据进 MD 用 MarkItDown,MD 往出发用 Pandoc。