Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/lib/search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,10 @@ export class BraveSearchService {
}

private extractTextContent(html: string): string {
// Repeatedly remove <script> and <style> tags and their content
let sanitized = html;
let previous;
do {
previous = sanitized;
sanitized = sanitized
.replace(/<script[^>]*>.*?<\/script>/gis, '')
.replace(/<style[^>]*>.*?<\/style>/gis, '');
} while (sanitized !== previous);
return sanitized
.replace(/<[^>]*>/g, ' ')
.replace(/\s+/g, ' ')
.trim();
// Use cheerio to robustly remove <script> and <style> tags and extract text
const $ = cheerio.load(html);
$('script, style').remove();
return $.root().text().replace(/\s+/g, ' ').trim();
}
}

Expand Down
Loading