@@ -2,12 +2,14 @@ import { CodeBlock } from "@components/CodeBlock";
22import { Divider } from "@components/Divider" ;
33import { HighlightedCode } from "@components/HighlightedCode" ;
44import { List , ListItem } from "@components/List" ;
5+ import { parseGithubIssueUrl } from "@features/message-editor/utils/githubIssueUrl" ;
56import { Blockquote , Checkbox , Code , Em , Kbd , Text } from "@radix-ui/themes" ;
67import { memo , useMemo } from "react" ;
78import type { Components } from "react-markdown" ;
89import ReactMarkdown from "react-markdown" ;
910import remarkGfm from "remark-gfm" ;
1011import type { PluggableList } from "unified" ;
12+ import { GithubRefChip } from "./GithubRefChip" ;
1113
1214interface MarkdownRendererProps {
1315 content : string ;
@@ -87,39 +89,53 @@ export const baseComponents: Components = {
8789 { children }
8890 </ del >
8991 ) ,
90- a : ( { href, children } ) => (
91- < a
92- href = { href }
93- target = "_blank"
94- rel = "noopener noreferrer"
95- className = "markdown-link"
96- style = { {
97- fontSize : "var(--font-size-1)" ,
98- display : "inline-flex" ,
99- alignItems : "center" ,
100- gap : "2px" ,
101- } }
102- >
103- { children }
104- < svg
105- width = "10"
106- height = "10"
107- viewBox = "0 0 12 12"
108- fill = "none"
109- stroke = "var(--accent-11)"
110- strokeWidth = "1.5"
111- strokeLinecap = "round"
112- strokeLinejoin = "round"
113- style = { { marginLeft : "var(--space-1)" , flexShrink : 0 } }
114- aria-label = "external link icon"
115- role = "img"
92+ a : ( { href, children } ) => {
93+ const githubRef = href ? parseGithubIssueUrl ( href ) : null ;
94+ if ( githubRef ) {
95+ const isAutoLink = typeof children === "string" && children === href ;
96+ const label = isAutoLink
97+ ? `${ githubRef . owner } /${ githubRef . repo } #${ githubRef . number } `
98+ : children ;
99+ return (
100+ < GithubRefChip href = { githubRef . normalizedUrl } kind = { githubRef . kind } >
101+ { label }
102+ </ GithubRefChip >
103+ ) ;
104+ }
105+ return (
106+ < a
107+ href = { href }
108+ target = "_blank"
109+ rel = "noopener noreferrer"
110+ className = "markdown-link"
111+ style = { {
112+ fontSize : "var(--font-size-1)" ,
113+ display : "inline-flex" ,
114+ alignItems : "center" ,
115+ gap : "2px" ,
116+ } }
116117 >
117- < path d = "M4.5 1.5H2.25C1.836 1.5 1.5 1.836 1.5 2.25V9.75C1.5 10.164 1.836 10.5 2.25 10.5H9.75C10.164 10.5 10.5 10.164 10.5 9.75V7.5" />
118- < path d = "M7.5 1.5H10.5V4.5" />
119- < path d = "M5.25 6.75L10.5 1.5" />
120- </ svg >
121- </ a >
122- ) ,
118+ { children }
119+ < svg
120+ width = "10"
121+ height = "10"
122+ viewBox = "0 0 12 12"
123+ fill = "none"
124+ stroke = "var(--accent-11)"
125+ strokeWidth = "1.5"
126+ strokeLinecap = "round"
127+ strokeLinejoin = "round"
128+ style = { { marginLeft : "var(--space-1)" , flexShrink : 0 } }
129+ aria-label = "external link icon"
130+ role = "img"
131+ >
132+ < path d = "M4.5 1.5H2.25C1.836 1.5 1.5 1.836 1.5 2.25V9.75C1.5 10.164 1.836 10.5 2.25 10.5H9.75C10.164 10.5 10.5 10.164 10.5 9.75V7.5" />
133+ < path d = "M7.5 1.5H10.5V4.5" />
134+ < path d = "M5.25 6.75L10.5 1.5" />
135+ </ svg >
136+ </ a >
137+ ) ;
138+ } ,
123139 kbd : ( { children } ) => < Kbd size = "1" > { children } </ Kbd > ,
124140 ul : ( { children } ) => (
125141 < List as = "ul" size = "1" >
0 commit comments