Skip to content

fix: special characters in markdown links#4195

Open
Yash-Singh1 wants to merge 4 commits into
mainfrom
yash/markdown-links-fix
Open

fix: special characters in markdown links#4195
Yash-Singh1 wants to merge 4 commits into
mainfrom
yash/markdown-links-fix

Conversation

@Yash-Singh1

@Yash-Singh1 Yash-Singh1 commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Before

Before: markdown file path rendered as a generic route link
[route](/Users/yashsingh/p/projects/t3chat-new/apps/expo/src/app/(chat)/chat/[threadId].tsx)

After

After: markdown file path rendered as a file link
[route](/Users/yashsingh/p/projects/t3chat-new/apps/expo/src/app/(chat)/chat/[threadId].tsx)

Reopen of #2846

What Changed

  • Better relative path detection
  • Used a remark plugin to handle same filenames in different subdirectories instead of raw markdown parsing w/ regex
  • Fixed links w/ special characters in them

Why

Filenames with square brackets or parenthesis or other special characters in them (param route files, route group folders) were unlinkable to, this pr fixes that

UI Changes

N/A

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Touches link classification and sanitization in chat rendering; misclassification could break external links or mis-open paths, but scope is limited to markdown link handling with expanded tests.

Overview
Fixes chat markdown file links so paths with route groups, brackets, and other punctuation resolve and open correctly instead of being treated as broken or external URLs.

markdown-links: normalizeMarkdownLinkDestination now unescapes markdown-escaped punctuation (while leaving Windows backslash paths untouched) instead of stripping angle brackets. Relative path detection is reworked: multi-segment paths can include () and [], encoded segments are handled, extensionless paths like scripts/release still qualify conservatively, and ambiguous strings such as docs/user%20guide are no longer classified as files. Angle-bracket destination unwrapping is removed from this flow.

ChatMarkdown: The regex pre-scan that built a href→meta map is replaced by a remark plugin that walks link nodes, resolves file metadata from the AST url, and stamps dataFileLinkParentSuffix on nodes for duplicate-basename disambiguation; the sanitize schema allows that attribute. Link rendering resolves meta at click/render time, and urlTransform preserves raw hrefs when resolveMarkdownFileLinkTarget recognizes a file path.

Reviewed by Cursor Bugbot for commit e9b4530. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix special characters in markdown file links

  • Replaces angle-bracket unwrapping in normalizeMarkdownLinkDestination with markdown punctuation unescaping, so paths containing special characters (e.g. (, ), [) are handled correctly.
  • Rewrites isLikelyPathCandidate in markdown-links.ts with a segment-based approach that reduces false positives on ambiguous encoded web paths while still accepting extensionless multi-segment paths.
  • Adds a createFileLinkDisambiguationPlugin remark plugin that annotates file link AST nodes with a parent-suffix property, replacing the previous approach of computing suffixes from raw markdown text; anchor rendering then reads this via a DOM data attribute.
  • Fixes markdownUrlTransform so file-path-looking links that are not file URIs are passed through unchanged instead of being mangled by defaultUrlTransform.

Macroscope summarized e9b4530.

@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 000db045-5cdb-447f-a9ee-61a8de111cc1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yash/markdown-links-fix

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.

@github-actions github-actions Bot added the size:L 100-499 changed lines (additions + deletions). label Jul 20, 2026
Comment thread apps/web/src/markdown-links.ts
Comment thread apps/web/src/markdown-links.ts
Comment thread apps/web/src/components/ChatMarkdown.tsx
@macroscopeapp

macroscopeapp Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This bug fix involves non-trivial refactoring of markdown link parsing logic - replacing regex extraction with an AST-based plugin approach and changing path normalization behavior. While well-tested and scoped to markdown rendering, the behavioral changes to link resolution warrant human review.

You can customize Macroscope's approvability policy. Learn more.

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

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant