/** * @file * * A note's footnotes, footnote references and link reference definitions, collected the way Obsidian's metadata worker * collects them. The worker reads them with `remark-footnotes` 2 (inline notes on) on top of `remark-parse` 8: * * - A link reference definition with a destination is a `referenceLinks` entry: its label as written, and its destination * unescaped, with its character references decoded. * - A footnote definition is a `footnotes` entry, keyed by its label lower-cased. * - A footnote reference, `[^label]`, is a `footnoteRefs` entry, but only when some footnote definition carries its label; * any other is plain text. * - An inline footnote, `^[text]`, is a `footnotes` entry whose position is its text's, keyed `[inline`, where `n` * counts the inline footnotes and the definitions first referenced before it. An empty one, `^[]`, is a `footnoteRefs` * entry keyed `''` instead, at the whole of it. * * A definition counts wherever it is, a top-level section or a block inside a blockquote, a callout or a list item (see * `markdown-container-definitions.ts`). * * Approximated: references are found by a scan of the inline text of the sections that hold any, which knows escapes, * code spans and fenced code but none of the other inline constructs. */ import type { FootnoteCache, FootnoteRefCache, ListItemCache, Pos, ReferenceLinkCache, SectionCache } from 'obsidian'; /** * What {@link collectReferences} needs. */ export interface CollectReferencesParams { /** * The ranges of the fenced code blocks, which hold no reference. */ readonly codeZones: readonly (readonly [number, number])[]; /** * The note's full text. */ readonly content: string; /** * The note's list items, at every depth, which a definition can sit in. */ readonly listItems: readonly ListItemCache[]; /** * Builds a position from two offsets. */ readonly makePos: (startOffset: number, endOffset: number) => Pos; /** * The note's top-level sections, sorted. */ readonly sections: readonly SectionCache[]; } /** * A footnote the note references, which Obsidian's worker copies into the footnote list it appends to the note. */ export interface FootnoteSource { /** * Whether it is a footnote definition, whose text is the whole definition, label included, and the line break after * it when the note goes on; otherwise it is an inline footnote, whose text is what it holds. */ readonly isDefinition: boolean; /** * The footnote's text. */ readonly text: string; } /** * What {@link collectReferences} finds. */ export interface NoteReferences { /** * The `footnoteRefs` collection. */ readonly footnoteRefs: FootnoteRefCache[]; /** * The `footnotes` collection. */ readonly footnotes: FootnoteCache[]; /** * The footnotes the note references, each once, in the order each is first referenced. When there is any, Obsidian's * worker appends a `text` and an `element` section to the note, the latter holding these. */ readonly footnoteSources: FootnoteSource[]; /** * The `referenceLinks` collection. */ readonly referenceLinks: ReferenceLinkCache[]; } /** * Collects a note's footnotes, footnote references and link reference definitions. * * @param params - The note, its sections and fenced code blocks, and a way to build a position. * @returns The three collections, and the footnotes the note references. */ export declare function collectReferences(params: CollectReferencesParams): NoteReferences; /** * Finds where an inline footnote closes, a port of the worker's tokenizer: the `]` that balances the opening `[`, with a * `\` escaping the character after it and the brackets inside a code span ignored. * * @param content - The note's full text. * @param contentStart - The offset just past the `^[`. * @param end - The offset the inline text ends at. * @returns The offset of the closing `]`, or `-1` when there is none. */ export declare function findInlineNoteClose(content: string, contentStart: number, end: number): number; /** * Finds the inline footnotes in inline text, the ones nested in another left out. * * @param text - The text. * @returns What each inline footnote holds, in document order. */ export declare function findInlineNoteTexts(text: string): string[]; /** * Finds where a footnote reference's label ends: a non-empty run holding no space, tab or line break, and a `]`. * * @param content - The note's full text. * @param labelStart - The offset just past the `[^`. * @param end - The offset the inline text ends at. * @returns The offset of the closing `]`, or `-1` when there is none. */ export declare function findReferenceLabelEnd(content: string, labelStart: number, end: number): number; /** * Measures a run of backticks. * * @param content - The text. * @param start - The offset the run starts at. * @param end - The offset the inline text ends at. * @returns How many backticks the run holds, `0` when `start` holds none. */ export declare function measureBacktickRun(content: string, start: number, end: number): number;