/** * Cross-references to anchors (#262, #263): `:ref{id="sec-intro"}` naming a * heading with an identifier, an anchor set in the text or a container * opened with one. The label comes from the book outline — the heading's * number and title, the anchor's text — and, for a page reference, the * label of the page the target landed on in the previous layout round. */ import type { ContentBlock, InlineSpan } from '../parse/index.js'; import type { OutlineEntry } from '../types.js'; /** A target a cross-reference may name, as the outline knows it. */ export interface AnchorTarget { id: string; kind: 'heading' | 'anchor'; /** Heading level (1–6); absent for an anchor. */ level?: number; /** The printed number of a numbered heading (`''` otherwise). */ number: string; /** A heading's title, an anchor's text (`[text]{#id}`) or a container's * `title`; `''` when it has none. */ title: string; /** Label of the page it landed on, once laid out. */ pageLabel?: string; /** 0-based book page index of that page, once laid out. */ pageIndex?: number; /** A labelled equation's or a numbered statement's default label (#530): * "(3)", "Theorem 2". */ numberLabel?: string; } /** Anchor targets by identifier. */ export type AnchorTargets = ReadonlyMap; /** The targets of an outline: every heading with an identifier and every * anchor, the first setting of an identifier winning. */ export declare function anchorTargetsOf(outline: readonly OutlineEntry[] | undefined): AnchorTargets; /** The pandoc-crossref prefixes (`@sec:intro`, `@fig:map`): a reference * written with one names the identifier with or without it. */ export declare const CROSSREF_PREFIXES: readonly string[]; /** The identifier a reference names, without a pandoc-crossref prefix * (`sec:intro` → `intro`); `undefined` when it carries none. */ export declare function unprefixedId(id: string): string | undefined; /** The resource a reference names: its id as written, else without a * pandoc-crossref prefix (`@fig:map` names resource `map`) when only that * one is a resource. */ export declare function resourceRefId(id: string, isResource: (id: string) => boolean): string; /** The target `id` names: the identifier as written, else without its * pandoc-crossref prefix. */ export declare function findAnchorTarget(targets: AnchorTargets | undefined, id: string): AnchorTarget | undefined; /** The words a cross-reference prints around a number, per document * language: `{n}` stands for the number or the page label. */ export interface CrossRefStrings { /** A level-1 heading: "chapter 3". */ chapter: string; /** Any other heading: "section 3.2". */ section: string; /** A page: "p. 112". */ page: string; /** The style of a reference that sets none (`crossRefs.defaultStyle`). */ defaultStyle?: 'default' | 'number' | 'title' | 'page'; } /** The built-in cross-reference words for a document language. */ export declare function defaultCrossRefStrings(locale: unknown): CrossRefStrings; /** What a page reference prints before the target is laid out. */ export declare const UNKNOWN_PAGE = "?"; /** A cross-reference's label and whether it is words (#702): the text of * a `text="…"` override or the title of its target, which a line may * break at its spaces; a number, a page or a counted label is not. */ export interface RefLabel { text: string; words: boolean; } /** * The label of a cross-reference to an anchor target, and whether it is * words: * - `default` / `full`: a numbered heading as "chapter 3" / "section 3.2", * an unnumbered one by its title, an anchor by its text, else its page; * - `number`: the bare number (the title when there is none); * - `title`: the title or the anchor's text; * - `page`: "p. 112"; `pageNumber`: "112". * `text="…"` overrides it all. */ export declare function anchorRefLabel(ref: NonNullable, target: AnchorTarget, strings: CrossRefStrings): RefLabel; /** The label of a cross-reference to an anchor target (see * {@link anchorRefLabel}). */ export declare function resolveAnchorRefLabel(ref: NonNullable, target: AnchorTarget, strings: CrossRefStrings): string; /** Whether a reference prints its target's page, so its label moves with * the layout (the document is laid out again until it settles, #263). */ export declare function refPrintsPage(ref: NonNullable, target: AnchorTarget | undefined, defaultStyle?: CrossRefStrings['defaultStyle']): boolean; /** Whether the parsed content holds a reference that names no resource of * `resourceIds` — one that may name an anchor (#262). */ export declare function hasAnchorRefs(blocks: readonly ContentBlock[], resourceIds: ReadonlySet): boolean; /** Whether a reference of the parsed content prints the page of an anchor * of `targets`: the document is then laid out until the pages settle. */ export declare function printsAnchorPages(blocks: readonly ContentBlock[], targets: AnchorTargets, defaultStyle?: CrossRefStrings['defaultStyle']): boolean; //# sourceMappingURL=crossRefs.d.ts.map