fix(markdown): preserve descriptive file-link labels #10794
ClosedGigioxx(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/10794/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:M
- apps/web/src/components/ChatMarkdown.tsx line 2970OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2963,8 +2966,5 @@29632966 );29642967 }296529682966- return fileLinkChip(2967- fileLinkMeta,2968- `[${fileLinkMeta.basename}](${normalizedHref})`,2969- props.className,2970- normalizedHref,2969+ const label = nodeToPlainText(children);2970+ const copyMarkdown = `[${label || fileLinkMeta.basename}](${normalizedHref})`;
- apps/web/src/components/ChatMarkdown.tsx line 2970OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2963,8 +2966,5 @@29632966 );29642967 }296529682966- return fileLinkChip(2967- fileLinkMeta,2968- `[${fileLinkMeta.basename}](${normalizedHref})`,2969- props.className,2970- normalizedHref,2969+ const label = nodeToPlainText(children);2970+ const copyMarkdown = `[${label || fileLinkMeta.basename}](${normalizedHref})`;apps/web/src/components/ChatMarkdown.tsx lines 2975 to 2976OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2963,8 +2966,11 @@29632966 );29642967 }296529682966- return fileLinkChip(2967- fileLinkMeta,2968- `[${fileLinkMeta.basename}](${normalizedHref})`,2969- props.className,2970- normalizedHref,2969+ const label = nodeToPlainText(children);2970+ const copyMarkdown = `[${label || fileLinkMeta.basename}](${normalizedHref})`;2971+ const chip = fileLinkChip(fileLinkMeta, copyMarkdown, props.className, normalizedHref);2972+ return isMarkdownFileLinkLabel(label, normalizedHref) ? (2973+ chip2974+ ) : (2975+ <span data-markdown-copy={copyMarkdown}>2976+ {children} ({chip})packages/client-runtime/src/markdownLinks.ts lines 350 to 351OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -339,3 +339,13 @@339339 if (!pathForCompare.startsWith(`${rootForCompare}/`)) return null;340340 return normalizedPath.slice(normalizedRoot.length + 1);341341 }342+343+export function isMarkdownFileLinkLabel(label: string, href: string): boolean {344+ if (!label.trim()) return true;345+ const target = parseMarkdownFileLink(href);346+ if (!target) return false;347+ const path = (parseMarkdownFileLink(label)?.path ?? splitFilePathPosition(label.trim()).path)348+ .replaceAll("\\", "/")349+ .replace(/^\.\//, "");350+ const targetPath = target.path.replaceAll("\\", "/");351+ return path === targetPath || targetPath.endsWith(`/${path}`);
juliusmarminge added labelsmacroscope-review
- packages/client-runtime/src/markdownLinks.ts line 362Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -339,3 +339,14 @@339339 if (!pathForCompare.startsWith(`${rootForCompare}/`)) return null;340340 return normalizedPath.slice(normalizedRoot.length + 1);341341 }342+343+export function isMarkdownFileLinkLabel(label: string, href: string): boolean {344+ if (!label.trim()) return true;345+ const target = parseMarkdownFileLink(href);346+ if (!target) return false;347+ const path = (parseMarkdownFileLink(label)?.path ?? splitFilePathPosition(label.trim()).path)348+ .replaceAll("\\", "/")349+ .replace(/^\.\//, "")350+ .replace(/([^/:])\/+$/, "$1");351+ const targetPath = target.path.replaceAll("\\", "/").replace(/([^/:])\/+$/, "$1");352+ return path === targetPath || targetPath.endsWith(`/${path}`);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -480,4 +481,8 @@480481 }481482 const presentation = resolveMarkdownLinkPresentation(node.href ?? "");482483 if (presentation.kind === "file") {483- return appendRun(runs, presentation.label, {484+ const descriptive = !isMarkdownFileLinkLabel(nodeTextContent(node), presentation.href);485+ if (descriptive) {486+ appendChildren(runs, node, { ...context, href: presentation.href });487+ }488+ return appendRun(runs, descriptive ? ` (${presentation.label})` : presentation.label, {
- @@ -3101,7 +3131,14 @@31013131 );31023132 }310331333134+ const label = nodeToPlainText(children);3135+ const escapedLabel = (label.trim() ? label : fileLinkMeta.basename)3136+ .replaceAll("\\", "\\\\")3137+ .replaceAll("[", "\\[")3138+ .replaceAll("]", "\\]");3139+ const copyMarkdown = `[${escapedLabel}](${normalizedHref})`;31043140 return fileLinkChip(31053141 fileLinkMeta,3106- `[${fileLinkMeta.basename}](${normalizedHref})`,3142+ copyMarkdown,31073143 normalizedHref,3144+ isMarkdownFileLinkLabel(label, normalizedHref) ? undefined : children,@@ -344,3 +344,13 @@344344 if (!pathForCompare.startsWith(`${rootForCompare}/`)) return null;345345 return normalizedPath.slice(normalizedRoot.length + 1);346346 }347+348+export function isMarkdownFileLinkLabel(label: string, href: string): boolean {349+ if (!label.trim()) return true;350+ const target = parseMarkdownFileLink(href);351+ if (!target) return false;352+ // Windows paths compare case-insensitively, matching workspaceRelativeFilePath.353+ const caseInsensitive = isWindowsAbsolutePath(stripSlashPrefixedWindowsDrive(target.path));354+ const normalize = (value: string) => (caseInsensitive ? value.toLowerCase() : value);355+ const path = normalize(356+ (parseMarkdownFileLink(label)?.path ?? splitFilePathPosition(label.trim()).path)
juliusmarminge closed this
Sign in to join this conversation.




macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed