import { describe, it, expect } from 'vitest'; import { renderMarkdown, stripMarkdown } from './markdown.js'; describe('renderMarkdown', () => { it('should render bold text', () => { const html = renderMarkdown('**bold**'); expect(html).toContain('bold'); }); it('should render italic text', () => { const html = renderMarkdown('*italic*'); expect(html).toContain('italic'); }); it('should render headings', () => { const html = renderMarkdown('# Heading 1'); expect(html).toContain('

Heading 1

'); }); it('should render unordered lists', () => { const html = renderMarkdown('- item 1\n- item 2'); expect(html).toContain('
  • item 1
  • '); expect(html).toContain('
  • item 2
  • '); }); it('should render ordered lists', () => { const html = renderMarkdown('1. first\n2. second'); expect(html).toContain('
  • first
  • '); expect(html).toContain('
  • second
  • '); }); it('should render code blocks', () => { const html = renderMarkdown('```\nconst x = 1;\n```'); expect(html).toContain(''); expect(html).toContain('const x = 1;'); }); it('should syntax-highlight a fenced block that names its language', () => { const html = renderMarkdown('```ts\nconst x: number = 1;\n```'); expect(html).toContain(''); expect(html).toContain('const'); expect(html).toContain('1'); }); it('should leave an unlabelled fence as plain text rather than guessing a language', () => { const html = renderMarkdown('```\nSELECT * FROM users;\n```'); expect(html).toContain('
    SELECT * FROM users;');
    		expect(html).not.toContain('hljs-');
    	});
    
    	it('should leave a fence with an unknown language as plain text but keep its label', () => {
    		const html = renderMarkdown('```brainfuck\n+++\n```');
    		expect(html).toContain('+++');
    		expect(html).not.toContain('hljs-');
    	});
    
    	it('should keep code in a highlighted fence escaped', () => {
    		const html = renderMarkdown('```html\n\n```');
    		expect(html).not.toContain('');
    		expect(html).not.toContain(' {
    		const html = renderMarkdown('[ ] todo\n\n[x] done');
    		expect(html).toContain('type="checkbox"');
    		expect(html).toContain('checked');
    		expect(html).toContain('disabled');
    		expect(html).toContain('class="task-checkbox"');
    	});
    
    	it('should render an empty task item as a checkbox, not literal brackets', () => {
    		const html = renderMarkdown('- [ ] Train tickets\n- [ ]');
    		expect(html).not.toContain('[ ]');
    		expect(html.match(/type="checkbox"/g)).toHaveLength(2);
    	});
    
    	it('should render an empty checked task item as a checked checkbox', () => {
    		const html = renderMarkdown('- [x]');
    		expect(html).not.toContain('[x]');
    		expect(html).toContain('');
    		expect(html).toContain('class="task-list"');
    	});
    
    	it('should not treat brackets glued to text as a task marker', () => {
    		const html = renderMarkdown('- [ ]x');
    		expect(html).not.toContain('type="checkbox"');
    		expect(html).toContain('[ ]x');
    	});
    });
    
    describe('stripMarkdown', () => {
    	it('should remove markdown formatting', () => {
    		expect(stripMarkdown('**bold** and *italic*')).toBe('bold and italic');
    	});
    
    	it('should remove code blocks', () => {
    		expect(stripMarkdown('```\ncode\n```')).toBe('');
    	});
    
    	it('should remove inline code backticks', () => {
    		expect(stripMarkdown('Use `command`')).toBe('Use');
    	});
    
    	it('should extract link text', () => {
    		expect(stripMarkdown('[Click here](https://example.com)')).toBe('Click here');
    	});
    
    	it('should return empty for empty input', () => {
    		expect(stripMarkdown('')).toBe('');
    	});
    });
    
    describe('renderMarkdown note-link handling', () => {
    	it('should render a crumb-note:// link as plain text, not a clickable anchor', () => {
    		const html = renderMarkdown('See [Grocery List](crumb-note://abc-123) for details');
    		expect(html).not.toContain(' {
    		const html = renderMarkdown('See [Example](https://example.com) for details');
    		expect(html).toContain('