feat: AI回复格式约束 + 前端清洗器增强
- prompt: 禁止**粗体*斜体等内联标记、HTML标签、表格,标题仅限### - 前端_cleanAiText: 移除$N占位符、HTML标签、多余#标题降级 - 确认卡片/结构化消息不受影响
This commit is contained in:
@@ -1243,10 +1243,16 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
|
||||
/// 清理 AI 返回文本中的异常占位符(Markdown 格式交给 MarkdownBody 渲染)
|
||||
static String _cleanAiText(String text) {
|
||||
return text
|
||||
.replaceAll('\$1', '') // AI 偶尔输出 $1 占位符(正则残留)
|
||||
.replaceAll(RegExp(r'\n{3,}'), '\n\n')
|
||||
.trim();
|
||||
var t = text;
|
||||
// 移除 $1、$2 等占位符
|
||||
t = t.replaceAll(RegExp(r'\$\d+'), '');
|
||||
// 移除残留 HTML 标签
|
||||
t = t.replaceAll(RegExp(r'<[^>]+>'), '');
|
||||
// 行首 # 超过 3 个降为 ###
|
||||
t = t.replaceAllMapped(RegExp(r'^#{4,}\s', multiLine: true), (_) => '### ');
|
||||
// 压缩多余空行
|
||||
t = t.replaceAll(RegExp(r'\n{3,}'), '\n\n');
|
||||
return t.trim();
|
||||
}
|
||||
|
||||
String _freqLabel(String freq) {
|
||||
|
||||
Reference in New Issue
Block a user