Repository navigation
fix(markdown): preserve non-line fragments in preview links - #332661
Conversation
Fix verified RED->GREEN. Markdown file links drop non-line fragments (#page=3) - PDFs always open on page 1 at openDocumentLink.ts:43
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the built-in markdown language features extension where file links with non-line fragments (e.g. [pdf](file.pdf#page=3)) lost their fragment when opened, causing PDF viewers to always land on page 1. It adds a fallback in MdLinkOpener.openDocumentLink so that, when the fragment is not a recognized line/location fragment, the raw fragment is still attached to the target URI.
Changes:
- Add an
elsebranch after the location-fragment handling to extract the raw fragment (#...) from the link text and set it on the URI when no line fragment matches. - Preserves fragments like
#page=3/#nameddestfor PDF and other custom viewers while keeping line-navigation behavior intact.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Done, fixed in bea9c5f, the raw fragment is now decoded with decodeURIComponent (wrapped in try/catch) before Uri.with, matching getLocationFragmentFromLinkText. |
|
please open an issue for this with steps to reproduce the problem |
|
Opened #338920 with repro steps. |
|
Thanks for the fix. I tested the exact changed opener from bea9c5f in an isolated Markdown extension copy, running in a real Code OSS Dev window with However, Ctrl+clicking the same relative link in the Markdown source editor still opens page 1 with the patch. The encoded variant The preview path uses Could fragment preservation be handled at that shared boundary, or otherwise cover both opening paths, with regression tests for fragment forwarding/decoding and existing line/heading navigation? Both interactions are included in #338920. I understand the shared-boundary fix may require an upstream language-service change and dependency update; if this PR is intentionally preview-only, please make that scope explicit and keep the editor case tracked separately. [comment authored by copilot] |
|
Thanks for checking both paths. I've narrowed the title and description to Markdown preview links. The relative-link Ctrl+click case, including |
Markdown preview clicks on
[pdf](file.pdf#page=3)lose their non-line fragment. This change forwards the percent-decoded fragment inMdLinkOpener, allowing a fragment-aware viewer to open the requested page. Existing line and heading resolution paths are unchanged.This PR covers Markdown preview links only. Relative-link Ctrl+click in the Markdown source editor remains tracked in #338920, including the encoded
#page%3D3case. This PR does not close that issue.Maintainer validation at bea9c5f used
mathematic.vscode-pdf0.2.6 in Code OSS Dev: the patched preview opened page 3, while the baseline opened page 1. The same report confirms that the relative-link source-editor case is still unfixed.