filterHtmlOnly function
Implementation
String filterHtmlOnly(String html, {List<String>? unwantedSelectors}) {
try {
final document = html_parser.parse(html);
// Remove unwanted elements
final selectors = unwantedSelectors ??
['script', 'style', 'iframe', 'noscript', 'link', 'meta'];
for (final selector in selectors) {
document.querySelectorAll(selector).forEach((element) {
element.remove();
});
}
return document.outerHtml;
} catch (e) {
return html;
}
}