MarsDawn

给 AI agent 的 marsdawn 参考

给调用 marsdawn 命令行工具的 AI agent 与脚本参考。本页每个范例都用目前源代码构建的工具实际运行过。

要把 Markdown 文件转成 PDF,运行 marsdawn export notes.md --json,再从 stdout 读取一个 JSON 对象。Mermaid 图表与代码高亮的呈现方式和 MarsDawn app 相同。export 不需要 app,open 需要。

能做什么

不做什么

export

marsdawn export notes.md --json

notes.md 旁写出 notes.pdf。选项:

marsdawn export notes.md -o out.pdf --theme classic --paper letter --force --json

成功,退出代码 0:

{"diagramErrors":[],"ok":true,"output":"/path/to/out.pdf","pages":1,"paper":"letter","theme":"classic"}

open

marsdawn open notes.md --json
marsdawn open notes.md:120 --json
marsdawn open notes.md --line 120 --json

成功,退出代码 0:

{"app":"/Applications/MarsDawn.app","ok":true,"opened":[{"line":120,"path":"/path/to/notes.md"}]}

marsdawn 0.2.x 的 opened 是路径字符串的清单。如果需要同时处理两种格式,请先查看 marsdawn --version

失败

加上 --json 时,失败会在 stdout 输出一个 JSON 对象,并以对应的代码结束:

{"error":"output_exists","message":"/path/to/notes.pdf already exists. Pass --force to replace it.","ok":false}

JSON Schema

每种 --json 结果的 JSON Schema(draft 2020-12):

环境变量

系统需求

安装

使用 Homebrew。在 Apple 芯片的 Mac 上,会直接安装预先构建好的版本,几秒就完成,不需要 Xcode。在 Intel Mac 上则会从源代码编译 marsdawn,需要几分钟,也需要 Xcode 26 以上。

brew tap redtear1115/tap && brew install marsdawn
marsdawn --version

也可以从源代码构建。第一次构建会下载依赖项并编译,同样需要几分钟。

git clone https://github.com/redtear1115/mars-dawn-kit.git
cd mars-dawn-kit
swift build -c release --product marsdawn
.build/release/marsdawn export notes.md --json

marsdawn --version 会输出版本号,例如 0.3.0,并以代码 0 结束。