@@ -188,6 +188,8 @@ interface ChatMarkdownProps {
188188 parseRawHtml ?: boolean ;
189189 /** Append a prompt that invokes a newly created artifact-template skill. */
190190 onUseArtifactTemplate ?: ( ( template : CodexArtifactTemplate ) => void ) | undefined ;
191+ /** Directory that anchors relative links and images; defaults to `cwd`. Set
192+ to the file's own directory when rendering a markdown file. */
191193 imageBaseDir ?: string | undefined ;
192194 onImageExpand ?: ( ( preview : ExpandedImagePreview ) => void ) | undefined ;
193195 extraRemarkPlugins ?: NonNullable < ReactMarkdownOptions [ "remarkPlugins" ] > ;
@@ -2100,24 +2102,24 @@ function ChatMarkdown({
21002102 for ( const href of extractMarkdownLinkHrefs ( renderCodexFileCitationsAsMarkdown ( text ) ) ) {
21012103 const normalizedHref = normalizeMarkdownLinkHrefKey ( href ) ;
21022104 if ( metaByHref . has ( normalizedHref ) ) continue ;
2103- const meta = resolveMarkdownFileLinkMeta ( normalizedHref , cwd ) ;
2105+ const meta = resolveMarkdownFileLinkMeta ( normalizedHref , cwd , imageBaseDir ?? cwd ) ;
21042106 if ( meta ) {
21052107 metaByHref . set ( normalizedHref , meta ) ;
21062108 }
21072109 }
21082110 return metaByHref ;
2109- } , [ cwd , text ] ) ;
2111+ } , [ cwd , imageBaseDir , text ] ) ;
21102112 const inlineCodeFileLinkMetaByText = useMemo ( ( ) => {
21112113 const metaByText = new Map < string , MarkdownFileLinkMeta > ( ) ;
21122114 for ( const span of extractInlineCodeSpans ( text ) ) {
21132115 if ( metaByText . has ( span ) ) continue ;
2114- const meta = resolveInlineCodeFileLinkMeta ( span , cwd ) ;
2116+ const meta = resolveInlineCodeFileLinkMeta ( span , cwd , imageBaseDir ?? cwd ) ;
21152117 if ( meta ) {
21162118 metaByText . set ( span , meta ) ;
21172119 }
21182120 }
21192121 return metaByText ;
2120- } , [ cwd , text ] ) ;
2122+ } , [ cwd , imageBaseDir , text ] ) ;
21212123 const fileLinkParentSuffixByPath = useMemo ( ( ) => {
21222124 const filePaths = [
21232125 ...[ ...markdownFileLinkMetaByHref . values ( ) ] . map ( ( meta ) => meta . filePath ) ,
@@ -2442,7 +2444,7 @@ function ChatMarkdown({
24422444 const normalizedHref = href ? normalizeMarkdownLinkHrefKey ( href ) : "" ;
24432445 const fileLinkMeta = normalizedHref
24442446 ? ( markdownFileLinkMetaByHref . get ( normalizedHref ) ??
2445- resolveMarkdownFileLinkMeta ( normalizedHref , cwd ) )
2447+ resolveMarkdownFileLinkMeta ( normalizedHref , cwd , imageBaseDir ?? cwd ) )
24462448 : null ;
24472449 if ( ! fileLinkMeta ) {
24482450 const faviconHost = resolveExternalWebLinkHost ( href ) ;
@@ -2588,7 +2590,7 @@ function ChatMarkdown({
25882590 const codeText = nodeToPlainText ( children ) ;
25892591 const fileLinkMeta =
25902592 inlineCodeFileLinkMetaByText . get ( codeText . trim ( ) ) ??
2591- resolveInlineCodeFileLinkMeta ( codeText , cwd ) ;
2593+ resolveInlineCodeFileLinkMeta ( codeText , cwd , imageBaseDir ?? cwd ) ;
25922594 if ( fileLinkMeta ) {
25932595 return fileLinkChip (
25942596 fileLinkMeta ,
0 commit comments