The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 09:00 UTC
feat(markdown): show the GitHub mark for github.com links (#10324)
Co-authored-by: Claude Code <noreply@anthropic.com>
Julius Marminge committed
Sep 5, 2026 at 23:21 UTC
272d6d747ef214f50dbd9d0051120de12ffa3591
12 files changed
+135
-27
apps/mobile/modules/t3-markdown-text/assets/link-icons/github.png
Binary files /dev/null and b/apps/mobile/modules/t3-markdown-text/assets/link-icons/github.png differ
apps/mobile/modules/t3-markdown-text/ios/T3MarkdownText.mm
+19
-10
@@ -60,14 +60,16 @@ static void T3MarkdownTextApplyAttachments(
60
NSString *imageUri = [NSString stringWithUTF8String:attachmentRange.imageUri.c_str()];
61
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
62
UIImage *image = images[imageUri];
63
- if ([imageUri hasPrefix:@"sf:"]) {
64
- NSString *symbolName = [imageUri substringFromIndex:3];
65
- UIColor *foregroundColor =
66
- [attributedString attribute:NSForegroundColorAttributeName
67
- atIndex:attachmentRange.location
68
- effectiveRange:nil] ?: UIColor.labelColor;
69
- image = [[UIImage systemImageNamed:symbolName] imageWithTintColor:foregroundColor
70
- renderingMode:UIImageRenderingModeAlwaysOriginal];
63
+ const BOOL isSymbol = [imageUri hasPrefix:@"sf:"];
64
+ if (isSymbol) {
65
+ image = [UIImage systemImageNamed:[imageUri substringFromIndex:3]];
66
+ }
67
+ UIColor *foregroundColor = [attributedString attribute:NSForegroundColorAttributeName
68
+ atIndex:attachmentRange.location
69
+ effectiveRange:nil];
70
+ if (image != nil && (isSymbol || attachmentRange.tintWithForeground)) {
71
+ image = [image imageWithTintColor:foregroundColor ?: UIColor.labelColor
72
+ renderingMode:UIImageRenderingModeAlwaysOriginal];
73
}
74
attachment.image = image ?: [[UIImage alloc] init];
75
const CGFloat attachmentSize = T3MarkdownTextAttachmentSize(attachmentRange);
@@ -79,8 +81,15 @@ static void T3MarkdownTextApplyAttachments(
81
const NSRange range = NSMakeRange(
82
attachmentRange.location,
83
MIN(attachmentRange.length, attributedString.length - attachmentRange.location));
82
- NSAttributedString *attachmentString =
83
- [NSAttributedString attributedStringWithAttachment:attachment];
84
+ NSMutableAttributedString *attachmentString =
85
+ [[NSAttributedString attributedStringWithAttachment:attachment] mutableCopy];
86
+ // Keep the run color on the attachment so a later re-apply (after the image
87
+ // loads asynchronously) still tints with the link color, not labelColor.
88
+ if (foregroundColor != nil) {
89
+ [attachmentString addAttribute:NSForegroundColorAttributeName
90
+ value:foregroundColor
91
+ range:NSMakeRange(0, attachmentString.length)];
92
+ }
93
[attributedString replaceCharactersInRange:range withAttributedString:attachmentString];
94
}
95
}
apps/mobile/modules/t3-markdown-text/ios/T3MarkdownTextShadowNode.h
+2
@@ -26,6 +26,8 @@ struct T3MarkdownTextAttachmentRange {
26
size_t location;
27
size_t length;
28
std::string imageUri;
29
+ /// Recolor the loaded image with the run's foreground color, like `sf:` symbols.
30
+ bool tintWithForeground;
31
};
32
33
inline Float T3MarkdownTextAttachmentSize(const T3MarkdownTextAttachmentRange &) {
apps/mobile/modules/t3-markdown-text/ios/T3MarkdownTextShadowNode.mm
+11
@@ -11,6 +11,7 @@ namespace facebook::react {
11
static constexpr Float ParagraphStyleEncodingOffset = 1000;
12
static constexpr auto FileAttachmentNativeIdPrefix = "t3-file:";
13
static constexpr auto SkillAttachmentNativeIdPrefix = "t3-skill:";
14
+static constexpr auto LinkAttachmentNativeIdPrefix = "t3-link:";
15
16
static void applyParagraphStyles(
17
NSMutableAttributedString *attributedString,
@@ -192,6 +193,7 @@ Size T3MarkdownTextShadowNode::measureContent(
193
utf16Offset,
194
1,
195
props.nativeId.substr(std::char_traits<char>::length(FileAttachmentNativeIdPrefix)),
196
+ false,
197
});
198
} else if (
199
props.nativeId.rfind(SkillAttachmentNativeIdPrefix, 0) == 0 && fragmentLength > 0) {
@@ -200,6 +202,15 @@ Size T3MarkdownTextShadowNode::measureContent(
202
1,
203
props.nativeId.substr(
204
std::char_traits<char>::length(SkillAttachmentNativeIdPrefix)),
205
+ false,
206
+ });
207
+ } else if (
208
+ props.nativeId.rfind(LinkAttachmentNativeIdPrefix, 0) == 0 && fragmentLength > 0) {
209
+ attachmentRanges.push_back(T3MarkdownTextAttachmentRange{
210
+ utf16Offset,
211
+ 1,
212
+ props.nativeId.substr(std::char_traits<char>::length(LinkAttachmentNativeIdPrefix)),
213
+ true,
214
});
215
}
216
utf16Offset += fragmentLength;
apps/mobile/modules/t3-markdown-text/package.json
+1
@@ -21,6 +21,7 @@
21
"exports": {
22
".": "./index.ts",
23
"./file-icons": "./src/markdownFileIcons.ts",
24
+ "./link-icons": "./src/markdownLinkIcons.ts",
25
"./links": "./src/markdownLinks.ts",
26
"./markdown": "./src/nativeMarkdownText.ts",
27
"./primitive": "./src/MarkdownTextPrimitive.tsx",
apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.ios.tsx
+27
-7
@@ -12,6 +12,8 @@ import {
12
13
import { MarkdownTextPrimitive } from "./MarkdownTextPrimitive";
14
import { markdownFileIconSource } from "./markdownFileIcons";
15
+import { markdownLinkIconSource } from "./markdownLinkIcons";
16
+import { resolveMarkdownLinkIcon } from "./markdownLinks";
17
import type { NativeMarkdownTextRun } from "./nativeMarkdownText";
18
import type {
19
MarkdownFileContextMenu,
@@ -177,10 +179,14 @@ export function NativeMarkdownSelectableText(props: {
179
}) {
180
const colorScheme = useColorScheme();
181
const menu = useContext(MarkdownFileContextMenuContext);
180
- const containsInlineFileIcon = props.runs.some((run) => run.fileIcon != null);
182
+ const containsInlineIcon = props.runs.some(
183
+ (run) =>
184
+ run.fileIcon != null ||
185
+ (run.externalHost != null && resolveMarkdownLinkIcon(run.externalHost) !== null),
186
+ );
187
const attachAndroidText = useCallback(
188
(textView: RNText | null) => {
183
- if (Platform.OS !== "android" || !containsInlineFileIcon || textView === null) {
189
+ if (Platform.OS !== "android" || !containsInlineIcon || textView === null) {
190
return;
191
}
192
const reactTag = findNodeHandle(textView);
@@ -188,7 +194,7 @@ export function NativeMarkdownSelectableText(props: {
194
installMarkdownCopySanitizer(reactTag);
195
}
196
},
191
- [containsInlineFileIcon],
197
+ [containsInlineIcon],
198
);
199
const occurrences = new Map<string, number>();
200
const prefixedExternalLinks = new Set<string>();
@@ -198,6 +204,7 @@ export function NativeMarkdownSelectableText(props: {
204
occurrences.set(signature, occurrence + 1);
205
206
let text = run.text;
207
+ let linkIcon = null;
208
if (run.fileIcon && Platform.OS === "ios") {
209
text = `${INLINE_ATTACHMENT_PREFIX}${text}`;
210
} else if (run.skillName && run.skillLabel) {
@@ -207,10 +214,15 @@ export function NativeMarkdownSelectableText(props: {
214
: `$${run.skillName}`;
215
} else if (run.externalHost && run.href && !prefixedExternalLinks.has(run.href)) {
216
prefixedExternalLinks.add(run.href);
210
- text = `${EXTERNAL_LINK_PREFIX}${text}`;
217
+ linkIcon = resolveMarkdownLinkIcon(run.externalHost);
218
+ if (linkIcon === null) {
219
+ text = `${EXTERNAL_LINK_PREFIX}${text}`;
220
+ } else if (Platform.OS === "ios") {
221
+ text = `${INLINE_ATTACHMENT_PREFIX}${text}`;
222
+ }
223
}
224
213
- return { key: `${signature}:${occurrence}`, run, text };
225
+ return { key: `${signature}:${occurrence}`, run, text, linkIcon };
226
});
227
// T3MarkdownText only rebuilds its attributed string during native layout. A
228
// color-only child update can otherwise leave the previous appearance cached.
@@ -248,7 +260,7 @@ export function NativeMarkdownSelectableText(props: {
260
lineHeight: props.textStyle.lineHeight,
261
}}
262
>
251
- {keyedRuns.map(({ key, run, text }) => {
263
+ {keyedRuns.map(({ key, run, text, linkIcon }) => {
264
const href = run.href;
265
const contextMenu = run.fileIcon && href ? menu?.fileContextMenu(href) : undefined;
266
return (
@@ -260,7 +272,9 @@ export function NativeMarkdownSelectableText(props: {
272
? `t3-file:${Image.resolveAssetSource(markdownFileIconSource(run.fileIcon)).uri}`
273
: run.skillName
274
? "t3-skill:sf:cube"
263
- : undefined
275
+ : linkIcon
276
+ ? `t3-link:${Image.resolveAssetSource(markdownLinkIconSource(linkIcon)).uri}`
277
+ : undefined
278
: undefined
279
}
280
contextMenuConfig={contextMenu ? JSON.stringify(contextMenu) : undefined}
@@ -284,6 +298,12 @@ export function NativeMarkdownSelectableText(props: {
298
>
299
{Platform.OS === "android" && run.fileIcon ? (
300
<Image source={markdownFileIconSource(run.fileIcon)} style={styles.inlineIcon} />
301
+ ) : Platform.OS === "android" && linkIcon ? (
302
+ <Image
303
+ source={markdownLinkIconSource(linkIcon)}
304
+ style={styles.inlineIcon}
305
+ tintColor={props.textStyle.linkColor}
306
+ />
307
) : null}
308
{text}
309
</MarkdownTextPrimitive>
apps/mobile/modules/t3-markdown-text/src/markdownLinkIcons.ts
new
+12
@@ -0,0 +1,12 @@
1
+import type { ImageSourcePropType } from "react-native";
2
+
3
+import type { MarkdownLinkIcon } from "./markdownLinks";
4
+
5
+// Black-on-transparent marks; callers tint them with the link color.
6
+const MARKDOWN_LINK_ICON_SOURCES = {
7
+ github: require("../assets/link-icons/github.png"),
8
+} as const satisfies Readonly<Record<MarkdownLinkIcon, ImageSourcePropType>>;
9
+
10
+export function markdownLinkIconSource(icon: MarkdownLinkIcon): ImageSourcePropType {
11
+ return MARKDOWN_LINK_ICON_SOURCES[icon];
12
+}
apps/mobile/modules/t3-markdown-text/src/markdownLinks.ts
+12
@@ -33,6 +33,18 @@ export type MarkdownLinkPresentation =
33
34
export type MarkdownFileIcon = keyof typeof MARKDOWN_FILE_ICON_SOURCES;
35
36
+export type MarkdownLinkIcon = "github";
37
+
38
+/**
39
+ * Sites whose brand mark replaces the generic external-link glyph. The marks
40
+ * are monochrome and tinted with the link color, so they follow the theme.
41
+ */
42
+export function resolveMarkdownLinkIcon(host: string): MarkdownLinkIcon | null {
43
+ const hostname = host.toLowerCase();
44
+ if (hostname === "github.com" || hostname.endsWith(".github.com")) return "github";
45
+ return null;
46
+}
47
+
48
const FILE_ICON_BY_NAME: Readonly<Record<string, MarkdownFileIcon>> = {
49
".babelrc": "babel",
50
".babelrc.json": "babel",
apps/mobile/src/features/threads/ThreadFeed.tsx
+13
-4
@@ -134,9 +134,11 @@ import {
134
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
135
import { useAppearanceCodeSurface } from "../settings/appearance/useAppearanceCodeSurface";
136
import { markdownFileIconSource } from "@t3tools/mobile-markdown-text/file-icons";
137
+import { markdownLinkIconSource } from "@t3tools/mobile-markdown-text/link-icons";
138
import {
139
normalizeNativeMarkdownUrl,
140
resolveMarkdownInlineCodePresentation,
141
+ resolveMarkdownLinkIcon,
142
resolveMarkdownLinkPresentation,
143
} from "@t3tools/mobile-markdown-text/links";
144
import {
@@ -606,7 +608,8 @@ const MarkdownExternalLink = memo(function MarkdownExternalLink(props: {
608
readonly onPress: (href: string) => void;
609
}) {
610
const [failedHost, setFailedHost] = useState<string | null>(null);
609
- const faviconUrl = faviconUrlForOrigin(`https://${props.host}`);
611
+ const linkIcon = resolveMarkdownLinkIcon(props.host);
612
+ const faviconUrl = linkIcon ? null : faviconUrlForOrigin(`https://${props.host}`);
613
614
return (
615
<NativeText
@@ -617,9 +620,15 @@ const MarkdownExternalLink = memo(function MarkdownExternalLink(props: {
620
textDecorationLine: "none",
621
}}
622
>
620
- {faviconUrl !== null &&
621
- failedHost !== props.host &&
622
- !failedMarkdownFaviconHosts.has(props.host) ? (
623
+ {linkIcon ? (
624
+ <Image
625
+ source={markdownLinkIconSource(linkIcon)}
626
+ style={markdownLinkStyles.inlineIcon}
627
+ tintColor={props.color}
628
+ />
629
+ ) : faviconUrl !== null &&
630
+ failedHost !== props.host &&
631
+ !failedMarkdownFaviconHosts.has(props.host) ? (
632
<Image
633
source={{
634
uri: faviconUrl,
apps/mobile/src/lib/markdownLinks.test.ts
+15
-1
@@ -1,6 +1,20 @@
1
import { describe, expect, it } from "vite-plus/test";
2
3
-import { resolveMarkdownLinkPresentation } from "@t3tools/mobile-markdown-text/links";
3
+import {
4
+ resolveMarkdownLinkIcon,
5
+ resolveMarkdownLinkPresentation,
6
+} from "@t3tools/mobile-markdown-text/links";
7
+
8
+describe("resolveMarkdownLinkIcon", () => {
9
+ it("gives GitHub hosts the brand mark and everything else the generic glyph", () => {
10
+ expect(resolveMarkdownLinkIcon("github.com")).toBe("github");
11
+ expect(resolveMarkdownLinkIcon("GitHub.com")).toBe("github");
12
+ expect(resolveMarkdownLinkIcon("gist.github.com")).toBe("github");
13
+ expect(resolveMarkdownLinkIcon("github.community")).toBeNull();
14
+ expect(resolveMarkdownLinkIcon("notgithub.com")).toBeNull();
15
+ expect(resolveMarkdownLinkIcon("example.com")).toBeNull();
16
+ });
17
+});
18
19
describe("resolveMarkdownLinkPresentation", () => {
20
it("treats protocol-relative media as an external URL, not a filesystem path", () => {
apps/web/src/components/ChatMarkdown.test.tsx
+10
-3
@@ -5,6 +5,7 @@ import { create, type ReactTestRenderer } from "react-test-renderer";
5
import { describe, expect, it, vi } from "vite-plus/test";
6
7
import { getSyntaxHighlighterPromise } from "../lib/syntaxHighlighting";
8
+import { GitHubIcon } from "./Icons";
9
import { Button } from "./ui/button";
10
import { setMarkdownTaskChecked } from "./files/filePreviewMode";
11
@@ -78,10 +79,10 @@ describe("ChatMarkdown favicon privacy", () => {
79
const markdown = (url: string) => <ChatMarkdown cwd="/tmp/project" text={`[Link](${url})`} />;
80
try {
81
await act(async () => {
81
- renderer = create(markdown("https://github.com"));
82
+ renderer = create(markdown("https://example.com"));
83
});
84
expect(renderer!.root.findAllByType("img").map((image) => image.props.src)).toEqual([
84
- "https://www.google.com/s2/favicons?domain=github.com&sz=32",
85
+ "https://www.google.com/s2/favicons?domain=example.com&sz=32",
86
]);
87
for (const url of ["http://192.168.1.10:8080", "http://localhost:3000", "http://home.arpa"]) {
88
await act(async () => {
@@ -90,9 +91,15 @@ describe("ChatMarkdown favicon privacy", () => {
91
expect(renderer!.root.findAllByType("img")).toHaveLength(0);
92
}
93
await act(async () => {
93
- renderer!.update(markdown("https://github.com"));
94
+ renderer!.update(markdown("https://example.com"));
95
});
96
expect(renderer!.root.findAllByType("img")).toHaveLength(1);
97
+ // GitHub links draw the brand mark in currentColor instead of fetching a favicon.
98
+ await act(async () => {
99
+ renderer!.update(markdown("https://github.com/pingdotgg/t3code/pull/1"));
100
+ });
101
+ expect(renderer!.root.findAllByType("img")).toHaveLength(0);
102
+ expect(renderer!.root.findAllByType(GitHubIcon)).toHaveLength(1);
103
} finally {
104
await act(async () => {
105
renderer?.unmount();
apps/web/src/components/ChatMarkdown.tsx
+13
-2
@@ -119,6 +119,7 @@ import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
119
import { fnv1a32 } from "../lib/diffRendering";
120
import { LRUCache } from "../lib/lruCache";
121
import { getSyntaxHighlighterPromise } from "../lib/syntaxHighlighting";
122
+import { GitHubIcon } from "./Icons";
123
import { RenderErrorBoundary } from "./RenderErrorBoundary";
124
import { useTheme } from "../hooks/useTheme";
125
import { getClientSettings, useClientSettings } from "../hooks/useSettings";
@@ -1189,15 +1190,25 @@ const MARKDOWN_LINK_FAVICON_CLASS_NAME = "block size-full shrink-0 select-none";
1190
/** Hosts whose favicon request already failed this session — skip straight to the globe. */
1191
const failedFaviconHosts = new Set<string>();
1192
1193
+/** Sites whose brand mark (drawn in `currentColor`) replaces the fetched favicon so it follows the theme. */
1194
+function brandLinkIcon(host: string): typeof GitHubIcon | null {
1195
+ const hostname = host.toLowerCase();
1196
+ if (hostname === "github.com" || hostname.endsWith(".github.com")) return GitHubIcon;
1197
+ return null;
1198
+}
1199
+
1200
const MarkdownLinkFavicon = memo(function MarkdownLinkFavicon({ host }: { host: string }) {
1201
const [failedHost, setFailedHost] = useState<string | null>(null);
1194
- const faviconUrl = faviconUrlForOrigin(`https://${host}`);
1202
+ const BrandIcon = brandLinkIcon(host);
1203
+ const faviconUrl = BrandIcon ? null : faviconUrlForOrigin(`https://${host}`);
1204
return (
1205
<span
1206
className="ms-[0.25em] me-[0.2em] inline-flex size-[14px] [vertical-align:-0.125em]"
1207
aria-hidden
1208
>
1200
- {faviconUrl === null || failedHost === host || failedFaviconHosts.has(host) ? (
1209
+ {BrandIcon ? (
1210
+ <BrandIcon className={MARKDOWN_LINK_FAVICON_CLASS_NAME} />
1211
+ ) : faviconUrl === null || failedHost === host || failedFaviconHosts.has(host) ? (
1212
<GlobeIcon className={MARKDOWN_LINK_FAVICON_CLASS_NAME} />
1213
) : (
1214
<img