This commit is contained in:
gosangam
2026-05-11 12:47:39 +05:30
parent e3df40559b
commit 7294d9e15b
+7 -2
View File
@@ -78,9 +78,14 @@ export function extractMatchedText(
fragment: { prefix: string; suffix: string; length: number },
paragraphs: string[],
): string | null {
// Strip HTML tags to get plain text
// Strip HTML tags and entities to get plain text. The entity regex must be
// strict — `&[^;]+;` would greedily pair a stray `&` (e.g. "24 & 25 Oct")
// with a far-away `;` (e.g. "my beloved son;"), eating everything between
// them. Only match real entities: named (&), decimal ('), hex (').
const plainParagraphs = paragraphs.map((p) =>
p.replace(/<[^>]*>/g, "").replace(/&[^;]+;/g, " "),
p
.replace(/<[^>]*>/g, "")
.replace(/&(?:[a-zA-Z][a-zA-Z0-9]*|#\d+|#x[0-9a-fA-F]+);/g, " "),
);
// Build a single string with paragraph breaks