mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-25 12:29:30 +00:00
fix: strip HTML tags from book descriptions for proper display
This commit is contained in:
parent
2b314696ac
commit
d6e49238ec
2 changed files with 35 additions and 1 deletions
26
lib/shared/utils/html_utils.dart
Normal file
26
lib/shared/utils/html_utils.dart
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/// 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue