import { test, describe } from 'node:test'; import assert from 'node:assert/strict'; import { parseReplyMarkdown } from './parseReplyMarkdown'; import { renderClipboardHtml } from './renderClipboardHtml'; import { renderPlainText } from './renderPlainText'; import { serializeMarkdown } from './serializeMarkdown'; import { stripUnsafeHtml, sanitizeLinkHref, escapeHtml } from './sanitize'; import { deriveReplyTitle, sanitizeFilename } from '../../features/replyExport/title'; describe('Reply Document IR & Export Engine', () => { test('deriveReplyTitle and sanitizeFilename derive title and safe file name', () => { const md = '# 医疗器械临床评价报告\n\n本报告基于GB 9706标准进行评价。'; const title = deriveReplyTitle(md, '2026-09-10 10:00'); assert.equal(title, '医疗器械临床评价报告'); const safeName = sanitizeFilename(title); assert.equal(safeName, '医疗器械临床评价报告'); }); test('deriveReplyTitle handles text without heading', () => { const md = '根据最新医疗器械法规要求,必须建立完整的风险管理体系。'; const title = deriveReplyTitle(md); assert.ok(title.startsWith('根据最新医疗器械法规要求')); }); test('parseReplyMarkdown parses headers, lists, code, and tables', () => { const sample = ` # 临床评价总结 1. 第一项评估 2. 第二项评估 - 无序要点 A - 无序要点 B > 这是一个引用说明 \`\`\`python def evaluate(): return True \`\`\` | 参数 | 阈值 | 结果 | | :--- | :---: | ---: | | 漏电流 | 10uA | 合格 | | 耐压 | 1500V | 合格 | `; const ir = parseReplyMarkdown(sample); assert.equal(ir.title, '临床评价总结'); assert.ok(ir.nodes.length >= 6); const types = ir.nodes.map((b) => b.type); assert.ok(types.includes('heading')); assert.ok(types.includes('list')); assert.ok(types.includes('blockquote')); assert.ok(types.includes('code')); assert.ok(types.includes('table')); }); test('renderClipboardHtml renders self-contained styling for office tools', () => { const md = `# 标题 正文包含 **粗体** 和 *斜体* 以及 [链接](https://example.com)。 - 项目 1 - 项目 2 `; const ir = parseReplyMarkdown(md); const html = renderClipboardHtml(ir); assert.ok(html.includes('