MindMap/frontend/test-table-rendering.html

128 lines
4.2 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>表格渲染测试</title>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background: #f5f5f5;
}
.test-container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.test-title {
color: #333;
border-bottom: 2px solid #007bff;
padding-bottom: 10px;
margin-bottom: 20px;
}
.markdown-table {
border-collapse: collapse;
width: 100%;
margin: 4px 0;
font-size: 11px;
border: 1px solid #ddd;
}
.markdown-table th,
.markdown-table td {
border: 1px solid #ddd;
padding: 4px 6px;
text-align: left;
vertical-align: top;
}
.markdown-table th {
background-color: #f8f9fa;
font-weight: 600;
color: #333;
}
.markdown-table tr:nth-child(even) {
background-color: #f8f9fa;
}
.markdown-table tr:hover {
background-color: #e9ecef;
}
.raw-content {
background: #f8f9fa;
padding: 10px;
border-radius: 4px;
font-family: monospace;
white-space: pre-wrap;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="test-container">
<h1 class="test-title">Markdown表格渲染测试</h1>
<h3>测试内容1数据质量评估矩阵</h3>
<div class="raw-content" id="raw1"></div>
<div id="rendered1"></div>
<h3>测试内容2产品价格表</h3>
<div class="raw-content" id="raw2"></div>
<div id="rendered2"></div>
<h3>测试内容3简单表格</h3>
<div class="raw-content" id="raw3"></div>
<div id="rendered3"></div>
</div>
<script>
// 配置marked
marked.setOptions({
breaks: true,
gfm: true,
tables: true,
sanitize: false
});
// 测试内容
const testContent1 = `| 评估维度 | 权重 | 评分标准 | 计算公式 |
|---------|------|---------|---------|
| 完整性 | 0.3 | 缺失值比例 < 5% | $\\text{完整性} = 1 - \\frac{\\text{缺失值数量}}{\\text{总数据量}}$ |
| 准确性 | 0.3 | 误差率 < 3% | $\\text{准确性} = 1 - \\frac{\\text{错误记录数}}{\\text{总记录数}}$ |
| 一致性 | 0.2 | 数据格式统一度 > 95% | $\\text{一致性} = \\frac{\\text{符合格式标准记录数}}{\\text{总记录数}}$ |
| 及时性 | 0.2 | 数据更新频率 ≤ 24小时 | $\\text{及时性} = \\frac{\\text{最近24小时更新数据量}}{\\text{总数据量}}$ |`;
const testContent2 = `产品价格表
| 产品 | 价格 |
|------|------|
| 苹果 | 4元 |
| 香蕉 | 2元 |`;
const testContent3 = `| 姓名 | 年龄 | 城市 |
|------|------|------|
| 张三 | 25 | 北京 |
| 李四 | 30 | 上海 |`;
// 渲染函数
function renderContent(rawId, renderedId, content) {
document.getElementById(rawId).textContent = content;
try {
const html = marked.parse(content);
// 为表格添加样式类
const processedHtml = html.replace(/<table>/g, '<table class="markdown-table">');
document.getElementById(renderedId).innerHTML = processedHtml;
} catch (error) {
document.getElementById(renderedId).innerHTML = `<div style="color: red;">渲染失败: ${error.message}</div>`;
}
}
// 渲染所有测试内容
renderContent('raw1', 'rendered1', testContent1);
renderContent('raw2', 'rendered2', testContent2);
renderContent('raw3', 'rendered3', testContent3);
</script>
</body>
</html>