1- import { MarkdownRenderer } from "@features/editor/components/MarkdownRenderer" ;
1+ import {
2+ baseComponents ,
3+ remarkPlugins ,
4+ } from "@features/editor/components/MarkdownRenderer" ;
25import { File } from "@phosphor-icons/react" ;
3- import { Box , Code } from "@radix-ui/themes" ;
6+ import { Box , Code , Text } from "@radix-ui/themes" ;
47import type { ReactNode } from "react" ;
8+ import { memo } from "react" ;
9+ import type { Components } from "react-markdown" ;
10+ import ReactMarkdown from "react-markdown" ;
511
612interface UserMessageProps {
713 content : string ;
814}
915
16+ /**
17+ * Markdown components that render paragraphs as inline spans so that
18+ * text chunks between file mentions stay on the same line.
19+ */
20+ const inlineComponents : Components = {
21+ ...baseComponents ,
22+ p : ( { children } ) => (
23+ < Text as = "span" size = "1" color = "gray" highContrast >
24+ { children }
25+ </ Text >
26+ ) ,
27+ } ;
28+
29+ const InlineMarkdown = memo ( function InlineMarkdown ( {
30+ content,
31+ } : {
32+ content : string ;
33+ } ) {
34+ return (
35+ < ReactMarkdown remarkPlugins = { remarkPlugins } components = { inlineComponents } >
36+ { content }
37+ </ ReactMarkdown >
38+ ) ;
39+ } ) ;
40+
1041function parseFileMentions ( content : string ) : ReactNode [ ] {
1142 const fileTagRegex = / < f i l e \s + p a t h = " ( [ ^ " ] + ) " \s * \/ > / g;
1243 const parts : ReactNode [ ] = [ ] ;
@@ -16,7 +47,7 @@ function parseFileMentions(content: string): ReactNode[] {
1647 if ( match . index !== undefined && match . index > lastIndex ) {
1748 const textBefore = content . slice ( lastIndex , match . index ) ;
1849 parts . push (
19- < MarkdownRenderer key = { `text-${ lastIndex } ` } content = { textBefore } /> ,
50+ < InlineMarkdown key = { `text-${ lastIndex } ` } content = { textBefore } /> ,
2051 ) ;
2152 }
2253
@@ -32,6 +63,7 @@ function parseFileMentions(content: string): ReactNode[] {
3263 alignItems : "center" ,
3364 gap : "4px" ,
3465 verticalAlign : "middle" ,
66+ margin : "0 6px" ,
3567 } }
3668 >
3769 < File size = { 12 } />
@@ -44,7 +76,7 @@ function parseFileMentions(content: string): ReactNode[] {
4476
4577 if ( lastIndex < content . length ) {
4678 parts . push (
47- < MarkdownRenderer
79+ < InlineMarkdown
4880 key = { `text-${ lastIndex } ` }
4981 content = { content . slice ( lastIndex ) }
5082 /> ,
@@ -66,7 +98,12 @@ export function UserMessage({ content }: UserMessageProps) {
6698 { hasFileMentions ? (
6799 parseFileMentions ( content )
68100 ) : (
69- < MarkdownRenderer content = { content } />
101+ < ReactMarkdown
102+ remarkPlugins = { remarkPlugins }
103+ components = { baseComponents }
104+ >
105+ { content }
106+ </ ReactMarkdown >
70107 ) }
71108 </ Box >
72109 </ Box >
0 commit comments