Skip to main content

resolve_page_references

Function resolve_page_references 

Source
pub fn resolve_page_references(
    document: &mut Document,
    label_pages: &BTreeMap<String, u32>,
) -> bool
Expand description

Rewrite every @page(label) reference’s visible text to its target’s page number, drawn from label_pages (a label→1-based-page map produced by layout). Returns whether any text changed, so the fixpoint driver can tell when the document settled.

A label absent from label_pages resolves to its ?label? placeholder: an undeclared label was already reported as MOS0033 at lower time, and a declared label whose target produced no content simply has no page. The placeholder is written every call, so a reference whose label drops out of a later map reverts from a stale number back to the placeholder rather than keeping it.

Idempotent and a pure function of the document’s page-reference labels and label_pages: the text is re-derived from the map each call, never from the previously-written number, so repeated calls with the same map are no-ops and the result never depends on call history.