// 简单的Markdown渲染函数 export function renderMarkdown(content) { if (!content) return ''; // 由于UniApp的rich-text组件支持HTML,我们将Markdown转换为HTML // 这是一个简化版的Markdown解析器,仅支持基本语法 let html = content // 转义HTML特殊字符 .replace(/&/g, '&') .replace(//g, '>') // 标题 .replace(/^# (.*$)/gm, '

$1

') .replace(/^## (.*$)/gm, '

$1

') .replace(/^### (.*$)/gm, '

$1

') .replace(/^#### (.*$)/gm, '

$1

') .replace(/^##### (.*$)/gm, '
$1
') .replace(/^###### (.*$)/gm, '
$1
') // 粗体和斜体 .replace(/\*\*(.*?)\*\*/g, '$1') .replace(/\*(.*?)\*/g, '$1') .replace(/__(.*?)__/g, '$1') .replace(/_(.*?)_/g, '$1') // 链接 .replace(/\[([^\]]+)\]$$([^)]+)$$/g, '$1') // 图片 .replace(/!\[([^\]]+)\]$$([^)]+)$$/g, '$1') // 无序列表 .replace(/^\s*[-*+]\s+(.*$)/gm, '
  • $1
  • ') // 有序列表 .replace(/^\s*\d+\.\s+(.*$)/gm, '
  • $1
  • ') // 代码块 .replace(/```([\s\S]*?)```/g, '
    $1
    ') // 行内代码 .replace(/`([^`]+)`/g, '$1') // 引用 .replace(/^\> (.*$)/gm, '
    $1
    ') // 段落 .replace(/\n\s*\n/g, '

    ') // 换行 .replace(/\n/g, '
    '); // 包装在段落标签中 html = '

    ' + html + '

    '; // 修复列表 html = html.replace(/
  • .*?<\/li>/g, function(match) { return ''; }); return html; }