import LRU from "lru-cache";
const renderCache = new LRU<string, string>({ max: 100 });
import { sha1 } from "@cocalc/backend/sha1";
import { markdown_to_html } from "@cocalc/frontend/markdown";
export function renderMarkdown(text: string): string {
const key = sha1(text);
const cached = renderCache.get(key);
if (cached) return cached;
const html = markdown_to_html(text);
renderCache.set(key, html);
return html;
}
export function extractID(
param: string | string[] | undefined
): number | undefined {
if (param == null || typeof param !== "string") return;
const idStr = param.split("-").pop();
const id = Number(idStr);
if (!Number.isInteger(id) || id < 0) return;
return id;
}