diff --git a/lib/features/item_viewer/view/library_item_page.dart b/lib/features/item_viewer/view/library_item_page.dart index e7b9310..f297320 100644 --- a/lib/features/item_viewer/view/library_item_page.dart +++ b/lib/features/item_viewer/view/library_item_page.dart @@ -10,6 +10,7 @@ import 'package:vaani/features/item_viewer/view/library_item_sliver_app_bar.dart import 'package:vaani/features/player/view/mini_player_bottom_padding.dart'; import 'package:vaani/router/models/library_item_extras.dart'; import 'package:vaani/shared/widgets/expandable_description.dart'; +import 'package:vaani/shared/utils/html_utils.dart'; import 'library_item_actions.dart'; import 'library_item_hero_section.dart'; @@ -149,9 +150,16 @@ class LibraryItemDescription extends HookConsumerWidget { if (item == null) { return const SizedBox(); } + + // Get description and strip HTML tags + final rawDescription = item.media.metadata.description; + final cleanDescription = rawDescription != null + ? HtmlUtils.stripHtml(rawDescription) + : 'Sorry, no description found'; + return ExpandableDescription( title: 'About the Book', - content: item.media.metadata.description ?? 'Sorry, no description found', + content: cleanDescription, ); } } diff --git a/lib/shared/utils/html_utils.dart b/lib/shared/utils/html_utils.dart new file mode 100644 index 0000000..46160f8 --- /dev/null +++ b/lib/shared/utils/html_utils.dart @@ -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; + } +}