[FIX] Cross-page links resolve in the merged PDF - #89
Merged
Conversation
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.
Summary
Cross-page links in the merged mooring PDF (the Summary/Stack/Grid/serial header pills and the instrument links) were dead:
combine_mooring_pdfrendered each source HTML file in its ownrender()call and page-concatenated them, and WeasyPrint only resolves internal links within a singlerender(). This rebuilds the combiner to assemble one HTML document and render it once, so the links resolve, and makes tall tables paginate sensibly.What's changed
Single-document combine.
combine_mooring_pdfnow reads the ordered report files, assembles them into one HTML document via a pure, tested string transform (_build_combined_html+ helpers inreports/_pdf.py), and renders that once.Per-page id namespacing. Ids are reused across pages (
top,qc,ts,vars, …), so the transform rewritesid="x"→id="{slug}__x"and same-pagehref="#x"→href="#{slug}__x"(slugssummary/stack/grid/instr-{serial}) before concatenation; otherwise every#topwould resolve to the first page.Inter-page link rewriting. Links to sibling report files (
{mooring}_stack_report.html, theinstrument/…#startand../forms) become in-document anchors targeting each page's masthead#{slug}__top(every page carriesid="top"frombase.html).Regex, not an HTML parser. Safe because the report CSS has no id selectors and figures are base64 PNG, not inline SVG — a
SAFETY CONDITIONcomment in_pdf.pyrecords that SVG would also require rewritingurl(#…)/xlink:href.Table pagination.
_PRINT_CSSnow lets tables break at row boundaries (tr { break-inside: avoid }), repeats the header row on continuation pages (thead { display: table-header-group }), and keeps headings with their content (h2,h3,h4 { break-after: avoid }) — instead of forcing a tall table whole onto the next sheet.Tests.
test_pdf_report.py: slug derivation, the pure transform (namespacing, inter-page + fragment rewrite, style dedup,.pdf-pagewrapping, a completeness tripwire scanning broader than the transform), and a WeasyPrint-gated end-to-end test asserting the link resolves to an internal/Destwith no dead.html. Verified on the real dune2 fixture.Notes
combine_mooring_pdf's signature and output path are unchanged. The PDF's internal layout changes (links now internal; tables paginate at rows), but nothing parses the PDF — no breaking change for callers.importorskip("weasyprint")(thepdfextra); they skip without it, as the existing PDF tests already do.break-after: avoidthere and it is not reproducible in a minimal case. Logged for follow-up (candidate fix: emit the heading as a table<caption>).