跳到內容

匯出設定檔

先備知識:快速開始

export profile 設定的是頁面、字型、邊界、縮排與頁碼等呈現;它不改變 MDI syntax 或文件語意。套件為 @illusions-lab/mdi-export-profileresolveExportProfile 不會靜默接受錯誤的版面資料,而會回傳含 field 名的 Error

{
"layout": { "system": "word" },
"metadata": { "title": "The Last Station", "author": "A Writer", "publisher": "Example Press", "identifier": "isbn:9780000000000" },
"typesetting": { "writingMode": "horizontal", "fontFamily": "Noto Serif JP", "fontSize": 10.5, "lineSpacing": 1.4, "textIndentEm": 1 },
"pagination": {
"pageSize": "A4", "landscape": false, "gridMode": "typographic",
"margins": { "top": 25.4, "bottom": 25.4, "left": 25.4, "right": 25.4 },
"pageNumbers": { "enabled": true, "format": "simple", "position": "bottom-center" }
},
"epub": { "chapterSplitLevel": "h1", "coverPath": "cover.png" },
"text": { "fullwidthSpaceIndent": true, "indentCount": 1 }
}

resolveExportProfile({}) 可供內部/default resolution 使用,但 CLI --config 與設定型 @illusions-lab/mdi export 必須提供 layout.system。請選擇一個 contract:嚴格日文書籍的 "japanese-publisher",或流動 Word 頁面的 "word";兩者不能混用。

欄位型別 / 預設條件
layout.system"japanese-publisher" | "word"設定型 export 必填;選擇整套 layout contract。
layout.marginMode / bindingSide / gutterpublisher: mirror / 依方向 / 0 mmword 為 single margin,沒有 gutter。
metadata.*optional string指定時必須為 string。
typesetting.writingMode"horizontal""horizontal" | "vertical"
fontFamily / fontSize / lineSpacingMincho stack / system default / optionallineSpacing 僅可用於 typographic。
pagination.pageSizepublisher 橫書:Shirokuban;直書:A4 landscape;word:A4PAGE_SIZES 的 key。
charactersPerLine / linesPerPagepublisher 橫書 27×26;直書 40×3010–400;word 的 count 僅供資訊,不是頁面契約。
gridModepublisher: strict; word: typographicword 拒絕 strict;strict 拒絕 line spacing。
marginspublisher: 16.5/18/18/15.5 mm;word: 四邊 25.4 mm必須留下 printable area。
pageNumbersenabled / simple / bottom-centerformat 為 simple / dash / fraction,位置有 6 種。
epub.chapterSplitLevel / coverPathh1 / optionalh1/h2/h3/none;CLI cover 為 PNG/JPEG。
text.fullwidthSpaceIndent / indentCountfalse / 1boolean / 1–4。

japanese-publisher 的預設為鏡像跨頁:橫書是 10 pt 明朝體的 Shirokuban、左裝訂 27 字 × 26 行;直書是 A4 landscape 小說原稿、右裝訂 40 字 × 30 行 strict grid。word 預設為 A4、四邊 25.4 mm、無鏡像的流動 typographic layout。

Terminal window
mdi build novel.mdi --to pdf --config novel.export.json -o novel.pdf
mdi build novel.mdi --to docx --config novel.export.json
mdi build novel.mdi --to epub --config novel.export.json
mdi build novel.mdi --to txt-ruby --config novel.export.json
import { parseExportProfileJson, resolveExportProfile } from "@illusions-lab/mdi-export-profile";
const profile = parseExportProfileJson(await readFile("novel.export.json", "utf8"));
const resolved = resolveExportProfile(profile);

resolvePrintProfile(profile, sourceWritingMode) 是 PDF/print 的 wrapper。文件 front matter 的 writing mode 是 default,明確 profile 優先;它不會為直書悄悄改成 landscape。

設定PDFTXT / txt-rubyEPUB / DOCX
頁面幾何、字型、頁碼DOCX:是;EPUB 使用 typography,但為 reflowable。
metadata / writing modeEPUB / DOCX:是。
全形空白縮排是(text.indentCount 為 1–4)EPUB / DOCX:是。
cover image、chapter splitEPUB:是。

adapter 包裝 Rust 已 parse 的 IR,layout policy 留在 MDI parser 外。EPUB 為 reflowable,不能承諾固定 physical pages。