import { escapeHtml, noteLink, renderList, renderTable, renderResults } from './html'; import { ResourceView } from '.'; import { URI } from '../model/uri'; // `renderList` / `renderTable` route markdown-bearing fields (`body`, `content`, // `section[...]`) through the injected `renderMarkdown` callback. Other fields // keep going through `escapeHtml`. Absent callback → escaped raw markdown. // `toHref` test stub: produces a stable href shape for assertions. The contract // is "host returns the full href string", so the stub returns the URI path // (callers asserted on `href="/notes/alpha.md"` before the API change and the // same assertions still hold). const pathHref = (uri: URI) => uri.path; describe('renderList / renderTable — markdown-bearing fields', () => { const fakeMd = (md: string) => `

RENDERED:${md}

`; const rows: ResourceView[] = [ { uri: URI.file('/q1.md'), title: 'Q1', body: '# Q1\n\nWhat is X?', content: 'What is X?', 'section[Question]': 'What is X?', }, ]; it('renderList pipes `body` through renderMarkdown', () => { const html = renderList(rows, ['title', 'body'], pathHref, fakeMd).html; expect(html).toContain('RENDERED:# Q1'); expect(html).not.toContain('<p>'); // not double-escaped }); it('renderList pipes `content` through renderMarkdown', () => { const html = renderList(rows, ['content'], pathHref, fakeMd).html; expect(html).toContain('RENDERED:What is X?'); }); it('renderList pipes `section[...]` through renderMarkdown', () => { const html = renderList(rows, ['section[Question]'], pathHref, fakeMd).html; expect(html).toContain('RENDERED:What is X?'); }); it('renderTable pipes markdown fields through renderMarkdown in cells', () => { const html = renderTable(rows, ['title', 'body'], pathHref, fakeMd).html; expect(html).toContain('RENDERED:# Q1'); }); it('without a renderMarkdown callback, markdown fields fall back to escaped text', () => { const rowsWithHtmlInBody: ResourceView[] = [ { uri: URI.file('/x.md'), title: 'X', body: '', }, ]; const html = renderList(rowsWithHtmlInBody, ['body'], pathHref).html; expect(html).not.toContain('