chore: render markdown on user message (#5146)

This commit is contained in:
Faisal Amir 2025-05-30 15:09:28 +07:00 committed by GitHub
parent 3022fdebc2
commit cde10a662c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 12 deletions

View File

@ -21,12 +21,14 @@ interface MarkdownProps {
className?: string className?: string
components?: Components components?: Components
enableRawHtml?: boolean enableRawHtml?: boolean
isUser?: boolean
} }
function RenderMarkdownComponent({ function RenderMarkdownComponent({
content, content,
enableRawHtml, enableRawHtml,
className, className,
isUser,
components, components,
}: MarkdownProps) { }: MarkdownProps) {
const { codeBlockStyle, showLineNumbers } = useCodeblock() const { codeBlockStyle, showLineNumbers } = useCodeblock()
@ -71,7 +73,7 @@ function RenderMarkdownComponent({
const shouldVirtualize = code.split('\n').length > 300 const shouldVirtualize = code.split('\n').length > 300
return !isInline ? ( return !isInline && !isUser ? (
<div className="relative overflow-hidden border rounded-md border-main-view-fg/2"> <div className="relative overflow-hidden border rounded-md border-main-view-fg/2">
<div className="flex items-center justify-between px-4 py-2 bg-main-view/10"> <div className="flex items-center justify-between px-4 py-2 bg-main-view/10">
<span className="font-medium text-xs font-sans"> <span className="font-medium text-xs font-sans">
@ -135,9 +137,7 @@ function RenderMarkdownComponent({
</SyntaxHighlighter> </SyntaxHighlighter>
</div> </div>
) : ( ) : (
<code className={className} {...props}> <code className={cn(className)}>{children}</code>
{children}
</code>
) )
}, },
}), }),

View File

@ -185,10 +185,14 @@ export const ThreadContent = memo(
<Fragment> <Fragment>
{item.content?.[0]?.text && item.role === 'user' && ( {item.content?.[0]?.text && item.role === 'user' && (
<div className="w-full"> <div className="w-full">
<div className="flex justify-end w-full text-start break-words whitespace-normal"> <div className="flex justify-end w-full h-full text-start break-words whitespace-normal">
<div className="bg-main-view-fg/4 relative text-main-view-fg p-2 rounded-md inline-block max-w-[70%]"> <div className="bg-main-view-fg/4 relative text-main-view-fg p-2 rounded-md inline-block max-w-[80%] ">
<div className="whitespace-pre-wrap select-text"> <div className="select-text">
{item.content?.[0].text.value} <RenderMarkdown
content={item.content?.[0].text.value}
components={linkComponents}
isUser
/>
</div> </div>
</div> </div>
</div> </div>
@ -274,7 +278,6 @@ export const ThreadContent = memo(
<div className="flex items-center gap-2 size-8 rounded-md justify-center border border-main-view-fg/10 bg-main-view-fg/5 p-1"> <div className="flex items-center gap-2 size-8 rounded-md justify-center border border-main-view-fg/10 bg-main-view-fg/5 p-1">
<AvatarEmoji <AvatarEmoji
avatar={assistant?.avatar} avatar={assistant?.avatar}
fallback="👋"
imageClassName="w-6 h-6 object-contain" imageClassName="w-6 h-6 object-contain"
textClassName="text-base" textClassName="text-base"
/> />

View File

@ -41,6 +41,10 @@
p { p {
line-height: 1.6; line-height: 1.6;
margin-bottom: 1em; margin-bottom: 1em;
&:last-child {
margin-bottom: 0;
}
} }
strong { strong {
@ -103,17 +107,17 @@
/* Code */ /* Code */
code { code {
font-family: monospace; font-family: monospace;
@apply bg-main-view-fg/10 text-main-view-fg; @apply bg-main-view-fg/6 text-main-view-fg;
padding: 0.2em 0.4em; padding: 0.2em 0.4em;
border-radius: 3px; border-radius: 3px;
} }
pre { pre {
font-family: monospace; font-family: monospace;
@apply bg-main-view-fg/10 text-main-view-fg; @apply bg-main-view-fg/6 text-main-view-fg;
overflow-x: auto; overflow-x: auto;
border-radius: 8px; border-radius: 8px;
margin-bottom: 1em; margin-bottom: 8px;
} }
pre code { pre code {