Android / Kotlin
Android 綁定是以 AAR 形式提供的 Kotlin 介面,底下只有一層精簡的 JNI façade。它把完整的 UTF-8 原始碼直接交給 mdi-core;Android 程式碼不會自行切分 Markdown 或 MDI、修補分隔符號的退回行為,也不負責渲染文件語意。
minSdk為 23,library 以 API 36 編譯;使用它的 app 自行決定 target SDK(目前送交 Google Play 應使用 API 36)。- 裝置提供
arm64-v8a,emulator 提供x86_64;Android v1 刻意不支援 32-bit ARM。 parse、HTML、canonical MDI serialization、TXT、EPUB 與 DOCX 都委派給 Rust。EPUB 與 DOCX 回傳ByteArray,app 應透過 Storage Access Framework 寫入這些位元組。- 解析結果會拒絕不支援的 IR 版本,並保留 diagnostics 與 UTF-8 byte spans。
- Kotlin unit coverage 設有強制的 90% 行覆蓋率門檻;驗收命令會先產生 JaCoCo XML、HTML 報告,再執行裝置測試。
- PDF 不是 Android API。Rust 的 PDF 路徑需要可執行的 Chromium process;Android app 應在 WebView 顯示 Rust HTML,或改用 Android 的 print framework。
val result = Mdi.parse("{東京|とうきょう}で第^12^話を読む。")val html = Mdi.renderHtml("# 題\n\n{東京|とうきょう}")本機 Rust target 設定、native library 產生與驗收命令,請見 android/README.md。
自動割注排版
Section titled “自動割注排版”分割規則由 Rust 統一實作。固定兩行、正文50%字級、零小行間距。首個片段可使用正文行剩餘容量,後續片段使用完整行容量。容量與回傳寬度以割注字級的半個em為單位;這是字寬估算,不保證比例字型的精確均衡。
val fragments = Mdi.layoutWarichuJson( """[{"type":"text","value":"一二三四五六"}]""", capacity = 4, firstCapacity = 2)結果包含 lines、html、widths、overflow、hardBreakAfter 與 sources。path 是從輸入陣列起算的子節點索引路徑;startUtf8 / endUtf8 是可見文字中的半開UTF-8位元組範圍。相同 group 保留跨格式邊界的書寫素。Ruby、縱中橫及no-break保持不可拆。作者硬換行保留,自動分割不寫回canonical MDI或純文字。靜態HTML/EPUB的閱讀器重排結果可能不同。DOCX使用原生雙行群組;XML與匯入器檢查不代表Word實測。
Editorial comments in MDI 2.1
Section titled “Editorial comments in MDI 2.1”Mdi.parse(source, includeComments = true)MDI 2.1 recognizes <!-- note --> in all documents, including declared 2.0 and unversioned source. Comments can be empty, multiline or Unicode; the nearest --> closes them and their contents are not interpreted. Code, front matter, link destinations and plain-text MDI parameters remain literal. Escape an opener as \<!--.
Source saving retains comments. Default parse/prepare/mdast APIs omit them with IR 1.0; { includeComments: true } returns positional comment nodes and IR 1.1. Both report syntax 2.1. Existing front-matter declarations are retained. Public body projections and layout exclude comments even with an inclusive tree, and their source-map runs preserve the gaps.
Every publication format always omits valid comments. This intentionally changes old 2.0 output that displayed them as HTML text. Unterminated comments remain literal and return mdi.comment.unterminated: export is allowed, so intended private text may be visible.
Use source serialization or an inclusive IR for lossless comment retention. A filtered external IR cannot restore omitted comments.
MIT License© 2026 Iktahana