fix: parse todo list json in code blocks
This commit is contained in:
@@ -2176,7 +2176,31 @@
|
|||||||
if (!content) return;
|
if (!content) return;
|
||||||
|
|
||||||
if (typeof content === 'string') {
|
if (typeof content === 'string') {
|
||||||
// 尝试检测是否是 JSON 格式的 todo_list
|
// 检测并提取 JSON 格式的 todo_list(可能在代码块中)
|
||||||
|
const jsonMatch = content.match(/```json\s*(\{[\s\S]*?"type"\s*:\s*"todo_list"[\s\S]*?\})\s*```/);
|
||||||
|
if (jsonMatch) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(jsonMatch[1]);
|
||||||
|
if (parsed.type === 'todo_list') {
|
||||||
|
const before = content.substring(0, jsonMatch.index);
|
||||||
|
const after = content.substring(jsonMatch.index + jsonMatch[0].length);
|
||||||
|
if (before.trim()) {
|
||||||
|
const textDiv = document.createElement('div');
|
||||||
|
textDiv.innerHTML = renderMarkdown(before);
|
||||||
|
bubble.appendChild(textDiv);
|
||||||
|
}
|
||||||
|
bubble.appendChild(createTodoListElement(parsed));
|
||||||
|
if (after.trim()) {
|
||||||
|
const textDiv = document.createElement('div');
|
||||||
|
textDiv.innerHTML = renderMarkdown(after);
|
||||||
|
bubble.appendChild(textDiv);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试直接解析 JSON
|
||||||
const trimmed = content.trim();
|
const trimmed = content.trim();
|
||||||
if (trimmed.startsWith('{') && trimmed.includes('"type"') && trimmed.includes('"todo_list"')) {
|
if (trimmed.startsWith('{') && trimmed.includes('"type"') && trimmed.includes('"todo_list"')) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user