` tag. Defaults to `false`. * * @returns The converted HTML string. */ export function mdToHtml(md: string, inline?: boolean): string; /** * Converts Markdown to an HTML string and sanitizes it. * * @param md The markdown to convert. * @param inline Whether to render the markdown as inline, without a wrapping `
` tag. Defaults to `false`. * * @returns The converted HTML string. */ export function mdToHtml( md: string | undefined, inline?: boolean ): string | undefined; export function mdToHtml( md: string | undefined, inline: boolean = false ): string | undefined { if (md == null) { return undefined; } const rawHtml = inline ? markdown.renderInline(md) : markdown.render(md); const safeHtml: string = sanitizeHtml(rawHtml, htmlSanitizeOptions); // Revert some escaped characters for comparison. if (comparableSanitizedHtml(rawHtml) === comparableSanitizedHtml(safeHtml)) { return adjustUrls(safeHtml); } console.debug('Rejected unsafe md:\n', md); console.error('Rejected unsafe html:\n', rawHtml); console.error('Clean unsafe html:\n', comparableSanitizedHtml(rawHtml)); console.error('Clean safe html:\n', comparableSanitizedHtml(safeHtml)); console.log('-'.repeat(80)); throw new Error('Found unsafe html'); } export function adjustUrls(description: string): string { return description.replaceAll(/https:\/\/(next.)?fakerjs.dev\//g, '/'); }