hololake-system-architecture/product-source/guanghu-knowledge-base/src/markdown.test.ts

33 lines
1.4 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { expandWikiLinks, normalizeImportedMarkup, renderKnowledgeMarkdown } from './markdown.js';
test('expands HoloLake wiki links with labels', () => {
assert.equal(
expandWikiLinks('进入 [[WAKE-ROUTE|唤醒路径]]'),
'进入 [唤醒路径](hololake://knowledge/WAKE-ROUTE "WAKE-ROUTE")',
);
});
test('renders tables inside a horizontal scroll container', () => {
const html = renderKnowledgeMarkdown('| A | B |\n|---|---|\n| 1 | 2 |');
assert.match(html, /class="kb-table-scroll"/);
assert.match(html, /<table>/);
});
test('does not execute imported raw HTML or unsafe links', () => {
const html = renderKnowledgeMarkdown('<script>alert(1)</script>\n\n[x](javascript:alert(1))');
assert.doesNotMatch(html, /<script>/);
assert.match(html, /href="#"/);
});
test('renders Outline aside blocks as safe callouts and keeps table line breaks', () => {
const source = `<aside>\n👥\n\n责任主体说明。\n</aside>\n\n| 项目 | 说明 |\n| --- | --- |\n| 路径 | 第一行<br>第二行 |`;
const normalized = normalizeImportedMarkup(source);
assert.match(normalized, /> 👥/);
const html = renderKnowledgeMarkdown(source);
assert.match(html, /<blockquote>/);
assert.match(html, /责任主体说明/);
assert.doesNotMatch(html, /&lt;aside&gt;|<aside>/);
assert.match(html, /第一行<br>第二行/);
});