import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import ts from 'typescript'; import React from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { tableTextAlignment } from '../src/tableTextAlignment.ts'; import { sanitizeAnalysisDisplayText } from '../src/analysisDisplayText.ts'; import { analysisEvidenceParts } from '../src/analysisEvidenceRefs.ts'; const source = fs.readFileSync(new URL('../src/AiMarkdown.tsx', import.meta.url), 'utf8') .replace(/^import .*;$/gm, '').replace('export function AiMarkdown', 'function AiMarkdown'); const Markdown = new Function('React', 'tableTextAlignment', 'sanitizeAnalysisDisplayText', 'analysisEvidenceParts', ts.transpileModule(`${source}\nreturn AiMarkdown;`, { compilerOptions: { target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.React } }).outputText )(React, tableTextAlignment, sanitizeAnalysisDisplayText, analysisEvidenceParts); test('original answers preserve wording, table headers, headings and escaped markup', () => { const answer = '## 模型原始回答\n\n数学说明保留。\n\n| 月份 | 原始值 |\n| --- | --- |\n| 8月 | 98.35% |\n\n'; const html = renderToStaticMarkup(React.createElement(Markdown, { content: answer, preserveSource: true })); assert.match(html, /