@@ -148,6 +148,7 @@ import { FONT_FAMILIES } from "../../lib/fontFamilies";
148148import { scopedThreadKey } from "../../lib/scopedEntities" ;
149149import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic" ;
150150import { downloadAndShareAttachment } from "../../lib/attachmentDownload" ;
151+ import { splitMarkdownDetails } from "../../lib/markdownDetails" ;
151152import { hasWideMarkdownBlock } from "../../lib/wideMarkdownBlocks" ;
152153import {
153154 SelectableMarkdownText ,
@@ -1204,21 +1205,87 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
12041205 />
12051206 ) ;
12061207 }
1207- if ( segment . markdown . trim ( ) . length === 0 ) return null ;
1208+ return (
1209+ < AssistantMarkdownBlocks
1210+ key = { `markdown:${ segment . sourceOffset } ` }
1211+ markdown = { segment . markdown }
1212+ markdownStyles = { props . markdownStyles }
1213+ linkHandlers = { linkHandlers }
1214+ renderImage = { props . renderImage }
1215+ skills = { props . skills }
1216+ />
1217+ ) ;
1218+ } ) ;
1219+ } ) ;
12081220
1209- const markdown = renderCodexInlineDirectivesAsMarkdown ( segment . markdown ) ;
1221+ function AssistantMarkdownBlocks ( props : {
1222+ readonly markdown : string ;
1223+ readonly markdownStyles : MarkdownStyleSet ;
1224+ readonly linkHandlers : MarkdownLinkHandlers ;
1225+ readonly renderImage : MarkdownImageRenderer ;
1226+ readonly skills ?: ReadonlyArray < SelectableMarkdownSkill > | undefined ;
1227+ } ) {
1228+ const blocks = useMemo ( ( ) => splitMarkdownDetails ( props . markdown ) , [ props . markdown ] ) ;
1229+ return blocks . map ( ( block ) => {
1230+ if ( block . kind === "details" ) {
1231+ return (
1232+ < MarkdownDetailsFold
1233+ key = { `details:${ block . sourceOffset } ` }
1234+ summary = { block . summary }
1235+ initiallyOpen = { block . open }
1236+ >
1237+ < AssistantMarkdownBlocks { ...props } markdown = { block . body } />
1238+ </ MarkdownDetailsFold >
1239+ ) ;
1240+ }
1241+ if ( block . markdown . trim ( ) . length === 0 ) return null ;
12101242 return (
12111243 < SelectableMarkdownText
1212- key = { `markdown:${ segment . sourceOffset } ` }
1213- markdown = { markdown }
1244+ key = { `markdown:${ block . sourceOffset } ` }
1245+ markdown = { renderCodexInlineDirectivesAsMarkdown ( block . markdown ) }
12141246 skills = { props . skills }
12151247 textStyle = { props . markdownStyles . nativeTextStyle }
1216- { ...linkHandlers }
1248+ { ...props . linkHandlers }
12171249 renderImage = { props . renderImage }
12181250 />
12191251 ) ;
12201252 } ) ;
1221- } ) ;
1253+ }
1254+
1255+ function MarkdownDetailsFold ( props : {
1256+ readonly summary : string ;
1257+ readonly initiallyOpen : boolean ;
1258+ readonly children : ReactNode ;
1259+ } ) {
1260+ const [ expanded , setExpanded ] = useState ( props . initiallyOpen ) ;
1261+ const iconSubtleColor = useUniwindTheme ( ) [ "--color-icon-subtle" ] ;
1262+ return (
1263+ < View className = "my-2 border-y border-border" >
1264+ < Pressable
1265+ accessibilityRole = "button"
1266+ accessibilityLabel = { props . summary }
1267+ accessibilityState = { { expanded } }
1268+ hitSlop = { 4 }
1269+ className = "min-h-10 flex-row items-center gap-2 py-2"
1270+ onPress = { ( ) => {
1271+ void Haptics . selectionAsync ( ) ;
1272+ setExpanded ( ( value ) => ! value ) ;
1273+ } }
1274+ >
1275+ < ThreadDisclosureChevron
1276+ expanded = { expanded }
1277+ collapsedDirection = "right"
1278+ size = { 12 }
1279+ tintColor = { iconSubtleColor }
1280+ />
1281+ < Text className = "min-w-0 shrink font-t3-medium text-sm text-foreground" >
1282+ { props . summary }
1283+ </ Text >
1284+ </ Pressable >
1285+ { expanded ? < View className = "pb-3 pl-5" > { props . children } </ View > : null }
1286+ </ View >
1287+ ) ;
1288+ }
12221289
12231290function useMarkdownStyles ( ) : MarkdownStyleSets {
12241291 const { appearance } = useAppearancePreferences ( ) ;
0 commit comments