export const COLLAPSED_LINES = 28; const PRE = /
]*)?>(?:(?!])[\s\S])*?<\/pre>/g; const MERMAID = /^]*\bclass="mermaid"/; const lineCount = (pre: string): number => pre .replace(/<[^>]*>/g, "") .replace(/\n$/, "") .split("\n").length; export const collapseCodeblocks = (html: string): string => html.replace(PRE, (pre) => { if (MERMAID.test(pre)) return pre; const lines = lineCount(pre); return lines < COLLAPSED_LINES ? pre : `${pre}`; });