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:
@@ -85,8 +85,9 @@ class _LearnMoreScreenState extends State<LearnMoreScreen> {
|
|||||||
_event = ev;
|
_event = ev;
|
||||||
});
|
});
|
||||||
_startAutoScroll();
|
_startAutoScroll();
|
||||||
} catch (_) {
|
} catch (e) {
|
||||||
// Silently fail — the pre-loaded data is already displayed
|
// 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
|
/// Parse an HTML important_information string into a list of {title, value} maps
|
||||||
List<Map<String, String>> _parseHtmlImportantInfo(String raw) {
|
List<Map<String, String>> _parseHtmlImportantInfo(String raw) {
|
||||||
// Strip HTML tags, preserving <br> as a newline separator first
|
var text = raw;
|
||||||
var text = raw
|
// 1. Remove <style>...</style> blocks entirely (content + tags)
|
||||||
.replaceAll(RegExp(r'<br\s*/?>', caseSensitive: false), '\n')
|
text = text.replaceAll(RegExp(r'<style[^>]*>.*?</style>', caseSensitive: false, dotAll: true), '');
|
||||||
.replaceAll(RegExp(r'<[^>]*>'), '');
|
// 2. Remove <script>...</script> blocks
|
||||||
// Decode entities
|
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
|
text = text
|
||||||
.replaceAll('&', '&')
|
.replaceAll('&', '&')
|
||||||
.replaceAll('<', '<')
|
.replaceAll('<', '<')
|
||||||
|
|||||||
Reference in New Issue
Block a user