/** Extract plain text from an HTML fragment using the platform's DOMParser
 *  when available. Falls back to a regex strip when DOMParser is missing
 *  (e.g. SSR / older runtimes). Whitespace normalised.
 *  SCRUM-268 — cards show HTML-encoded markup as literal text otherwise.
 */
export function extractTextFromHtml(html) {
    if (!html)
        return "";
    if (typeof DOMParser !== "undefined") {
        try {
            const doc = new DOMParser().parseFromString(html, "text/html");
            return (doc.body?.textContent || "").replace(/\s+/g, " ").trim();
        }
        catch {
            // fall through to regex
        }
    }
    return html
        .replace(/<[^>]*>/g, " ")
        .replace(/&[a-z#0-9]+;/gi, " ")
        .replace(/\s+/g, " ")
        .trim();
}
