og fix
This commit is contained in:
@@ -78,9 +78,14 @@ export function extractMatchedText(
|
|||||||
fragment: { prefix: string; suffix: string; length: number },
|
fragment: { prefix: string; suffix: string; length: number },
|
||||||
paragraphs: string[],
|
paragraphs: string[],
|
||||||
): string | null {
|
): 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) =>
|
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
|
// Build a single string with paragraph breaks
|
||||||
|
|||||||
Reference in New Issue
Block a user