Skip to content

Fix relative file links in Markdown previews - #3549

Draft
Eigenwise wants to merge 1 commit into
wavetermdev:mainfrom
Eigenwise:fix/markdown-relative-file-links
Draft

Eigenwise wants to merge 1 commit into
wavetermdev:mainfrom
Eigenwise:fix/markdown-relative-file-links

Conversation

@Eigenwise

Copy link
Copy Markdown

Problem

Clickable relative file links in a Markdown preview currently pass their raw href to openLink. The preview already supplies the document directory and connection for resolving images, but link activation does not use them. Consequently, a link such as [Target](target.md) is dispatched to an external opener (or a web block) without resolving it against the displayed document.

Minimal reproduction

  1. Create a directory with README.md and target.md.
  2. Put [Target](target.md) in README.md.
  3. Open README.md in Wave's Markdown preview and click Target.
  4. The current handler dispatches target.md as an unresolved URL. The expected behavior is file-preview navigation to the sibling document on the same connection.

The same handler path affects relative PDF and audio-file links. This is a Markdown-preview issue, separate from terminal/OSC 8 hyperlinks.

Change

  • Resolve non-schemed file destinations through the existing connection-aware FileJoinCommand, using the displayed document directory.
  • Navigate through the preview model's existing goHistory route rather than the external URL opener.
  • Decode URL-encoded filenames once, removing query/fragment suffixes before decoding so escaped filename characters are preserved.
  • Discard delayed resolution results if the preview's originating file or connection has changed.
  • Preserve same-document heading navigation, existing external URL dispatch, and shared Markdown behavior without a preview-navigation callback.
  • Keep the existing parser/sanitizer policy unchanged; contain resolution failures without falling back to the external opener.

The link component is extracted for focused activation tests. Additional tests render the actual MarkdownPreview/Markdown/parser/sanitizer/link chain, with mocked RPC and native-navigation boundaries.

Verification

Checked against base 9f1c9670d407be3b93cf090319a63ef30bf54d0e with Node 22 and npm 10 on Windows:

  • npm test -- --run --fileParallelism=false: 98 tests passed (51 existing + 47 new).
  • npm run build:dev: passed (main, preload and renderer bundles).
  • Prettier checks for new files and preview-markdown.tsx: passed. The existing markdown.tsx has formatting issues on the unchanged base as well; unrelated formatting is left untouched.
  • git diff --check: passed.
  • npx tsc --noEmit: reports 17 existing preview-mock diagnostics on both pristine base and patched source. Diagnostic output was compared byte-for-byte after the final repair, with no new diagnostics.

Dependencies were installed from the committed lockfile with workspace/lifecycle scripts skipped, followed by the inspected Electron binary installer. The missing docs-workspace @docusaurus/tsconfig produces a non-failing warning in the test/build commands.

Draft / remaining validation

This is a draft pending a live Windows UI check. The automated integration tests exercise parsed-anchor activation and the callback boundary, not a live Electron window, real remote/WSL filesystem, backend RPC, audio playback, or persisted preview history. The Go backend/package build was not run.

This does not add Obsidian [[wikilinks]] or cross-document fragment scrolling. A file link with a query/fragment suffix opens the file itself; query-only destinations are not navigated. Schemed destinations keep their existing behavior and sanitizer restrictions.

AI-assisted implementation and review; the contribution is limited to this file-link repair and synthetic regression cases.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants