refactor: enhance markdown parsing for <details> tags

- Implemented custom block syntax for <details> tags in the markdown parser to prevent rendering issues during streaming.
- Updated the assistant message widget to leverage the new <details> handling, eliminating the need for manual tag management.
- Added a details builder to ensure <details> elements are processed correctly without causing character flashing.
This commit is contained in:
cogwheel0
2025-10-05 23:36:14 +05:30
parent a8ae2644f5
commit 661a32866f
2 changed files with 83 additions and 8 deletions

View File

@@ -753,14 +753,9 @@ class _AssistantMessageWidgetState extends ConsumerState<AssistantMessageWidget>
'',
);
// If there's an unclosed <details>, drop the tail to avoid raw tags.
final lastOpen = cleaned.lastIndexOf('<details');
if (lastOpen >= 0) {
final tail = cleaned.substring(lastOpen);
if (!tail.contains('</details>')) {
cleaned = cleaned.substring(0, lastOpen);
}
}
// Note: The markdown parser now handles <details> tags via a custom block syntax,
// so they won't be rendered as plain text during streaming. This prevents the
// character flashing issue.
// Process images in the remaining text
final processedContent = _processContentForImages(cleaned);