fix(markdown): preserve descriptive file-link labels #15509
Mergedmaria-rcksmerged 4 commits into
main fromrefs/pull/15509/headmerged by maria-rcks View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
- @@ -1184,17 +1186,9 @@11841186 highlightCode: boolean,11851187 ): CustomRenderers => ({1186- link: ({ children, href = "" }) => {1188+ link: ({ children, node, href = "" }) => {11871189 const presentation = resolveMarkdownLinkPresentation(href);11881190 if (presentation.kind === "file") {11891191 return (1190- <NativeText1191- className="font-t3-bold"1192- onPress={() => onLinkPress(href)}1193- style={{ color: inlineTextColor }}1194- >1195- <Image1196- source={markdownFileIconSource(presentation.icon)}1197- style={markdownLinkStyles.inlineIcon}1198- />1199- {presentation.label}1200- </NativeText>1192+ <MarkdownLinkLabelContext.Provider value>1193+ <NativeText onPress={() => onLinkPress(href)} style={{ color: inlineTextColor }}>1194+ {!isMarkdownFileLinkLabel(getTextContent(node), href) && <>{children} </>}apps/mobile/modules/t3-markdown-text/src/nativeMarkdownText.ts line 510OutdatedResolvedby maria-rcks@@ -482,3 +501,10 @@482501 }483502 const presentation = resolveMarkdownLinkPresentation(node.href ?? "");484503 if (presentation.kind === "file") {504+ const label = textNodeContent(nodeTextContent(node));505+ if (!isMarkdownFileLinkLabel(label, presentation.href)) {506+ const fileRuns: NativeMarkdownTextRun[] = [];507+ const fileContext = {508+ ...context,509+ href: presentation.href,510+ sourceText: `[${label.replace(/[\\[\]]/g, "\\$&")}](<${presentation.href}>)`,
- apps/mobile/modules/t3-markdown-text/src/nativeMarkdownText.ts lines 504 to 510OutdatedResolvedby maria-rcks@@ -482,3 +501,10 @@482501 }483502 const presentation = resolveMarkdownLinkPresentation(node.href ?? "");484503 if (presentation.kind === "file") {504+ const label = textNodeContent(nodeTextContent(node));505+ if (!isMarkdownFileLinkLabel(label, presentation.href)) {506+ const fileRuns: NativeMarkdownTextRun[] = [];507+ const fileContext = {508+ ...context,509+ href: presentation.href,510+ sourceText: `[${label.replace(/[\\[\]]/g, "\\$&")}](<${presentation.href}>)`,apps/web/src/components/ChatMarkdown.tsx lines 3250 to 3251Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3233,7 +3235,17 @@32333235 );32343236 }323532373236- return fileLinkChip(3237- fileLinkMeta,3238- `[${fileLinkMeta.basename}](${normalizedHref})`,3239- normalizedHref,3238+ const label = nodeToPlainText(children);3239+ const start = node?.position?.start.offset;3240+ const end = node?.position?.end.offset;3241+ const source = start !== undefined && end !== undefined ? text.slice(start, end) : "";3242+ const copyMarkdown =3243+ source.startsWith("[") && source.includes("](")3244+ ? source3245+ : `[${(label || fileLinkMeta.basename).replace(/[\\[\]]/g, "\\$&")}](${normalizedHref})`;3246+ const chip = fileLinkChip(fileLinkMeta, copyMarkdown, normalizedHref);3247+ return isMarkdownFileLinkLabel(label, normalizedHref) ? (3248+ chip3249+ ) : (3250+ <span data-markdown-copy={copyMarkdown}>3251+ {children} {chip}packages/client-runtime/src/markdownLinks.ts lines 274 to 275OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -265,3 +265,11 @@265265 return `${position.path}:${position.line}${position.column ? `:${position.column}` : ""}`;266266 }267267268+/** Keeps filename and destination-path labels compact without discarding prose. */269+export function isMarkdownFileLinkLabel(label: string, href: string): boolean {270+ const destination = parseMarkdownFileLink(href);271+ if (!destination) return false;272+ const normalize = (path: string) =>273+ path.replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/+$/, "");274+ let labelPath = normalize(splitFilePathPosition(label.trim()).path);275+ let destinationPath = normalize(destination.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
- @@ -813,3 +815,11 @@813815 );814816 }815817818+function MarkdownImage(props: {819+ readonly node: MarkdownNode;820+ readonly renderImage: MarkdownImageRenderer;821+}) {822+ const insideLink = useContext(MarkdownLinkLabelContext);823+ if (insideLink) return <NativeText>{props.node.alt ?? props.node.title ?? ""}</NativeText>;824+ return props.node.href825+ ? props.renderImage({
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
maria-rcks merged this1d013c7
maria-rcks closed this
Sign in to join this conversation.




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