PDF: render /Link annotations as <a> overlays (URI + internal GoTo)#591
Merged
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5346eef950
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
1622bbc to
a8c565b
Compare
5346eef to
803c25d
Compare
andiwand
added a commit
that referenced
this pull request
Jul 5, 2026
Address Codex review on #591: - Reject active URI schemes (javascript:/data:/…) in /Link /URI actions; only navigable schemes and relative refs become live hrefs. - Emit target="_self" on internal #pN anchors so they override the document's <base target="_blank"> and scroll in place. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A page's /Link annotations (ISO 32000-1 12.5.6.5) now become absolutely
positioned <a> overlays:
- a /URI action -> external link (href attribute-escaped, opened in _blank via
the document target);
- a /GoTo action or a direct /Dest -> internal "#pN" link; each page div gains
a matching id="pN".
Destinations resolve a page reference (first element of a [page ...] array) to
its index, including named destinations via the catalog /Dests dictionary and
the /Names /Dests name tree (depth-guarded). The /Rect is mapped through the
page transform to page-box points. Resolved entirely in the HTML layer from the
parser's raw annotation dictionaries — no parser/IR change — and emitted by
both the dual-layer and single-layer render paths.
Also:
- Fix parse_page crashing (map::at) on a page with no /Contents — a blank page
carrying only annotations is valid; guard the lookup.
- Elevate attribute escaping to html::escape_attribute in common.{hpp,cpp}
(next to escape_text), replacing the local helper.
Adds an end-to-end PdfFile test rendering a mini-PDF with a /URI, a direct
/Dest, and a named /GoTo destination, asserting the anchors and page ids in
both render modes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address Codex review on #591: - Reject active URI schemes (javascript:/data:/…) in /Link /URI actions; only navigable schemes and relative refs become live hrefs. - Emit target="_self" on internal #pN anchors so they override the document's <base target="_blank"> and scroll in place. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
5cfa8a0 to
780d66f
Compare
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
🤖 Generated with Claude Code
Stacked on #590.
A page's
/Linkannotations (ISO 32000-1 12.5.6.5) now become absolutely-positioned<a>overlays.What lands
/URIaction → external link.hrefis attribute-escaped; opened in_blank(the document already sets that target)./GoToaction or direct/Dest→ internal#pNlink; each pagedivgains a matchingid="pN".[page …]array) → its index, including named destinations via the catalog/Destsdictionary and the/Names /Destsname tree (depth-guarded)./Rectis mapped through the page transform to page-box points.Resolved entirely in the HTML layer from the parser's raw annotation dictionaries — no parser/IR change — and emitted by both the dual-layer and single-layer render paths.
Also
parse_pagecrashed (map::at) on a page with no/Contents— a blank page carrying only annotations is valid (exactly the link-only cover-page case). Guarded the lookup.html::escape_attributeincommon.{hpp,cpp}(next toescape_text), replacing a local helper.Tests
End-to-end
PdfFiletest rendering a mini-PDF with a/URI, a direct/Dest, and a named/GoTodestination — asserts the anchors and page ids in both render modes. Full non-snapshot suite (421 tests) green; real PDFs render without regression and now carryid="pN".Deferred (noted in
AGENTS.md): remote/launch actions (/GoToR,/Launch), destination scroll position/zoom (only the target page is used), and non-/Linkannotation appearances.