Skip to content

fix(preview): open links in the default browser instead of navigating the preview - #9

Merged
maxmilian merged 2 commits into
mainfrom
fix/preview-link-handling
Aug 28, 2026
Merged

maxmilian merged 2 commits into
mainfrom
fix/preview-link-handling

Conversation

@maxmilian

Copy link
Copy Markdown
Owner

Problem

Clicking a link in the preview did three different things depending on the link, because PreviewView.Coordinator implemented no navigation policy at all — behaviour fell through to WebKit defaults:

Link Old behaviour
plain https://… navigated in place, replacing the whole preview with the remote page
target="_blank", ⌘-click handed to the system → opened the default browser
mailto: and other schemes handed to the system
relative ./other.md resolved against Bundle.main.resourceURL (the app bundle), so it always failed

Fix

LinkPolicy (pure, unit-tested) maps a clicked URL to one of four actions:

  • http / https / mailto / any other scheme → .openExternally → NSWorkspace.shared.open, navigation cancelled, so the preview is never replaced
  • in-page #anchor → .allow, so TOC links still scroll the preview
  • .md / .markdown / .txt … → .openDocument → opens in a new Markout window
  • any other local file (.pdf, images) → .openExternally
  • non-link navigations (the template load itself) → .allow

Because the preview is loaded with loadHTMLString(baseURL: Bundle.main.resourceURL), a relative href resolves inside the app bundle. LinkPolicy detects file URLs under baseURL and re-anchors the remaining relative path onto the document's own directory, which is what makes relative links work for the first time. ContentView now passes documentURL through to PreviewView.

Tests

10 new tests in LinkPolicyTests; full suite green (129 tests, 24 suites).

Manually verified by launching the app on a document containing an external link, a mailto: link, a relative .md link and an in-page anchor.

Version

Bumped to 0.2.0 (CFBundleVersion 1 → 2) — covers everything since v0.1.0: the markout CLI, the Find menu, reload-from-disk, and this fix.

🤖 Generated with Claude Code

https://claude.ai/code/session_018tFSJJcyAkW3PbRv1WLuYo

maxmilian and others added 2 commits August 28, 2026 23:35
… the preview

The preview WebView had no navigation policy, so link behavior fell through to
WebKit defaults: a plain http(s) click replaced the whole preview with the
remote page, target=_blank and non-http schemes were handed to the system, and
relative links resolved against the app bundle (baseURL) so they always failed.

Add a pure LinkPolicy that maps a clicked URL to allow / open externally / open
as a Markout document / cancel, re-anchoring bundle-relative file URLs onto the
document's own directory, and wire it into PreviewView.decidePolicyFor.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018tFSJJcyAkW3PbRv1WLuYo
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018tFSJJcyAkW3PbRv1WLuYo
@maxmilian
maxmilian merged commit 2713bb3 into main Aug 28, 2026
1 check passed
@maxmilian
maxmilian deleted the fix/preview-link-handling branch August 28, 2026 15:52
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.

1 participant