fix: important information now displays correctly on event details

Fixed HTML parser to strip <style> and <script> blocks entirely
(including their content) before extracting text. Previously, CSS
rules like "td {border: 1px solid...}" leaked into the parsed output.
Also added </div>, </p>, </li> as newline separators so div-wrapped
content (common in Django admin rich text) parses into separate items.
Added debug logging to _loadFullDetails for troubleshooting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-30 22:13:38 +05:30
parent 2fc45e0c5b
commit 6c533614b3

View File

@@ -85,8 +85,9 @@ class _LearnMoreScreenState extends State<LearnMoreScreen> {
_event = ev;
});
_startAutoScroll();
} catch (_) {
// Silently fail — the pre-loaded data is already displayed
} catch (e) {
// Log for debugging, but don't show error — the pre-loaded data is displayed
debugPrint('_loadFullDetails failed for event ${widget.eventId}: $e');
}
}
@@ -1221,11 +1222,20 @@ class _LearnMoreScreenState extends State<LearnMoreScreen> {
/// Parse an HTML important_information string into a list of {title, value} maps
List<Map<String, String>> _parseHtmlImportantInfo(String raw) {
// Strip HTML tags, preserving <br> as a newline separator first
var text = raw
.replaceAll(RegExp(r'<br\s*/?>', caseSensitive: false), '\n')
.replaceAll(RegExp(r'<[^>]*>'), '');
// Decode entities
var text = raw;
// 1. Remove <style>...</style> blocks entirely (content + tags)
text = text.replaceAll(RegExp(r'<style[^>]*>.*?</style>', caseSensitive: false, dotAll: true), '');
// 2. Remove <script>...</script> blocks
text = text.replaceAll(RegExp(r'<script[^>]*>.*?</script>', caseSensitive: false, dotAll: true), '');
// 3. Convert block-level closers to newlines
text = text.replaceAll(RegExp(r'</div>', caseSensitive: false), '\n');
text = text.replaceAll(RegExp(r'</p>', caseSensitive: false), '\n');
text = text.replaceAll(RegExp(r'</li>', caseSensitive: false), '\n');
// 4. Convert <br> to newlines
text = text.replaceAll(RegExp(r'<br\s*/?>', caseSensitive: false), '\n');
// 5. Strip all remaining HTML tags
text = text.replaceAll(RegExp(r'<[^>]*>'), '');
// 6. Decode HTML entities
text = text
.replaceAll('&amp;', '&')
.replaceAll('&lt;', '<')