/** * A parsed Obsidian wikilink (`[[Target]]`, `[[Target#section]]`, * `[[Target^block]]`, `[[Target|alias]]`, or any combination). * * Fields are populated when the corresponding fragment is present in the * source; otherwise omitted (not `undefined`-valued — the property is * absent so callers can use `"section" in link` without ambiguity). */ export interface Wikilink { /** Original payload between the `[[` `]]` delimiters (everything before * any alias `|`). Useful for round-tripping the link unchanged. */ raw: string; /** Note target (basename or relative path, no `.md` suffix). For * `[[Auth/oauth#setup|OAuth]]` this is `"Auth/oauth"`. */ target: string; /** Heading anchor, if any (the text after `#`). */ section?: string; /** Block reference, if any (the text after `^`). */ block?: string; /** Display alias, if any (the text after `|`). */ alias?: string; } /** A parsed Obsidian embed (`![[Target]]`). Same shape as {@link Wikilink}; * the `!` prefix is the only syntactic distinction. */ export type Embed = Wikilink; /** * A parsed Obsidian note: frontmatter + body + the structural extracts * we feed retrieval over (wikilinks, embeds, tags). * * Code fences and inline code are stripped before link / tag extraction * so example markdown inside ``` blocks doesn't pollute the structural * index. The `body` field keeps the original (post-frontmatter) content * so callers can render verbatim. */ export interface ParsedNote { /** Frontmatter object (empty when no YAML block, or when YAML is malformed). */ frontmatter: Record; /** Post-frontmatter body — verbatim, including code fences. */ body: string; /** 1-based line number in the ORIGINAL source where `body` begins (= the count * of frontmatter + delimiter lines + 1; 1 when there's no frontmatter). Lets * consumers that chunk `body` (the embedding pipeline) report FILE-absolute * line numbers that match the FTS5 index, which chunks the full content. * v3.10.0-rc.17 (audit M1). */ bodyStartLine: number; /** All `[[wikilinks]]` found in the body (after stripping code spans). */ wikilinks: Wikilink[]; /** All `![[embeds]]` found in the body (after stripping code spans). */ embeds: Embed[]; /** Union of frontmatter tags + inline `#tags` (deduped, normalized to * drop leading `#`). Order is insertion order from frontmatter first. */ tags: string[]; } /** * Parse an Obsidian markdown source string. Splits frontmatter (via * `parseFrontmatter`) from body, then extracts wikilinks, embeds, and tags * from a code-stripped view of the body. Malformed YAML falls back to * treating the whole input as body (no throw). * * @param source - Raw note text (UTF-8). * @returns Parsed structure ready for indexing or rendering. * @example * ```ts * const parsed = parseNote("---\ntags: [idea]\n---\nSee [[Other]]."); * parsed.frontmatter; // { tags: ["idea"] } * parsed.wikilinks; // [{ raw: "Other", target: "Other" }] * parsed.tags; // ["idea"] * ``` */ export declare function parseNote(source: string): ParsedNote; /** * Linear, non-backtracking scan for `[[wikilink]]` (embed=false) / `![[embed]]` * (embed=true) INNER captures, in source order. Byte-equivalent to the `m[1]` * sequence of the former regexes `/(?): string[]; /** * Strip fenced (` ``` ` / `~~~`) and inline (`` `…` ``) code from Markdown so that * `[[wikilinks]]`, `#tags`, and `![[embeds]]` inside code are NOT treated as real — * the canonical sanitizer `parseNote` applies before every extraction. Any consumer that * extracts links/tags from a note body MUST route through this (or `parseNote`) so its * view matches the parser + Obsidian, which do not index links/tags inside code blocks. * * Exported in v3.11.5-rc.3 (post-rc.2 re-sweep, PARSER-DESYNC class) — several always-on * tools (query_base, get_communities, validate_note_proposal) re-extracted from the RAW * body and disagreed with this sanitizer; guarded by `tests/parser-desync-invariant.test.ts`. * * v3.11.6-rc.1 — reconciled with the char-aware line-walkers on the UNCLOSED-fence shape: * the paired regexes require a closing fence, so an unclosed ` ``` ` used to leak its body * (phantom links/tags), while the walkers correctly treat it as code-to-EOF. `dropUnclosedBlockFence` * closes that divergence up front. Now covered by `tests/canonical-parser-agreement.test.ts`. * * KNOWN RESIDUAL (pre-existing, deferred): the non-greedy paired regexes still diverge from the * char-aware walkers on an EXOTIC shape — a line-leading self-contained inline `` ``` `` span * *inside* a fenced block makes the regex pair fences early, so a `[[link]]`/`#tag` still inside the * block can surface as a phantom (a read-side false positive in `buildWikilinkGraph`/`queryBase`/ * `validateNoteProposal`; not DoS, not data loss). This is the regex-vs-char-aware gap the meta-audit * named for the deferred canonical structure accessors (a fence-aware iterator on `ParsedNote`), not a * v3.11.6-rc.1 regression — the behavior is byte-identical to prior stable on that shape. */ export declare function stripCodeAndInline(text: string): string; //# sourceMappingURL=parser.d.ts.map