diff --git a/app/src/main/java/com/stand/standapp/ui/chat/components/ChatArea.kt b/app/src/main/java/com/stand/standapp/ui/chat/components/ChatArea.kt index 3e2a1df..2580c4a 100644 --- a/app/src/main/java/com/stand/standapp/ui/chat/components/ChatArea.kt +++ b/app/src/main/java/com/stand/standapp/ui/chat/components/ChatArea.kt @@ -40,6 +40,18 @@ fun ChatArea( } } + val context = androidx.compose.ui.platform.LocalContext.current + val markwon = remember(context) { + io.noties.markwon.Markwon.builder(context) + .usePlugin(io.noties.markwon.core.CorePlugin.create()) + .usePlugin(io.noties.markwon.ext.tables.TablePlugin.create(context)) + .usePlugin(io.noties.markwon.html.HtmlPlugin.create()) + .usePlugin(io.noties.markwon.linkify.LinkifyPlugin.create()) + .usePlugin(io.noties.markwon.ext.strikethrough.StrikethroughPlugin.create()) + .usePlugin(io.noties.markwon.ext.tasklist.TaskListPlugin.create(context)) + .build() + } + val isAnyStreaming = remember(messages) { messages.any { it.isStreaming } } if (isAnyStreaming) { val totalLength = messages.map { it.content.length }.sum() @@ -111,6 +123,7 @@ fun ChatArea( val contentWithCursor = msg.content + if (msg.isStreaming) " █" else "" MarkwonRenderer( markdown = contentWithCursor, + markwon = markwon, modifier = Modifier.padding(12.dp) ) } @@ -161,19 +174,7 @@ fun ChatArea( } @Composable -fun MarkwonRenderer(markdown: String, modifier: Modifier) { - val context = androidx.compose.ui.platform.LocalContext.current - val markwon = remember(context) { - io.noties.markwon.Markwon.builder(context) - .usePlugin(io.noties.markwon.core.CorePlugin.create()) - .usePlugin(io.noties.markwon.ext.tables.TablePlugin.create(context)) - .usePlugin(io.noties.markwon.html.HtmlPlugin.create()) - .usePlugin(io.noties.markwon.linkify.LinkifyPlugin.create()) - .usePlugin(io.noties.markwon.ext.strikethrough.StrikethroughPlugin.create()) - .usePlugin(io.noties.markwon.ext.tasklist.TaskListPlugin.create(context)) - .build() - } - +fun MarkwonRenderer(markdown: String, markwon: io.noties.markwon.Markwon, modifier: Modifier) { androidx.compose.ui.viewinterop.AndroidView( factory = { ctx -> val textView = SafeSelectableTextView(ctx).apply {