/** * @fileoverview Read-modify-write helpers for the YAML frontmatter block of a * note's raw content. Used by the composed manage-frontmatter / manage-tags * tools when the upstream Local REST API has no single-call equivalent. Also * holds the wikilink span rule (`wikilinkCloser`) that the inline tag reader * and `obsidian_get_note`'s outgoing-link parser share. * @module services/obsidian/frontmatter-ops */ /** * The outcome of a frontmatter mutation. A block that cannot be re-emitted * faithfully is reported as a value rather than written or thrown: these * helpers back a read-modify-write, so "cannot" means the caller would * otherwise hand the vault a note with properties it never asked to change — * or lose the block outright. The handlers turn `ok: false` into a typed, * declared tool error and issue no write. */ export type FrontmatterEdit = { ok: true; content: string; } | { ok: false; problem: string; }; /** The two halves of a note: its raw frontmatter prefix and everything after it. */ export interface Splice { /** Everything after the closing fence. The whole file when `hasFrontmatter` is false. */ body: string; /** Closing fence with the newlines around it. Empty when `hasFrontmatter` is false. */ close: string; hasFrontmatter: boolean; /** Opening fence and its newline. Empty when `hasFrontmatter` is false. */ open: string; /** The frontmatter prefix verbatim — `open + yamlText + close`, and `''` when there is none. */ raw: string; /** YAML text between the `---` fences. Empty when `hasFrontmatter` is false. */ yamlText: string; } /** * Split a note into its raw frontmatter prefix and its body. `raw + body` * reconstructs the input byte for byte, which is what makes this the primitive * for body-scoped mutations: rebuild with the original `raw` and the frontmatter * block is untouched by construction. Rebuilding through `serializeFrontmatter` * would instead re-emit the YAML and can reformat scalars nobody asked to change. * * A file whose fence is never closed, whose `---` sits below the first line, or * whose opening `---` carries trailing whitespace has no frontmatter — the whole * thing is body, which is also how Obsidian reads each of those shapes. An empty * block is a block: `---` immediately followed by `---` splits with an empty * `yamlText`, matching the properties block Obsidian reads there. */ export declare function splice(content: string): Splice; /** * Describe why `yamlText` is not usable as a frontmatter block, or `undefined` * when it is. Catches YAML that no longer parses, YAML that parses to * something other than a mapping — the two states in which Obsidian reads no * properties at all — and YAML that parses but cannot be emitted again. * * That last one is its own class: an unresolved alias (`bad: *missing`) is * accepted by `parseDocument` with an empty `doc.errors` and refused only by * the emitter, so the round trip is what surfaces it. * * It cannot catch an edit that stays well-formed while meaning something else: * a renamed key, a scalar that re-parses as a different type. Those are valid * YAML and pass this check. */ export declare function frontmatterParseError(yamlText: string): string | undefined; /** * The full file content with `key` removed from the frontmatter. A file with * no frontmatter, or one where the key isn't present, comes back unchanged. * * Refuses — rather than writing — when the existing block does not parse as a * mapping or the mutation leaves YAML that cannot be emitted. Both were silent * data loss before: a block the parser recovered into a single malformed key * was "emptied" by deleting that key, taking every sibling property and the * block itself with it (issue #123). */ export declare function deleteFrontmatterKey(content: string, key: string): FrontmatterEdit; export interface TagReconcileResult { /** Tags actually changed (added/removed) at one or more locations. */ applied: string[]; /** Updated content with the requested tag mutations applied. */ content: string; /** Tags that were already in the desired state at the targeted location(s). */ skipped: string[]; } export type TagOperation = 'add' | 'remove'; export type TagLocation = 'frontmatter' | 'inline' | 'both'; /** A completed reconciliation, or the reason the frontmatter half refused. */ export type TagReconcileOutcome = ({ ok: true; } & TagReconcileResult) | { ok: false; problem: string; }; /** * Add or remove tags across frontmatter (`tags:` array) and inline `#tag` * syntax. Inline detection skips code spans, link spans, HTML comments, math, * and a `#` preceded by anything but whitespace, line start, or markup such * as `**` or `
` — see `splitProtectedSegments` and `TAG_LEFT_BOUNDARY`. */ export declare function reconcileTags(content: string, tags: string[], operation: TagOperation, location: TagLocation): TagReconcileOutcome; /** * The end of the wikilink each `[[` in `text` opens, or `undefined` when it * opens none, as Obsidian's metadata cache reads links: from `[[` to the first * `]]` on the same line. Single `[` and `]` belong to the link * (`[[Note|see [1]]]` links `Note`), a second `[[` before that `]]` starts the * link over (`[[a [[b]]` links `b`), and no link crosses a line break. * * Every opener before the same `[[`, `]]`, or line break stops there, so that * stop is scanned for once and shared. Openers must be looked up in ascending * order; the scan is then linear in `text`. */ export declare function wikilinkCloser(text: string): (open: number) => number | undefined; /** * Read-only helpers for `obsidian_manage_tags list`. Inline tags are read from * the body only, and through the same protected-segment split and left boundary * a removal uses, so what `list` reports is exactly what `remove` can reach — a * `#` inside a YAML scalar, code, an HTML block or comment, math, an image, or * a link's destination or label, or one glued to the character before it * (`\#`, `(#x`), is none of them. A tag runs for as long as `TAG_CHAR` * matches, and an all-digit run is not a tag. */ export declare function listTagsFromContent(content: string, frontmatter: Record): { frontmatter: string[]; inline: string[]; }; //# sourceMappingURL=frontmatter-ops.d.ts.map