The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.
JavaScript
import { describe, expect, it } from 'vitest';
import { entityReference, markdownHtml, remoteImageUrls } from './markdown.js';
describe('markdownHtml', () => {
it('renders GitHub-flavored tables, task lists and fenced code', () => {
const html = markdownHtml('| Name | Value |\n| --- | --- |\n| A | B |\n\n- [x] done\n\n```js\nconst x = 1;\n```');
expect(html).toContain('<table>');
expect(html).toContain('type="checkbox"');
expect(html).toContain('<pre><code class="language-js">');
});
it('removes unsafe HTML and URL schemes', () => {
const html = markdownHtml('<script>alert(1)</script>\n\n[bad](javascript:alert(1))');
expect(html).not.toContain('<script>');
expect(html).not.toContain('javascript:');
});
it('renders entity references as clickable local links', () => {
const source = entityReference({ id: 'e_lead', label: 'Lead' });
expect(source).toBe('[[entity:e_lead|Lead]]');
expect(markdownHtml(source, { entities: [{ id: 'e_lead', label: 'Lead' }] }))
.toContain('data-entity-id="e_lead"');
});
it('keeps deleted case references visible as broken', () => {
expect(markdownHtml('[[entity:e_gone|Deleted lead]]')).toContain('Reference unavailable: Deleted lead');
expect(markdownHtml('', { caseId: 'case-1' }))
.toContain('Media unavailable: Deleted image');
});
it('opens the survivor while preserving the original wording and escaping its label', () => {
const source = '[[entity:old|Earlier name]]';
const html = markdownHtml(source, {
entities: [{ id: 'kept', label: 'Kept "subject" <test>' }],
redirects: { old: { id: 'kept', label: 'Earlier name' } },
});
expect(html).toContain('data-entity-id="kept"');
expect(html).toContain('Merged into Kept "subject" <test>');
expect(html).toContain('>Earlier name</a>');
expect(markdownHtml(source, { redirects: { old: { id: 'gone' } } }))
.toContain('Reference unavailable');
});
it('sizes and aligns images without allowing unsafe values', () => {
const html = markdownHtml('{width=50% align=center}');
expect(html).toContain('class="markdown-image align-center"');
expect(html).toContain('style="width: 50%"');
const invalid = markdownHtml('{width=99999px align=diagonal}');
expect(invalid).toContain('class="markdown-image align-left"');
expect(invalid).not.toContain('width:');
});
it('applies alignment blocks to rendered Markdown content', () => {
const html = markdownHtml('::: center\n**Centred text**\n:::');
expect(html).toContain('<div class="markdown-align align-center">');
expect(html).toContain('<strong>Centred text</strong>');
});
it('applies image options to case media', () => {
const html = markdownHtml('[[media:e_image|Map]]{width=320px align=right}', {
caseId: 'case-1',
entities: [{ id: 'e_image', label: 'Map', type: 'media', attrs: { path: 'media/map.png', kind: 'image' } }],
});
expect(html).toContain('src="/files/case-1/media/map.png"');
expect(html).toContain('class="markdown-image align-right"');
expect(html).toContain('style="width: 320px"');
});
});
describe('mermaid fences', () => {
it('wraps the diagram source instead of rendering it as code', () => {
const html = markdownHtml('```mermaid\nflowchart LR\n A --> B\n```');
expect(html).toContain('<div class="mermaid-diagram"><pre class="mermaid-source">');
expect(html).not.toContain('language-mermaid');
expect(html).toContain('flowchart LR');
});
it('escapes the source so a diagram cannot inject markup', () => {
const html = markdownHtml('```mermaid\nflowchart LR\n A["<img src=x onerror=alert(1)>"] --> B\n```');
expect(html).not.toContain('<img');
expect(html).toContain('<img src=x onerror=alert(1)>');
});
it('leaves other fenced languages alone', () => {
expect(markdownHtml('```mermaidjs\nnot a diagram\n```')).toContain('language-mermaidjs');
expect(markdownHtml('```\nplain\n```')).toContain('<pre><code>');
});
});
describe('remoteImageUrls', () => {
it('reports external inline images but not links or case media', () => {
const source = [
'[Website](https://example.com/page)',
'',
'',
'[[media:e_local|Filed image]]',
].join('\n\n');
expect(remoteImageUrls(source)).toEqual(['https://images.example/pixel.png']);
});
it('deduplicates remote images and recognizes protocol-relative URLs', () => {
const source = '\n';
expect(remoteImageUrls(source)).toEqual(['https://images.example/a.png']);
});
});