diff --git a/src/components/MindMap.jsx b/src/components/MindMap.jsx index 190a600..197661d 100644 --- a/src/components/MindMap.jsx +++ b/src/components/MindMap.jsx @@ -103,78 +103,33 @@ const MindMap = ({ meetingId, meetingTitle, meeting, formatDateTime }) => { continue; } - // 处理标题行 + // 处理标题行 - 保持标题格式不变 if (line.match(/^#+\s+/)) { - // 清理标题格式,移除粗体和多余符号 + // 清理标题格式,移除粗体和多余符号,但保持标题符号 let cleanTitle = line.replace(/\*\*([^*]+)\*\*/g, '$1'); // 移除粗体 - cleanTitle = cleanTitle.replace(/[*_]/g, ''); // 移除其他markdown符号 processedLines.push(cleanTitle); - // 查看下一个非空行 - let j = i + 1; - while (j < lines.length && lines[j].trim() === '') { - j++; - } - - // 如果下一行不是标题、列表或表格,将段落内容转换为列表项 - if (j < lines.length) { - const nextLine = lines[j].trim(); - if (!nextLine.match(/^#+\s+/) && !nextLine.match(/^[-*+]\s+/) && !nextLine.includes('|') && nextLine.length > 0) { - // 收集段落内容直到下一个标题、列表或表格 - const paragraphLines = []; - while (j < lines.length) { - const currentLine = lines[j].trim(); - if (currentLine === '') { - j++; - continue; - } - if (currentLine.match(/^#+\s+/) || currentLine.match(/^[-*+]\s+/) || currentLine.includes('|')) { - break; - } - paragraphLines.push(currentLine); - j++; - } - - // 将段落内容转换为列表项,只保留重点内容 - if (paragraphLines.length > 0) { - const paragraphText = paragraphLines.join(' '); - - // 提取加粗内容作为重点 - const boldMatches = paragraphText.match(/\*\*([^*]+)\*\*/g); - if (boldMatches && boldMatches.length > 0) { - // 只保留加粗的重点内容 - boldMatches.forEach(match => { - const cleanText = match.replace(/\*\*/g, '').trim(); - if (cleanText.length > 0 && cleanText.length < 50) { // 避免过长的内容 - processedLines.push(`- ${cleanText}`); - } - }); - } else { - // 如果没有加粗内容,提取关键词汇或短句 - const keyPhrases = extractKeyPhrases(paragraphText); - keyPhrases.forEach(phrase => { - if (phrase.length > 0) { - processedLines.push(`- ${phrase}`); - } - }); - } - } - i = j - 1; // j will be incremented at the end of the loop - } - } + // 获取标题级别 + const titleLevel = (line.match(/^#+/) || [''])[0].length; } - // 处理列表项 - else if (line.match(/^[-*+]\s+/)) { - const cleanListItem = line.replace(/\*\*([^*]+)\*\*/g, '$1'); // 移除粗体 - processedLines.push(cleanListItem); + // 处理现有列表项(有序和无序) - 保持其原始结构 + else if (line.match(/^\s*([-*+]|\d+\.)\s+/)) { + // 只移除加粗格式,保留原始行,包括缩进和列表标记 + const cleanedLine = line.replace(/\*\*([^*]+)\*\*/g, '$1'); + processedLines.push(cleanedLine); + } + // 将区块引用转换为列表项 + else if (line.startsWith('>')) { + const content = line.replace(/^>+\s*/, ''); + processedLines.push(`- ${content}`); } // 保持表格原样,让markmap自己处理 else if (line.includes('|')) { processedLines.push(line); } - // 处理其他普通段落(如果前面没有被处理) + // 处理其他普通段落 - 保留原样 else if (line.length > 0 && !line.match(/\*\*总字数:\d+字\*\*/)) { - processedLines.push(`- ${line}`); + processedLines.push(line); } i++; @@ -193,14 +148,15 @@ const MindMap = ({ meetingId, meetingTitle, meeting, formatDateTime }) => { try { const processedMarkdown = preprocessMarkdownForMindMap(markdown); - console.log('原始markdown内容:', markdown); - console.log('预处理后的markdown:', processedMarkdown); + console.log('=== 思维导图数据调试 ==='); + console.log('原始markdown内容:'); + console.log(markdown); + console.log('预处理后的markdown:'); + console.log(processedMarkdown); const transformer = new Transformer(); const { root } = transformer.transform(processedMarkdown); - console.log('转换后的思维导图数据:', root); - if (markmapRef.current) { markmapRef.current.setData(root); } else {