/** Conservative check: does a text/plain paste look like HTML rather than prose or Markdown? */ /** Block-level tags whose balanced open+close pair marks real HTML structure. */ const BLOCK_TAGS = 'table|div|p|h1|h2|h3|h4|h5|h6|ul|ol|blockquote|section|body'; const BALANCED_BLOCK = new RegExp( `<(${BLOCK_TAGS})(?:\\s[^>]*)?>[\\s\\S]*?`, 'i' ); export function looksLikeHtml(text: string): boolean { if (!text) return false; // Skip leading whitespace and HTML comments so a doctype/`` preamble // behind a comment still counts. let head = text.replace(/^\s+/, ''); while (head.startsWith(''); if (end === -1) break; head = head.slice(end + 3).replace(/^\s+/, ''); } const lower = head.toLowerCase(); if (lower.startsWith('