import { DocumentRange } from "./types.js"; /** * A single section of a document: a heading plus the body that belongs * directly to it (i.e. up to its first child heading), together with the * blank-line separator the library owns. Child sections are stored as an * ordered list; the tree *is* the nesting. Nothing contested is stored here * (no path, no occurrence counter); those are derived when projecting or * resolving a target. */ export interface SectionNode { /** `null` for the synthetic document root. `level` is the *source* heading * depth as written; canonical levels are derived, not stored. */ heading: { text: string; level: number; } | null; /** The heading line (`# Foo\n`); `null` for the root. */ marker: DocumentRange | null; /** The section's direct body, excluding {@link trailingGap}. */ body: DocumentRange; /** The blank-line separator following {@link body} that the library owns. */ trailingGap: DocumentRange; /** Child sections, in document order. */ children: SectionNode[]; /** `^id`-bearing blocks that live directly in this section's body. */ blocks: BlockNode[]; /** * The ordered top-level blocks of this section's *direct* body (paragraphs, * lists, tables, code fences, …), the sequence a positional `within` index * addresses. Like {@link blocks}, an overlay rather than a partition: * blank-line gaps and isolated `^id` marker lines belong to no child, so * the rendered block count here matches Obsidian's section cache. */ bodyChildren: BodyChild[]; parent: SectionNode | null; } /** One top-level block of a section's direct body. */ export interface BodyChild { /** marked token type: `paragraph`, `list`, `table`, `code`, `blockquote`, `hr`, … */ kind: string; /** * The block's visible span, trailing line endings excluded (the same * convention as {@link BlockNode.content} and Obsidian's block spans). An * inline `^id` sits inside its block's token, so the span includes it. */ range: DocumentRange; } /** * A `^id`-bearing block. Blocks are an *overlay* onto the section tree: their * ranges fall within their containing section's {@link SectionNode.body}, * they do not tile the document themselves. */ export interface BlockNode { id: string; /** marked token type: `paragraph`, `table`, `list`, `blockquote`, … */ kind: string; /** Column header texts, for `table` blocks only. */ columns?: string[]; /** * True when the `^id` sits alone on its own line and therefore targets the * *preceding* block (Obsidian's isolated-block-reference rule): in that case * {@link content} is the preceding block's span and {@link marker} is the * detached `^id` line that follows it. False for an inline `^id` trailing a * paragraph/table row, where content and marker are contiguous. */ isolated: boolean; /** * The region the block id addresses. For an inline block this is the token * text preceding the `^id` marker; for an isolated block it is the whole * preceding block. Never includes a trailing line ending (Obsidian excludes * it from block spans). */ content: DocumentRange; /** The `^id` token span, with any trailing line ending excluded. */ marker: DocumentRange; /** The blank-line separator following the block. */ trailingGap: DocumentRange; section: SectionNode; } export interface FrontmatterEntry { key: string; value: unknown; /** The full `key: value` span within the frontmatter block. */ entryRange: DocumentRange; /** The value span within {@link entryRange}. */ valueRange: DocumentRange; } export interface DocumentModel { /** Short content hash of the source document; the future `ifMatch` token. */ version: string; lineEnding: "\n" | "\r\n"; frontmatter: { entries: FrontmatterEntry[]; /** The `---` … `---` block span, or `null` when there is no frontmatter. */ block: DocumentRange | null; }; root: SectionNode; } /** * The version token of a document: the SHA-256 digest of the document's UTF-8 * bytes, as lowercase hex, truncated to its first 6 characters. * * This is the same value as {@link PublicMap.version} (and * {@link DocumentModel.version}) and the token an instruction's `ifMatch` * precondition compares against, so it can be computed — e.g. as an HTTP * ETag — without parsing the document. * * Pass a string to hash its UTF-8 encoding, or a `Uint8Array` (including a * `Buffer`) to hash those bytes verbatim, undecoded; a string and its UTF-8 * bytes yield the same token. * * The derivation is part of the public contract: tokens held by clients must * keep validating, so it will not change without a major version bump. */ export declare const versionOf: (document: string | Uint8Array) => string; /** * Build the internal document model: an ordered tree of sections (each owning * its heading, direct body and trailing gap), a block overlay indexed into * those sections, and the frontmatter. Every byte of the content region * belongs to exactly one section's marker, content or trailingGap, so the tree * losslessly partitions the document. */ export declare const buildModel: (document: string) => DocumentModel; /** Iterate every section, root first, in document order. Exposed for tests. */ export declare const eachSection: (root: SectionNode, visit: (node: SectionNode) => void) => void; /** * Reconstruct the source document from the section partition. Used to prove the * tree tiles the content region losslessly. */ export declare const serializeModel: (document: string, model: DocumentModel) => string; //# sourceMappingURL=model.d.ts.map