/** * Reconcile a subtree render's links with the single page it actually * produced. * * A fragment preview is rendered with upstream's `subtree` parameter: the * whole document is assembled — so numbering is right and every `` * finds its target — but only one division is emitted. The links, though, are * written for the multi-page build that assembling implies. PreTeXt hands back * `sec-two.html#thm-b` for a theorem in another section, `sec-one.html#thm-a` * for one on this very page, and a bare `sec-three.html` for each table of * contents entry. None of those files exist: there is one page, in memory. * * Two fixes, from one question — is the target on this page? * * - **On the page.** Rewrite to a bare `#id`. The link then does exactly * what the built book's would: scroll to the target. Answering by looking * for the `id` in the rendered HTML, rather than by reasoning about * PreTeXt's filename scheme, means this cannot drift when that scheme * changes, and it costs one pass over the page. * * - **Not on the page.** Drop the `@href` and explain in a tooltip. A link * that silently does nothing is worse than an obvious non-link, and the * reader has no other way to learn that the preview is showing one section * of something larger. The element, its classes and its text are all left * alone, so the page still reads like the built one — the same tactic, and * the same `aria-disabled` spelling, as the inert print-preview button in * preview-html.xsl (see PRINTOUT_LINK_OVERRIDE in scripts/refresh-xsl.mjs). * * Applied to the rendered HTML rather than in the stylesheet because the * question cannot be answered during the transform: whether a target lands on * the page is a fact about the finished output, and upstream computes every * URL through `mode="url"` from a dozen call sites. One pass over the result * is one rule that cannot fall out of step with them. */ /** Default tooltip on a link whose target is not on the previewed page. */ export declare const OFF_PAGE_MESSAGE = "This live preview shows a single division, so links into the rest of the document do not work here."; export interface RewriteXrefLinkOptions { /** * Tooltip for a link whose target is not on this page. Defaults to * {@link OFF_PAGE_MESSAGE}. When the link already carries a tooltip — an * `` is given one naming its target, like "Theorem 2.1: Beta" — the * two are joined rather than the original being thrown away. */ offPageMessage?: string; } /** * Point every link in `html` at something real: same-page targets become * `#id`, and links leaving the page become inert with an explanatory tooltip. * * Safe to run on any rendered page. A whole-document preview emits only * same-page anchors and absolute URLs, so nothing matches and the HTML comes * back unchanged. */ export declare function rewriteXrefLinks(html: string, options?: RewriteXrefLinkOptions): string;