import assert from 'node:assert/strict' import { registerHooks } from 'node:module' import { test } from 'node:test' const STUB = ` const store = globalThis.__factoryStore ??= new Map(); export const packageStorage = () => ({ async get(k) { return store.get(k) ?? null }, async set(k, v) { store.set(k, JSON.stringify(v)) }, }); export const packageContext = { appBasePath: '/apps/factory/' }; export async function credential(key) { throw new Error('credential not mapped'); } export async function credentials() { return [] } ` registerHooks({ resolve(spec, ctx, next) { if (spec === 'kody:runtime') return { url: `data:text/javascript,${encodeURIComponent(STUB)}`, shortCircuit: true } return next(spec, ctx) }, }) const { renderMarkdown } = await import('./markdown.ts') test('headings', () => { assert.equal(renderMarkdown('# Title'), '
Hello world
') assert.equal(renderMarkdown('Line one\n\nLine two'), 'Line one
\nLine two
') }) test('bold and italic', () => { assert.equal(renderMarkdown('**bold**'), 'bold
') assert.equal(renderMarkdown('*italic*'), 'italic
') assert.equal(renderMarkdown('_italic_'), 'italic
') assert.equal(renderMarkdown('__bold__'), 'bold
') }) test('inline code', () => { assert.equal(renderMarkdown('Use `npm test`'), 'Use npm test
'))
assert.ok(html.includes('const x = 1;'))
assert.ok(html.includes(''))
})
test('unordered lists', () => {
const md = '- One\n- Two\n- Three'
const html = renderMarkdown(md)
assert.ok(html.includes('')) assert.ok(html.includes('This is quoted')) assert.ok(html.includes('')) }) test('XSS: script tags are escaped', () => { const html = renderMarkdown('') assert.ok(!html.includes(')') assert.ok(!html.includes(' { const html = renderMarkdown('
')) assert.ok(html.includes('href="https://example.com"')) assert.ok(html.includes('')) assert.ok(html.includes('Important:')) assert.ok(!html.includes('href="javascript'), 'javascript: link must not become an anchor href') assert.ok(!html.includes('