コンテンツにスキップ

Document IR

前提: コア概念

parse() は次を返します。irVersion"1.0"syntaxVersion"2.0" で、独立したバージョンです。

{"irVersion":"1.0","syntaxVersion":"2.0","capabilities":{"mdi":true,"commonMark":true,"gfm":true,"frontMatter":true,"sourceSpans":true},"document":{"span":{"startByte":0,"endByte":0},"children":[]},"diagnostics":[]}

現在 capability はすべて true です。mdi-core は CommonMark、GFM、front matter、MDI を一回で解析し、すべての source-backed node に span を付けます。それでも consumer は値を固定せず確認してください。この field は古い結果や将来の結果を推測しないために存在します。

interface MdiDocument { span: MdiSourceSpan; frontmatter?: MdiFrontmatter; children: MdiNode[] }
interface MdiFrontmatter { span: MdiSourceSpan; raw: string; entries: Array<{ key: string; value: unknown }> }

frontmatterchildren 内の node ではなく sibling です。可視コンテンツを走査する際には含まれません。raw は YAML block の正確な source text、entries は順序を保持し unknown key も含みます。

すべての node は type と(source-backed node では)span を持ち、container node は children を持ちます。通常の CommonMark/GFM node は paragraphheadingdepth: 1–6)、blockquotelist/listItemcodeinlineCodethematicBreakhtmltable/tableRow/tableCelllinkimageemphasisstrongdeletetext、footnote などです。

type追加 field記法
rubybase, ruby{base|reading}
tcyvalue^text^
break[[br]]
emmark, children[[em:text]] / 《《text》》
noBreakchildren[[no-break:text]]
warichuchildren[[warichu:text]]
kernamount, children[[kern:<amount>:text]]
blanklone \ line、<br>[[blank]]
pagebreakvariant: "left" | "right" | null[[pagebreak]] / [[pagebreak:left|right]]
paragraphindent?, bottom?次の paragraph に対する [[indent:N]] / [[bottom]] / [[bottom:N]]
type MdiRubyReading = { type: "group"; value: string } | { type: "split"; value: string[] };

{雪女|ゆき.おんな}base: "雪女"ruby: { type: "split", value: ["ゆき", "おんな"] }ruby node になります。span は source 全体の UTF-8 byte range を指します。

startByte / endByte は元ソースへの半開 UTF-8 byte range です。host 言語の文字 index に変換する方法は Diagnostic を参照してください。

deprecated な parse_mdi_syntax / parseMdiSyntax は別の、より単純な形を返します。

interface MdiSyntaxDocument { blocks: Array<{ type: "paragraph"; inlines: MdiInline[]; indent: number | null; bottom: number | null } | { type: "blank" } | { type: "pagebreak"; variant: "left" | "right" | null }> }

これは span、front matter、通常 Markdown node を持たず、MDI 構文だけを扱う互換用 API です。完全な CommonMark/GFM/MDI parser より前のもので、その他を opaque paragraph text として扱います。新規コードは parse() / parse_document()Document を使ってください。MdiSyntaxDocument を返す function は deprecated path を使っている合図です。