mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-01-18 08:09:33 +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
|
|
@ -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/features/player/view/mini_player_bottom_padding.dart';
|
||||||
import 'package:vaani/router/models/library_item_extras.dart';
|
import 'package:vaani/router/models/library_item_extras.dart';
|
||||||
import 'package:vaani/shared/widgets/expandable_description.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_actions.dart';
|
||||||
import 'library_item_hero_section.dart';
|
import 'library_item_hero_section.dart';
|
||||||
|
|
@ -149,9 +150,16 @@ class LibraryItemDescription extends HookConsumerWidget {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return const SizedBox();
|
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(
|
return ExpandableDescription(
|
||||||
title: 'About the Book',
|
title: 'About the Book',
|
||||||
content: item.media.metadata.description ?? 'Sorry, no description found',
|
content: cleanDescription,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
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