diff --git a/demo/web/static/index.html b/demo/web/static/index.html index b39b81d..38b6e88 100644 --- a/demo/web/static/index.html +++ b/demo/web/static/index.html @@ -1197,120 +1197,117 @@ async function generateParadigm() { } } -/** 轻量 Markdown 转 HTML 渲染器 */ +/** 轻量 Markdown 转 HTML 渲染器(支持标题、列表、子列表、引用、粗体、代码) */ function renderMarkdown(md) { if (!md) return ''; const lines = md.split('\n'); let html = ''; - let inList = false; - let inOrderedList = false; - for (let i = 0; i < lines.length; i++) { - let line = lines[i]; - // 标题 - if (/^### /.test(line)) { - if (inList) { html += ''; inList = false; } - if (inOrderedList) { html += ''; inOrderedList = false; } - html += `
${inlineMd(line)}
`; + let i = 0; + /** 关闭所有打开的列表 */ + function closeLists(stack) { + while (stack.length) { + html += stack.pop() === 'ul' ? '' : ''; } } - if (inList) html += ''; - if (inOrderedList) html += ''; + const listStack = []; + while (i < lines.length) { + let line = lines[i]; + const trimmed = line.trimStart(); + const indent = line.length - trimmed.length; + // 空行 + if (trimmed === '') { + closeLists(listStack); + i++; + continue; + } + // 标题 + if (/^### /.test(trimmed)) { + closeLists(listStack); + html += `${inlineMd(quoteLines.join(' '))}`; + continue; + } + // 有序列表 + if (/^\d+\. /.test(trimmed)) { + const level = Math.floor(indent / 2); + while (listStack.length > level) { + html += listStack.pop() === 'ul' ? '' : ''; + } + if (listStack.length === level) { + if (listStack[level - 1] !== 'ol') { + if (listStack.length) html += listStack.pop() === 'ul' ? '' : ''; + html += '
${inlineMd(paraLines.join(' '))}
`; + } + closeLists(listStack); return html; } /** 行内 Markdown:粗体、行内代码、链接 */ function inlineMd(text) { - // 转义 HTML text = escapeHtml(text); - // 粗体 **text** text = text.replace(/\*\*(.+?)\*\*/g, '$1'); - // 行内代码 `code` text = text.replace(/`(.+?)`/g, '$1');
return text;
}
-function renderParadigm(data) {
- const result = document.getElementById('paradigm-result');
- const stageColors = {
- '成交': 'border-green-400 bg-green-50',
- '异议处理': 'border-orange-400 bg-orange-50',
- '报价': 'border-blue-400 bg-blue-50',
- '需求发现': 'border-purple-400 bg-purple-50',
- '建立联系': 'border-gray-300 bg-gray-50',
- };
- result.innerHTML = `
- 客户类型: ${data.customer_type || '-'}
- ${data.product_positioning ? `产品推荐理由: ${escapeHtml(data.product_positioning)}
` : ''} - -目标: ${s.goal || '-'}
-${escapeHtml(s.sales_script || '-')}
-${escapeHtml(s.expected_response || '-')}
-${escapeHtml(s.tips || '-')}
-