Skip to main content

Module ir

Module ir 

Source
Expand description

Intermediate representation produced by crate::render_to_ir.

The shape mirrors the TypeScript IRDocument consumed by afm-obsidian/src/ir/types.ts (and validated in afm-obsidian/src/ir/from-wasm.ts). Keeping the names and field ordering aligned across the FFI boundary makes the serde-wasm-bindgen round-trip a pass-through, no shape adapters needed.

§Coverage

  • Markdown side: paragraphs, headings, lists, blockquotes, fenced code, tables, thematic breaks. Inline runs preserve Strong, Emphasis, Link, Code, LineBreak, and verbatim Text.
  • Aozora side: Ruby / DoubleRuby / Bouten / Tcy / Gaiji / Annotation (inline) and Container / PageBreak / SectionBreak (block). Heading hints ([#「X」は大見出し]) promote their host paragraph to IrBlock::Heading directly, mirroring crate::post_process.

§Architecture

The walker is built from three small primitives:

  1. crate::sentinels::SentinelCursor — the shared registry-stream cursor. The HTML splicer (crate::post_process) and this builder both consume the same source-order sequence of NodeRef entries; the cursor abstraction keeps them in lockstep.
  2. ParaScan — single-descent paragraph profile. One walk per paragraph computes both the sole-block-sentinel test and the heading-hint lookahead at once, eliminating the two-scan redundancy that a naive translation of the HTML splicer would have.
  3. OpenContainer — the per-walker container stack. Where the HTML splicer can stream open/close tags into a string buffer, the IR demands a tree, so each open container collects IrBlocks into its own Vec until the matching close arrives. Move semantics (no clone) carry the children into the closed IrBlock::Container.

Structs§

IrDiagnostic
IrDocument
IrListItem
IrTableRow
IrWalker 🔒
Tree builder that consumes comrak nodes plus a sentinel cursor and emits IrBlocks into a stack-balanced container hierarchy.
OpenContainer 🔒
ParaScan 🔒
Collected paragraph properties. The walker computes this in one pass over the paragraph’s text descendants and dispatches off the result.
Range
StreamingIrBuilder
Stateful per-block IR builder for streaming mode.
TableMeta 🔒

Enums§

IrBlock
IrInline
IrTableAlign
ParagraphAction 🔒

Functions§

annotation_kind_resolved 🔒
bouten_kind_str 🔒
bouten_position_str 🔒
build_ir 🔒
Walk a comrak AST root and project it to IrDocument.
container_indent_level 🔒
container_subtype 🔒
content_to_string 🔒
place_in 🔒
Push block onto the top-of-stack open container’s children, or onto the document’s top-level blocks if no container is open.
project_annotation 🔒
project_block_leaf 🔒
project_bouten 🔒
project_content_inlines 🔒
project_double_ruby 🔒
project_gaiji 🔒
project_inline 🔒
project_ruby 🔒
project_tcy 🔒
resolved_to_string 🔒
section_kind_subtype 🔒
sourcepos_to_range 🔒
table_align 🔒
to_u32 🔒
Saturating usize → u32. Source line/column overflow requires ~4G-line files, so saturating to u32::MAX is safe.
top_metadata 🔒