Conversation
Markdown links such as `[report.pdf#page=12](/api/files/...?type=read#page=12)` opened the in-app viewer at page 1: the href is resolved to a filesystem path before it reaches the viewer, so the fragment never made it to the iframe URL. Parse the page selector in MarkdownBody, carry it through the file tab state, and append it to the `type=read` iframe URL so the browser's PDF viewer jumps to the requested page. Opening a different page of the same file remounts the viewer, while any other fragment (for example `#L42`) is ignored as before.
Seeds a session with a generated multi-page PDF whose pages print their own number, then clicks a `#page=N` markdown link and asserts the viewer iframe URL. Requires the full Chromium build: the Chromium headless shell has no PDF viewer and downloads the file instead, so nothing renders in the iframe.
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.
Problem
Opening a PDF through the in-app viewer always lands on page 1, even when the markdown
link points at a specific page:
resolveLocalFileHref()resolves that href to/home/me/books/report.pdf, and the viewerbuilds its iframe URL from the path alone — so the
#page=183fragment never reaches thePDF viewer. A relative link (
books/report.pdf#page=183) behaves the same way.Only the in-app viewer is affected. A link that the browser opens itself — a top-level
/api/files/...?type=read#page=N, whichresolveLocalFileHref()deliberately ignores andleaves as a plain
target="_blank"anchor — does jump, because the browser's native PDFviewer handles
#page=Non its own.Cause
resolveLocalFileHref()strips#…while resolving the href to a filesystem path(
lib/file-links.ts), andDocumentViewerthen builds its iframe URL from that path alonevia
getFileApiUrl(filePath, "read", …), which has no fragment parameter. There is no routefor the fragment from the markdown href to the iframe URL.
Change
Carry the page selector from the markdown href through to the iframe URL:
lib/file-links.ts— addparsePdfPageFragment(): accepts#page=N(positive integer),returns
nullfor anything else.components/MarkdownBody.tsx—onOpenFile(filePath, page?).components/AppShell.tsx,components/file-tab-state.ts,components/TabBar.tsx— storepageon the tab and bumpviewerRevisionwhen it changes, so the viewer remounts andjumps when another page of the same file is opened.
components/FileViewer.tsx— newinitialPageprop;DocumentViewerappends#page=Nfor PDFs only.
Behaviour for every other fragment (
#L42,#section, …) is unchanged.Verification
Static:
node_modules/.bin/tsc --noEmit— cleaneslinton all touched files — cleannpm test— 1026/1026 pass, including new cases for#page=parsing (rejects#page=0,#page=-1,#page=abc,#page=12&zoom=100) and for the page-change remountRuntime (
e2e/pdf-page-fragment.mjs, full Chromium build):[PDF page 183](...report.pdf#page=183)opens the viewer with#page=183in the iframeURL, and the rendered document shows page 183