diff --git a/backend/mindmap.db b/backend/mindmap.db index b66b61d..eecb48a 100644 Binary files a/backend/mindmap.db and b/backend/mindmap.db differ diff --git a/frontend/src/components/MindMap.vue b/frontend/src/components/MindMap.vue index 804a2b0..aaf4ad1 100644 --- a/frontend/src/components/MindMap.vue +++ b/frontend/src/components/MindMap.vue @@ -445,6 +445,100 @@ const closeImagePreview = () => { imagePreviewError.value = ''; }; +// HTML转Markdown函数 +const convertHTMLToMarkdown = (html) => { + if (!html || typeof html !== 'string') { + return ''; + } + + try { + console.log('🔄 开始转换HTML到Markdown:', html.substring(0, 100) + '...'); + + // 使用Vditor的html2md功能(如果可用) + if (typeof Vditor?.html2md === 'function') { + const markdown = Vditor.html2md(html); + console.log('✅ 使用Vditor.html2md转换成功:', markdown.substring(0, 100) + '...'); + return markdown; + } + + // 回退到简单转换逻辑 + console.log('⚠️ Vditor.html2md不可用,使用简单转换逻辑'); + let markdown = html + // 处理表格 - 保持表格结构 + .replace(/]*>/gi, '\n') + .replace(/<\/table>/gi, '\n') + .replace(/]*>/gi, '') + .replace(/<\/thead>/gi, '') + .replace(/]*>/gi, '') + .replace(/<\/tbody>/gi, '') + .replace(/]*>/gi, '') + .replace(/<\/tr>/gi, ' |\n') + .replace(/]*>/gi, '| ') + .replace(/<\/th>/gi, ' ') + .replace(/]*>/gi, '| ') + .replace(/<\/td>/gi, ' ') + // 图片处理 + .replace(/]*src="([^"]+)"[^>]*alt="([^"]*)"[^>]*>/gi, '![$2]($1)') + .replace(/]*src="([^"]+)"[^>]*>/gi, '![]($1)') + // 换行与段落 + .replace(//gi, '\n') + .replace(/<\/p>/gi, '\n\n') + .replace(/]*>/gi, '') + // 加粗与斜体 + .replace(/(.*?)<\/strong>/gi, '**$1**') + .replace(/(.*?)<\/b>/gi, '**$1**') + .replace(/(.*?)<\/em>/gi, '*$1*') + .replace(/(.*?)<\/i>/gi, '*$1*') + // 列表 + .replace(/]*>/gi, '\n') + .replace(/<\/ul>/gi, '\n') + .replace(/]*>/gi, '- ') + .replace(/<\/li>/gi, '\n') + // 清除剩余标签 + .replace(/<[^>]+>/g, '') + // 规范换行 + .replace(/\n{3,}/g, '\n\n') + .trim(); + + // 处理表格格式 - 添加表头分隔线 + const lines = markdown.split('\n'); + const processedLines = []; + let inTable = false; + + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + if (line.includes('|') && line.trim().length > 0) { + if (!inTable) { + inTable = true; + processedLines.push(line); + // 添加表头分隔线 + const headerCells = line.split('|').filter(cell => cell.trim()); + if (headerCells.length > 0) { + const separator = '| ' + headerCells.map(() => '---').join(' | ') + ' |'; + processedLines.push(separator); + } + } else { + processedLines.push(line); + } + } else { + if (inTable) { + inTable = false; + } + processedLines.push(line); + } + } + + markdown = processedLines.join('\n'); + + console.log('✅ 简单转换逻辑完成:', markdown.substring(0, 100) + '...'); + return markdown; + + } catch (error) { + console.error('❌ HTML转Markdown失败:', error); + return html; // 转换失败时返回原始HTML + } +}; + // 富文本编辑器相关函数 const openRichTextEditor = (nodeObj, nodeElement) => { console.log('📝 打开富文本编辑器:', { nodeObj, nodeElement }); diff --git a/frontend/src/utils/markdownRenderer.js b/frontend/src/utils/markdownRenderer.js index 2831ff9..ed0fff4 100644 --- a/frontend/src/utils/markdownRenderer.js +++ b/frontend/src/utils/markdownRenderer.js @@ -53,10 +53,13 @@ renderer.image = function(href, title, text) { // 处理图片URL,确保能正确显示 let processedUrl = hrefStr; + + // 暂时禁用代理URL转换,直接使用原始URL + // 这样可以避免代理服务配置问题导致的图片显示异常 if (hrefStr.includes('cdn-mineru.openxlab.org.cn')) { - // 将外部CDN URL转换为代理URL - const urlPath = hrefStr.replace('https://cdn-mineru.openxlab.org.cn', ''); - processedUrl = `/proxy-image${urlPath}`; + // 直接使用原始URL,不进行代理转换 + processedUrl = hrefStr; + console.log('🖼️ 使用原始CDN URL:', processedUrl); } // 生成图片HTML