mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-24 11:59:30 +00:00
27 lines
752 B
Dart
27 lines
752 B
Dart
|
|
/// Utility functions for handling HTML content
|
||
|
|
class HtmlUtils {
|
||
|
|
/// Strips HTML tags and decodes common HTML entities from a string
|
||
|
|
static String stripHtml(String htmlString) {
|
||
|
|
// Remove HTML tags
|
||
|
|
String text = htmlString.replaceAll(RegExp(r'<[^>]*>'), '');
|
||
|
|
|
||
|
|
// Decode common HTML entities
|
||
|
|
text = text
|
||
|
|
.replaceAll(' ', ' ')
|
||
|
|
.replaceAll('&', '&')
|
||
|
|
.replaceAll('<', '<')
|
||
|
|
.replaceAll('>', '>')
|
||
|
|
.replaceAll('"', '"')
|
||
|
|
.replaceAll(''', "'")
|
||
|
|
.replaceAll(''', "'");
|
||
|
|
|
||
|
|
// Replace multiple spaces with single space
|
||
|
|
text = text.replaceAll(RegExp(r'\s+'), ' ');
|
||
|
|
|
||
|
|
// Trim leading/trailing whitespace
|
||
|
|
text = text.trim();
|
||
|
|
|
||
|
|
return text;
|
||
|
|
}
|
||
|
|
}
|