fix(web): keep Windows drive paths as chat file links #7182
Closedmaslinedwin(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/7182/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/markdown-links.ts lines 143 to 143OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -108,0 +123,21 @@123+ if (target) return `${target.path}${target.hash}`;124+ // Leftover `D:/...` / UNC hrefs never became file: URLs. Keep them so125+ // react-markdown's urlTransform does not treat the drive letter as a protocol.126+ if (127+ WINDOWS_DRIVE_PATH_PATTERN.test(normalizedHref) ||128+ WINDOWS_UNC_PATH_PATTERN.test(normalizedHref)129+ ) {130+ return normalizedHref;131+ }132+ return null;133+}134+135+const HAS_WINDOWS_FILESYSTEM_PATH_PATTERN = /[A-Za-z]:[\\/]|\\\\/;136+const INLINE_MARKDOWN_LINK_PATTERN =137+ /(!?\[[^\]]*])\(([ \t]*)(?:<([^>\n]*)>|([^ \t\n)]+))((?:[ \t]+(?:"[^"]*"|'[^']*'|\([^)]*\)))?)([ \t]*)\)/g;138+const MARKDOWN_LINK_DEFINITION_PATTERN =139+ /^([ \t]{0,3}\[[^\]]+\]:[ \t]+)(?:<([^>\n]*)>|(\S+))((?:[ \t]+(?:"[^"]*"|'[^']*'|\([^)]*\)))?)([ \t]*)$/gm;140+const ANGLE_AUTOLINK_PATTERN = /<([^<>\n]+)>/g;141+const PROTECTED_MARKDOWN_SPAN_PATTERN = /!?\[[^\]]*]\([^)]*\)|!?\[[^\]]*]\[[^\]]*]|<[^>\n]+>/g;142+const BARE_WINDOWS_PATH_PATTERN =143+ /(?<![A-Za-z0-9_/])(?:[A-Za-z]:[\\/][^\s<>[\]()`]+|\\\\[^\s<>[\]()`\\/]+(?:[\\/][^\s<>[\]()`]+)+)/g;apps/web/src/components/ChatMarkdown.tsx line 1595OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1589,4 +1591,5 @@15891591 li({ node, children, ...props }) {15901592 const listItemStart = node?.position?.start.offset;15911593 const markerOffset =1592- typeof listItemStart === "number" ? findTaskListMarkerOffset(text, listItemStart) : null;1594+ typeof listItemStart === "number"1595+ ? findTaskListMarkerOffset(markdownSource, listItemStart)@@ -1382,3 +1383,4 @@13821383 serverConfig?.availableEditors ?? [],13831384 );13841385 const diffThemeName = resolveDiffThemeName(resolvedTheme);1386+ const markdownSource = useMemo(() => normalizeWindowsMarkdownFileLinks(text), [text]);
- apps/web/src/components/ChatMarkdown.tsx line 1586Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1589,4 +1591,6 @@15891591 li({ node, children, ...props }) {15901592 const listItemStart = node?.position?.start.offset;15911593 const markerOffset =1592- typeof listItemStart === "number" ? findTaskListMarkerOffset(text, listItemStart) : null;1594+ typeof listItemStart === "number"1595+ ? findTaskListMarkerOffset(markdownSource, listItemStart)1596+ : null;apps/web/src/markdown-links.ts line 275OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -108,0 +255,21 @@255+ const withDestinations = rewriteWindowsLinkDefinitions(256+ rewriteInlineWindowsLinkDestinations(text),257+ );258+ return autolinkBareWindowsPaths(rewriteWindowsAngleAutolinks(withDestinations));259+}260+261+const FENCED_CODE_SEGMENT_PATTERN = /(```[\s\S]*?(?:```|$)|~~~[\s\S]*?(?:~~~|$))/;262+const INLINE_CODE_SEGMENT_PATTERN = /(`[^`\n]+`)/;263+264+function mapOutsideInlineCode(text: string, transform: (chunk: string) => string): string {265+ return text266+ .split(INLINE_CODE_SEGMENT_PATTERN)267+ .map((segment, index) => (index % 2 === 1 ? segment : transform(segment)))268+ .join("");269+}270+271+function mapMarkdownOutsideCode(markdown: string, transform: (text: string) => string): string {272+ return markdown273+ .split(FENCED_CODE_SEGMENT_PATTERN)274+ .map((segment, index) => (index % 2 === 1 ? segment : mapOutsideInlineCode(segment, transform)))275+ .join("");
- @@ -108,0 +303,21 @@303+ const lineLimit = lineEnd === -1 ? markdown.length : lineEnd;304+ const line = markdown.slice(index, lineLimit);305+ const newline = lineEnd === -1 ? "" : "\n";306+ const matchLine = lineWithoutCarriageReturn(line);307+308+ if (openFence !== null) {309+ output += line + newline;310+ if (isClosingFenceLine(matchLine, openFence)) {311+ openFence = null;312+ }313+ index = lineLimit + newline.length;314+ continue;315+ }316+317+ const fence = openingFenceMarker(matchLine);318+ if (fence !== null) {319+ openFence = fence;320+ output += line + newline;321+ index = lineLimit + newline.length;322+ continue;323+ }
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:
2d1d1b92-b417-4931-aedf-510bf787fdaaYou 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