src / engine / normalization / HtmlCleaner.ts
/**
* Pure helper utility to strip HTML/XML tags and decode standard HTML entities.
* Ensures search result strings contain zero markup pollution.
*/
export class HtmlCleaner {
/**
* Strips all HTML/XML tags and decodes standard HTML entities.
*/
public static stripHtml(str: string): string {
if (!str) return "";
return str
// Remove HTML/XML tags (<script>, <style>, <div>, etc.)
.replace(/<[^>]+>/g, "")
// Decode standard HTML entities
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/ /g, " ");
}
}
src / engine / normalization / HtmlCleaner.ts
/**
* Pure helper utility to strip HTML/XML tags and decode standard HTML entities.
* Ensures search result strings contain zero markup pollution.
*/
export class HtmlCleaner {
/**
* Strips all HTML/XML tags and decodes standard HTML entities.
*/
public static stripHtml(str: string): string {
if (!str) return "";
return str
// Remove HTML/XML tags (<script>, <style>, <div>, etc.)
.replace(/<[^>]+>/g, "")
// Decode standard HTML entities
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/ /g, " ");
}
}