sanitizeHtml function
Removes <script>/<style> blocks, then strips all remaining tags, leaving
plain text. See the library note: this is text extraction, not sanitization.
Audited: 2026-06-12 11:26 EDT
Implementation
String sanitizeHtml(String html) {
String s = html.replaceAllMapped(
RegExp(r'<script[^>]*>[\s\S]*?</script>', caseSensitive: false),
(_) => '',
);
s = s.replaceAllMapped(RegExp(r'<style[^>]*>[\s\S]*?</style>', caseSensitive: false), (_) => '');
return stripHtmlTags(s);
}