import { describe, expect, it } from 'vitest' import { escapeHtml, mdToHtml } from '../../src/lib/md' // The md micro-renderer is the ONLY place dataset prose becomes HTML // (set:html in Timeline/Observatory/Directory/Checklist). It must escape // first and only ever emit ,
and Ext-policy anchors. describe('escapeHtml', () => { it('escapes all five HTML special characters', () => { expect(escapeHtml(` & `)).toBe( '<a href="x" title='y'> & </a>', ) }) }) describe('mdToHtml', () => { it('escapes HTML before rendering anything (no injection from overlays)', () => { expect(mdToHtml('')).toBe( '<script>alert("x")</script>', ) expect(mdToHtml('')).toBe('<img src=x onerror=alert(1)>') }) it('renders **bold** as ', () => { expect(mdToHtml('a **very bold** claim')).toBe('a very bold claim') }) it('renders [text](https://url) with the Ext.astro rel policy', () => { expect(mdToHtml('see [the ruling](https://example.org/a?b=c&d=e)')).toBe( 'see the ruling', ) }) it('never links non-https URLs (they stay literal, escaped text)', () => { expect(mdToHtml('[x](http://insecure.example)')).toBe('[x](http://insecure.example)') expect(mdToHtml('[x](javascript:alert(1))')).toBe('[x](javascript:alert(1))') }) it('escapes markup inside link labels', () => { expect(mdToHtml('[hi](https://example.org)')).toBe( '<b>hi</b>', ) }) it('renders bold inside a link label', () => { expect(mdToHtml('[**Blaze**, 1994](https://example.org)')).toBe( 'Blaze, 1994', ) }) it('converts line breaks to
', () => { expect(mdToHtml('one\ntwo')).toBe('one
two') }) it('renders NOTHING else from markdown', () => { expect(mdToHtml('# heading * item _em_ `code`')).toBe('# heading * item _em_ `code`') }) })