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。這個 formula 會從原始碼編譯 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 結束。