fix: strip HTML tags from book descriptions for proper display

This commit is contained in:
Claude 2025-11-21 11:05:38 +00:00
parent 2b314696ac
commit d6e49238ec
No known key found for this signature in database
2 changed files with 35 additions and 1 deletions

View 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('&nbsp;', ' ')
.replaceAll('&amp;', '&')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&quot;', '"')
.replaceAll('&#39;', "'")
.replaceAll('&apos;', "'");
// Replace multiple spaces with single space
text = text.replaceAll(RegExp(r'\s+'), ' ');
// Trim leading/trailing whitespace
text = text.trim();
return text;
}
}