/**
* Rendering a repository's markdown into this page.
*
* The text belongs to whoever wrote the repository and the result is put
* straight into the document, so most of what follows is about what must not
* come out the other side.
*/
import { describe, expect, it } from 'vitest';
import {
isSafeHref,
renderMarkdown,
resolveRepoPath,
} from '../src/lib/markdown.js';
const render = (text, ctx = {}) =>
renderMarkdown(text, { repo: 'demo', refName: 'main', ...ctx });
describe('renderMarkdown, with no repository to resolve against', () => {
// Prose about the work rather than in it: a pull request's description, a
// review, an issue. It names no tree, so it is rendered with no context at
// all, and asking for one threw.
it('renders without a context', () => {
const html = renderMarkdown(
'# Title\n\nSome `code` and a [link](https://a.example/).',
);
expect(html).toContain('
');
expect(render('~~gone~~')).toContain('gone');
});
it('colours a fenced code block the way a file is coloured', () => {
const html = render(['```js', 'const a = 1;', '```'].join('\n'));
expect(html).toContain('md-code');
expect(html).toContain('hljs-keyword');
});
it('leaves a fence with no language uncoloured but escaped', () => {
const html = render(['```', '', '```'].join('\n'));
expect(html).not.toContain('');
expect(html).not.toContain('script');
expect(html).not.toContain('alert(1)');
});
it('keeps an image and drops the handler on it', () => {
const html = render('text more');
expect(html).not.toContain('onerror');
expect(html).toContain('');
});
it('drops an iframe rather than embedding it', () => {
const html = render('');
expect(html).not.toContain('iframe');
expect(html).not.toContain('evil.example');
});
it('keeps a block element and drops the handler on it', () => {
const html = render('