コンテンツにスキップ

Android / Kotlin

Android バインディングは、小さな JNI ファサードの上に構築した AAR 形式の Kotlin API です。完全な UTF-8 のソースをそのまま mdi-core に渡します。Android 側で Markdown/MDI をトークン化したり、区切り記号のフォールバックを補正したり、文書の意味をレンダリングしたりすることはありません。

  • minSdk は 23、ライブラリは API 36 に対してコンパイルします。利用側アプリの target SDK は利用側が管理します(現在の Google Play 提出では API 36)。
  • 実機用に arm64-v8a、エミュレータ用に x86_64 を提供します。Android v1 では意図的に 32-bit ARM を含めません。
  • parse、HTML、canonical MDI serialization、TXT、EPUB、DOCX は Rust に委譲します。EPUB と DOCX は ByteArray を返すため、アプリは Storage Access Framework などでそのバイト列を書き出します。
  • 解析結果は未対応の IR バージョンを拒否し、diagnostic と UTF-8 byte span を保持します。
  • Kotlin unit coverage には line 90% の強制閾値があります。acceptance command は端末テストの前に JaCoCo の XML/HTML レポートを生成します。
  • PDF は Android API にはありません。Rust の PDF 経路は実行可能な Chromium プロセスを必要とするため、Android アプリでは Rust HTML を WebView に表示するか、Android の印刷フレームワークを使用してください。
val result = Mdi.parse("{東京|とうきょう}で第^12^話を読む。")
val html = Mdi.renderHtml("# 題\n\n{東京|とうきょう}")

ローカルの Rust target の準備、native library の生成、acceptance command は android/README.md を参照してください。

分割規則は Rust が一元管理します。本文の50%の字級、固定2行、行間なしで表示します。先頭の断片には本文行の残り幅、後続には行全体の幅を指定できます。幅の単位は割注字級の半角emです。文字幅の推定であり、比例フォントの厳密な均衡は保証しません。

val fragments = Mdi.layoutWarichuJson(
"""[{"type":"text","value":"一二三四五六"}]""", capacity = 4, firstCapacity = 2)

戻り値は lines、html、widths、overflow、hardBreakAfter、sources を含みます。path は入力配列からの子インデックス列、startUtf8 / endUtf8 は可視文字列内の半開UTF-8バイト範囲です。同一の group は書式境界をまたぐ書記素も分割しません。ルビ、縦中横、改行禁止は一体として扱います。明示改行を保ち、自動分割は正規MDIや平文に書き戻しません。静的HTML/EPUBは閲覧ソフトにより再配置が異なります。DOCXはネイティブの双行グループを使います。XMLやインポーターの検証をWordの描画実測とは記載しません。

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