Something went wrong. Try again.
The Social Wire — an ATProto publication reader. thesocialwire.app
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839const NAMED_HTML_ENTITIES: Record<string, string> = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\u00A0", ndash: "–", mdash: "—", hellip: "…", lsquo: "\u2018", rsquo: "\u2019", ldquo: "\u201C", rdquo: "\u201D",};
/** Decodes HTML entities and strips markup from plain-text titles and summaries. */export function decodeHtmlEntities(text: string): string { const trimmed = text.trim(); if (!trimmed) return trimmed;
const withoutTags = trimmed.includes("<") ? trimmed.replace(/<[^>]+>/g, "") : trimmed; if (!withoutTags.includes("&")) return withoutTags;
return withoutTags .replace(/&#(\d+);/g, (_, code: string) => String.fromCodePoint(Number(code)) ) .replace(/&#x([0-9a-fA-F]+);/g, (_, hex: string) => String.fromCodePoint(parseInt(hex, 16)) ) .replace(/&([a-z]+);/gi, (match, name: string) => { const decoded = NAMED_HTML_ENTITIES[name.toLowerCase()]; return decoded ?? match; });}