feat(renderer): markdown lib (marked + DOMPurify + mermaid placeholders)

This commit is contained in:
2026-06-05 12:56:31 +05:30
parent 5d6a55dd09
commit f34775ce53
2 changed files with 59 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import { describe, it, expect } from 'vitest';
import { renderMarkdown } from '@/lib/markdown';
describe('renderMarkdown', () => {
it('renders headings', () => {
const html = renderMarkdown('# Hello');
expect(html).toContain('<h1>Hello</h1>');
});
it('renders bold and italic', () => {
const html = renderMarkdown('**bold** and *italic*');
expect(html).toContain('<strong>bold</strong>');
expect(html).toContain('<em>italic</em>');
});
it('renders code blocks with language class', () => {
const html = renderMarkdown('```js\nconst x = 1;\n```');
expect(html).toContain('language-js');
});
it('renders mermaid blocks with a placeholder', () => {
const html = renderMarkdown('```mermaid\ngraph TD\nA-->B\n```');
expect(html).toContain('data-mermaid-source=');
});
it('sanitizes dangerous HTML', () => {
const html = renderMarkdown('<script>alert(1)</script>');
expect(html).not.toContain('<script>');
});
});