import { renderMermaidSVG } from "beautiful-mermaid";
import {
marked,
Renderer,
type Token,
type Tokens,
type TokensList,
} from "marked";
import { escapeHtml, highlightHtml } from "./syntax-highlight.js";
import type { MarkdownReviewBlock } from "./types.js";
const MARKED_OPTIONS = { gfm: true, breaks: false } as const;
function safeHref(value: string): string | undefined {
if (value.startsWith("#")) return value;
try {
const url = new URL(value);
return ["http:", "https:", "mailto:"].includes(url.protocol)
? value
: undefined;
} catch {
return undefined;
}
}
function codeBlock(text: string, language?: string): string {
const name = language?.trim().split(/\s+/, 1)[0]?.toLowerCase();
const className = name ? ` class="language-${escapeHtml(name)}"` : "";
return `
${highlightHtml(text, name)}\n
`;
}
function localSvg(svg: string): string {
if (!svg.trimStart().startsWith("