@@ -179,6 +179,7 @@ interface ChatMarkdownProps {
179179 onUseArtifactTemplate ?: ( ( template : CodexArtifactTemplate ) => void ) | undefined ;
180180 imageBaseDir ?: string | undefined ;
181181 onImageExpand ?: ( ( preview : ExpandedImagePreview ) => void ) | undefined ;
182+ extraRemarkPlugins ?: NonNullable < ReactMarkdownOptions [ "remarkPlugins" ] > ;
182183}
183184
184185export function canUseMarkdownFileShellActions (
@@ -211,6 +212,7 @@ export function shouldUseMarkdownFileBrowserPrimaryAction(input: {
211212}
212213
213214const EMPTY_MARKDOWN_SKILLS : ReadonlyArray < Pick < ServerProviderSkill , "name" | "displayName" > > = [ ] ;
215+ const EMPTY_REMARK_PLUGINS : NonNullable < ReactMarkdownOptions [ "remarkPlugins" ] > = [ ] ;
214216
215217const ARTIFACT_TEMPLATE_ICON_BY_KIND = {
216218 document : FileTextIcon ,
@@ -360,6 +362,7 @@ const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
360362 code : [ ...( defaultSchema . attributes ?. code ?? [ ] ) , "dataCodeMeta" , "dataInlineCode" ] ,
361363 blockquote : [ ...( defaultSchema . attributes ?. blockquote ?? [ ] ) , "dataAlert" ] ,
362364 div : [ ...( defaultSchema . attributes ?. div ?? [ ] ) , ...CODEX_ARTIFACT_TEMPLATE_HAST_PROPERTIES ] ,
365+ a : [ ...( defaultSchema . attributes ?. a ?? [ ] ) , "dataPullRequestAutolink" ] ,
363366 img : [ ...( defaultSchema . attributes ?. img ?? [ ] ) , "dataLocalSrc" , "dataMarkdownTitle" ] ,
364367 } ,
365368 protocols : {
@@ -1807,6 +1810,7 @@ function ChatMarkdown({
18071810 onUseArtifactTemplate,
18081811 imageBaseDir,
18091812 onImageExpand,
1813+ extraRemarkPlugins = EMPTY_REMARK_PLUGINS ,
18101814} : ChatMarkdownProps ) {
18111815 const { resolvedTheme } = useTheme ( ) ;
18121816 const createAssetUrl = useAtomQueryRunner ( assetEnvironment . createUrl , {
@@ -2203,13 +2207,25 @@ function ChatMarkdown({
22032207 : null ;
22042208 if ( ! fileLinkMeta ) {
22052209 const faviconHost = resolveExternalWebLinkHost ( href ) ;
2210+ const pullRequestAutolink = String (
2211+ ( props as Record < string , unknown > ) [ "data-pull-request-autolink" ] ?? "" ,
2212+ ) ;
2213+ const pullRequestCopy =
2214+ pullRequestAutolink === "commit"
2215+ ? / \/ c o m m i t \/ ( [ 0 - 9 a - f ] { 40 } ) $ / iu. exec ( href ?? "" ) ?. [ 1 ]
2216+ : pullRequestAutolink === "reference"
2217+ ? plainHastText ( node )
2218+ : undefined ;
2219+ const isPullRequestAutolink = pullRequestCopy !== undefined ;
22062220 const isSameDocumentLink = href ?. startsWith ( "#" ) ?? false ;
22072221 const onClick = props . onClick ;
22082222 const canOpenInPreview = Boolean ( threadRef ) && isPreviewSupportedInRuntime ( ) ;
22092223 const linkChildren = < MarkdownLinkContext value > { children } </ MarkdownLinkContext > ;
22102224 const link = (
22112225 < a
22122226 { ...props }
2227+ className = { cn ( props . className , pullRequestAutolink === "commit" && "font-mono" ) }
2228+ data-markdown-copy = { pullRequestCopy }
22132229 href = { href }
22142230 target = { isSameDocumentLink ? undefined : "_blank" }
22152231 rel = { isSameDocumentLink ? undefined : "noopener noreferrer" }
@@ -2281,7 +2297,7 @@ function ChatMarkdown({
22812297 } ) ;
22822298 } }
22832299 >
2284- { faviconHost && hastHasText ( node ) ? (
2300+ { faviconHost && hastHasText ( node ) && ! isPullRequestAutolink ? (
22852301 < MarkdownExternalLinkContent host = { faviconHost } plainText = { plainHastText ( node ) } >
22862302 { linkChildren }
22872303 </ MarkdownExternalLinkContent >
@@ -2438,6 +2454,14 @@ function ChatMarkdown({
24382454 ] ) ;
24392455 /* eslint-enable react/no-unstable-nested-components */
24402456
2457+ const remarkPlugins = useMemo (
2458+ ( ) => [
2459+ ...( lineBreaks ? CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS : CHAT_MARKDOWN_REMARK_PLUGINS ) ,
2460+ ...extraRemarkPlugins ,
2461+ ] ,
2462+ [ extraRemarkPlugins , lineBreaks ] ,
2463+ ) ;
2464+
24412465 // react-markdown converts unparsed HTML nodes to text when skipHtml is false.
24422466 // Keep that behavior explicit because literal mode depends on escaping the
24432467 // complete source token instead of dropping it from the rendered message.
@@ -2450,9 +2474,7 @@ function ChatMarkdown({
24502474 onCopy = { handleCopy }
24512475 >
24522476 < ReactMarkdown
2453- remarkPlugins = {
2454- lineBreaks ? CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS : CHAT_MARKDOWN_REMARK_PLUGINS
2455- }
2477+ remarkPlugins = { remarkPlugins }
24562478 rehypePlugins = { parseRawHtml ? CHAT_MARKDOWN_REHYPE_PLUGINS : undefined }
24572479 skipHtml = { false }
24582480 components = { markdownComponents }
0 commit comments