Repository navigation
feat: preserve PDF URL hash fragments (#page, #search) in links and embeds - #385
mrsaynothing wants to merge 1 commit into
Conversation
…mbeds When a markdown link references a PDF with a URL hash fragment (e.g. [Guide](guide.pdf#page=3&search=installation)), the fragment is now preserved through the entire resolution pipeline so Chromium's built-in PDF viewer can navigate to the correct page and highlight search terms. Closes #295 Changes: - local-assets.ts: add hrefFragment() helper; append fragment to PDF iframe src in buildEmbed() and anchor href in enhanceLocalAssetNodes() - cm-live-preview.ts: append fragment to LocalPdfWidget iframe src; pass fragment through pin-reference button handlers - store.ts: add pinnedRefFragment (runtime-only); extend noteRefs type with optional fragment; accept fragment param in pinAssetReference/pinAssetReferenceForNote - PinnedReferencePane.tsx: read fragment from store; apply to iframe URL and cache keys - Editor.tsx: extract and pass fragment on Cmd+click PDF links - Preview.tsx: extract and pass fragment in context-menu handlers
…r-note pin Follow-up to the PDF fragment feature (#385): a per-note asset pin without a fragment fell back to the global pin's fragment, so a per-note pinned PDF could open at an unrelated page. Tie the fragment to the same pin the path comes from.
|
Thanks for this, @wholetthekfcgo! Reviewed and merged into the Cherry-picked as 5315c91 with your authorship preserved. I verified in the running app that the fragment now reaches the target in every path: markdown link hrefs, inline PDF embeds, the standalone card's inline view, the pinned reference pane, and Cmd/Ctrl+click, with plain fragment-less links unaffected. One small follow-up I added on top (f22d481): in Closing here since it's already merged via the release branch (it won't auto-close because it targeted |
Problem
Markdown links to PDFs with URL hash fragments (e.g.
#page=3,#search=keyword) lose the fragment at multiple points in the resolution pipeline. Chromium's built-in PDF viewer natively supports these fragments, but they never reach it.Closes #295
Before
[Guide](guide.pdf#page=3&search=installation)→ PDF opens at page 1 (fragment stripped)After
[Guide](guide.pdf#page=3&search=installation)→ PDF opens at page 3 with "installation" highlightedWorks everywhere: inline embeds, the pinned reference pane, preview anchors, and Cmd/Ctrl+click in the editor.
Example
Supported Chromium PDF parameters
Since we pass the fragment through to the native viewer, all standard parameters work:
#page=N— jump to page N#search=keyword— highlight search results#page=N&search=keyword— combined jump + search#zoom=scale— set zoom levelUse case
Link notes directly to specific PDF content without copying context into the note itself. For example, a bug report note can link to page 42 of a specification PDF where the regression is documented.
Testing
vault/inbox/[Test](file.pdf#page=2)on its own line![[file.pdf#page=2&search=something]]embed syntaxScope
pinnedRefFragmentis runtime-only (not persisted across sessions)Changes
local-assets.tshrefFragment()helper; append fragment to PDF iframe src inbuildEmbed()and anchor href inenhanceLocalAssetNodes()cm-live-preview.tsLocalPdfWidgetiframe src; pass fragment through pin-reference button handlersstore.tspinnedRefFragment(runtime-only, not persisted); extendnoteRefstype with optional fragment; accept fragment param inpinAssetReference/pinAssetReferenceForNotePinnedReferencePane.tsxEditor.tsxPreview.tsx