Fix introspection-driven features (page numbering, refs, outline)#4
Open
ntodd wants to merge 2 commits into
Open
Fix introspection-driven features (page numbering, refs, outline)#4ntodd wants to merge 2 commits into
ntodd wants to merge 2 commits into
Conversation
The Engine was wired with EmptyIntrospector and laid out exactly once, so Typst's two-pass introspection — which resolves page counters, refs, the outline, and any raw_typst calling counter/here/query — could never see the document's actual positions. Page numbering rendered the literal pattern on every page, refs found nothing, and the outline was empty. Build the body and styles once, then run the same MAX_ITERS=5 convergence loop the Typst CLI uses (compile_impl in vendor/typst/crates/typst/src/lib.rs): each iteration feeds the previous PagedDocument's introspector into a fresh engine, stopping when comemo::Constraint validates against the new document's introspector.
label/1 produced Content::empty().labelled(lbl), an empty placeholder
carrying the label. Refs then couldn't find any numbered element, so
[heading(1, "Foo"), label("foo")] followed by ref("foo") resolved to
nothing.
Mirror Typst's markup eval (vendor/typst/crates/typst-eval/src/markup.rs):
when a Label node is built, walk backwards through the current sequence to
the last non-Unlabellable element and attach the label there. Applied in
both build_content and cc so labels inside nested bodies behave the same.
Also suppress the auto-parbreak that would otherwise sit between a block
and its trailing label and sever the attachment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Engine was wired with
EmptyIntrospectorand laid out once, so anything that depends on Typst's second-pass resolution silently broke: page numbering rendered the literal pattern on every page, refs resolved to nothing, and the outline was empty.Two fixes:
world.rs— build the body/styles once, then run the same MAX_ITERS=5 convergence loop the Typst CLI uses (compile_implinvendor/typst/crates/typst/src/lib.rs). Each iteration feeds the previousPagedDocument's introspector into a fresh engine; the loop exits whencomemo::Constraintvalidates against the new document's introspector.convert.rs—label/1was producingContent::empty().labelled(lbl), an empty placeholder carrying the label, so[heading(1, "Foo"), label("foo")]never associated the label with the heading. Mirror Typst's markup eval (typst-eval/src/markup.rs): when aLabelnode is built, walk backwards through the sequence to the last non-Unlabellableelement and attach the label there. Also suppress the auto-parbreak that would otherwise slip between a block and its trailing label.Testing
New regression test (
test/folio_test.exs) compiles two pages with identical bodies separated by a pagebreak withpage_numberingenabled, and asserts the SVG strings differ. This isn't perfect, but like other tests, does not require PDF introspection tools.