fix(web): make Windows file links clickable in chat #8081
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/8081/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- apps/web/src/components/ChatMarkdown.tsx lines 364 to 369Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -353,11 +355,15 @@353355354356 /**355- * Fenced code also lands on the `code` component, and inline vs block is no356- * longer distinguishable there once both render `<code>` — so inline spans are357- * tagged on the mdast, where the distinction still exists. Code inside a link358- * label stays untagged: linkifying it would nest an anchor inside the link's359- * anchor and steal its clicks.357+ * Preserve Windows drive links as allowed `file:` URLs before sanitization.358+ * The same traversal tags inline code while it can still be distinguished359+ * from fenced code. Code inside links stays untagged to avoid nested anchors.360360 */361-function remarkTagInlineCode() {361+function remarkNormalizeLinksAndTagInlineCode() {362362 return (tree: MarkdownAstNode) => {363363 const visit = (node: MarkdownAstNode, insideLink: boolean) => {364+ if (365+ (node.type === "link" || node.type === "definition") &&366+ typeof node.url === "string" &&367+ WINDOWS_DRIVE_PATH_REGEX.test(node.url)368+ ) {369+ node.url = `file:///${node.url.replaceAll("\\", "/")}`;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/web/src/components/ChatMarkdown.tsx lines 952 to 954Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -943,4 +950,7 @@943950944951 function normalizeMarkdownLinkHrefKey(href: string): string {945952 const normalizedHref = normalizeMarkdownLinkDestination(href);946- return rewriteMarkdownFileUriHref(normalizedHref) ?? normalizedHref;953+ const rewrittenHref = rewriteMarkdownFileUriHref(normalizedHref) ?? normalizedHref;954+ return WINDOWS_DRIVE_PATH_REGEX.test(rewrittenHref)955+ ? rewrittenHref.replaceAll("\\", "/")956+ : rewrittenHref;
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
06761d41-e9e7-4726-9e9d-12144a63bdf9You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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