Skip to content

Markdown preview: repo-relative links open a broken app URL instead of the target file #1161

@srid

Description

@srid

Problem

In the Code tab's rendered Markdown preview, a repo-relative link — e.g. [the limitations doc](packages/solid-markdown/LIMITATIONS.md) — opens a new browser tab at the app origin (http://localhost:5173/packages/solid-markdown/LIMITATIONS.md), which just boots a fresh kolu SPA at a bogus route. It does not open the linked file.

Root cause

The link pipeline never distinguishes a repo-relative href from a real external one:

  • safeHref (packages/solid-markdown/src/url-policy.ts) resolves a scheme-less path against a fake https://markdown.local/ base, sees https:, and declares it safe.
  • applyLinkPolicy (packages/solid-markdown/src/sanitize.ts) then stamps target="_blank" rel="noopener noreferrer".
  • On click, the browser resolves the relative href against the real document origin (http://localhost:5173/) and opens the bogus URL in a new tab.

Images already do the right thing — resolveImageSrc resolves relative image paths against the document's directory and loads them via the per-terminal file route. Links have no equivalent.

Proposed fix (GitHub-faithful)

Mirror the resolveImageSrc host-wiring for links: when a Markdown anchor's href is repo-relative (no scheme — reuse hasOwnScheme), resolve it against the current document's directory and open that repo file in the Code tab's browse view (reusing the same file-open front door the tree/terminal path:line links use), instead of letting the browser navigate the app.

Rough layers:

  • @kolu/solid-markdown: tag scheme-less anchors and intercept their clicks in bindInteractions, calling a new optional host callback (e.g. onNavigateRelative(path)).
  • @kolu/solid-fileview markdown renderer: thread the callback through.
  • right-panel/BrowseFileDispatcher: wire it to resolve the path against the current file's dir and open it in the Code tab.

Test gap to close

The existing e2e (packages/tests/features/code-tab.feature, scenario "applies the link policy to raw inline anchors") only asserts that a relative anchor is kept with target=_blank/rel=noopener — it never clicks it, so it codified the new-tab markup as correct and was blind to the bogus destination. The fix should add a scenario that clicks a relative link and asserts the target file opens in the Code tab (and that the app origin is never navigated).

Current behavior (this PR)

Until this lands, repo-relative links are treated as ordinary external links (open in a new tab). Tracked as a known limitation in packages/solid-markdown/LIMITATIONS.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions