@@ -759,6 +759,7 @@ export function MarkdownCodeBlockFrame({
759759 title,
760760 actions,
761761 headerProps,
762+ className,
762763 children,
763764} : {
764765 as ?: React . ElementType ;
@@ -770,11 +771,15 @@ export function MarkdownCodeBlockFrame({
770771 title ?: React . ReactNode ;
771772 actions ?: React . ReactNode ;
772773 headerProps ?: React . HTMLAttributes < HTMLDivElement > ;
774+ className ?: string ;
773775 children : React . ReactNode ;
774776} ) {
775777 return (
776778 < Wrapper
777- className = "chat-markdown-codeblock my-[0.65rem] overflow-hidden rounded-lg border border-border/70 bg-secondary leading-snug dark:border-transparent dark:bg-input/32"
779+ className = { cn (
780+ "chat-markdown-codeblock my-[0.65rem] overflow-hidden rounded-lg border border-border/70 bg-secondary leading-snug dark:border-transparent dark:bg-input/32" ,
781+ className ,
782+ ) }
778783 data-language = { language }
779784 data-wrap = { wrapped ? "true" : "false" }
780785 >
@@ -849,7 +854,7 @@ function MarkdownCodeBlock({
849854 theme,
850855 onRunShellCommand,
851856 isStreaming,
852- leadingActions ,
857+ viewToggle ,
853858 canWrap = true ,
854859 diagram = false ,
855860 children,
@@ -860,7 +865,8 @@ function MarkdownCodeBlock({
860865 theme : "light" | "dark" ;
861866 onRunShellCommand ?: ( ( command : string ) => void ) | undefined ;
862867 isStreaming : boolean ;
863- leadingActions ?: ReactNode ;
868+ /** Switches between source and rendered content; stays below the block in both views. */
869+ viewToggle ?: ReactNode ;
864870 canWrap ?: boolean ;
865871 /** Renders content instead of code, with actions below it like tables. */
866872 diagram ?: boolean ;
@@ -945,15 +951,16 @@ function MarkdownCodeBlock({
945951 < div className = "my-[0.65rem]" data-language = { language } >
946952 { children }
947953 < div className = "mt-0.5 flex items-center justify-between select-none" >
948- { leadingActions }
954+ { viewToggle }
949955 { copyButton }
950956 </ div >
951957 </ div >
952958 ) ;
953959 }
954960
955- return (
961+ const frame = (
956962 < MarkdownCodeBlockFrame
963+ { ...( viewToggle ? { className : "my-0" } : { } ) }
957964 language = { language }
958965 fenceTitle = { fenceTitle }
959966 theme = { theme }
@@ -962,7 +969,6 @@ function MarkdownCodeBlock({
962969 headerProps = { THREAD_FIND_IGNORE_PROPS }
963970 actions = {
964971 < span className = "flex items-center gap-0.5" role = "toolbar" aria-label = "Code block actions" >
965- { leadingActions }
966972 { canWrap ? (
967973 < Tooltip >
968974 < TooltipTrigger
@@ -1007,6 +1013,14 @@ function MarkdownCodeBlock({
10071013 { children }
10081014 </ MarkdownCodeBlockFrame >
10091015 ) ;
1016+ if ( ! viewToggle ) return frame ;
1017+ // The toggle keeps its place under the block so switching views never moves it.
1018+ return (
1019+ < div className = "my-[0.65rem]" >
1020+ { frame }
1021+ < div className = "mt-0.5 flex items-center select-none" > { viewToggle } </ div >
1022+ </ div >
1023+ ) ;
10101024}
10111025
10121026/**
@@ -1043,7 +1057,7 @@ function MarkdownMermaidCodeBlock({
10431057 isStreaming = { isStreaming }
10441058 canWrap = { ! showDiagram }
10451059 diagram = { showDiagram }
1046- leadingActions = {
1060+ viewToggle = {
10471061 isStreaming ? null : (
10481062 < Tooltip >
10491063 < TooltipTrigger
0 commit comments