Skip to content

fix(markdown): open file links at source locations - #847

Open
Harry19081 wants to merge 1 commit into
developfrom
dev/fix-markdown-file-line-links
Open

fix(markdown): open file links at source locations#847
Harry19081 wants to merge 1 commit into
developfrom
dev/fix-markdown-file-line-links

Conversation

@Harry19081

Copy link
Copy Markdown
Member

Problem

Agent-authored markdown file links such as /repo/src/View.tsx:220 passed the trailing source location into filesystem lookup and tab creation as part of the filename. The editor therefore tried to open a nonexistent View.tsx:220 file instead of View.tsx at line 220. React Markdown also removed supported file://, Windows drive-letter, and Tauri asset hrefs before the local-link click handler could classify them.

Solution

Parse trailing :line and :line:column syntax at the markdown file-reference boundary, keep the filesystem path clean, and pass the 1-based line through the existing editor target-line option. Apply the same parser to inline-code file navigation. Preserve supported local filesystem references during URL transformation only for href; non-link attributes and unsupported schemes continue through React Markdown's default sanitizer.

The resulting invariant is that markdown navigation sends path and source location as separate values. No persisted data or historical cleanup is involved.

Potential risks

A POSIX filename that legitimately ends in :<positive integer> will be interpreted as a source-location reference when opened from chat markdown. Optional columns are accepted so the path is parsed correctly, but navigation currently targets the line only because the WorkStation tab contract has no target-column field. Workspace-relative markdown href behavior is unchanged.

Rollback is a straight revert of commit 04250d017; there are no schema, dependency, persistence, API, or wire-format changes.

Audit

Reviewed the adjacent markdown link pipeline for absolute POSIX paths, file:// URLs, Windows drive-letter paths, Tauri asset URLs, home-relative paths, inline code, remote schemes, and non-href URL attributes. Relative href resolution remains intentionally out of scope because the current renderer does not infer a workspace root for links.

Verification

  • npx vitest run src/components/MarkDown/markdownFileRef.test.ts src/components/MarkDown/MarkdownLocalImage.test.ts src/components/MarkDown/markdownUtils.test.ts src/components/MarkDown/markdownUrlTransform.test.ts — 4 files, 28 tests passed.
  • npx prettier --check <8 changed files> — passed.
  • npx eslint <8 changed files> — passed.
  • npm run typecheck — passed.
  • git diff --check — passed.
  • Commit hooks reran lint-staged formatting/lint and scoped TypeScript checks — passed.

No screenshot is included because this changes click navigation and target-line behavior without changing rendered appearance. The owning parser and editor-opening boundary are covered by regression tests.

Pre-commit hook ran. Total eslint: 5, total circular: 0
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