Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718export const COLLAPSED_LINES = 28;
const PRE = /<pre(?:\s[^>]*)?>(?:(?!<pre[\s>])[\s\S])*?<\/pre>/g;
const lineCount = (pre: string): number => pre .replace(/<[^>]*>/g, "") .replace(/\n$/, "") .split("\n").length;
export const collapseCodeblocks = (html: string): string => html.replace(PRE, (pre) => { const lines = lineCount(pre); return lines < COLLAPSED_LINES ? pre : `<div data-codeblock="${lines}"><div data-codeblock-toolbar></div>${pre}</div>`; });