diff --git a/CHANGELOG.md b/CHANGELOG.md index a88a0302..bcfd0ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - 修复积分统计页面我的积分标签页中缺少空隙的问题。 +- 修复部分楼层丢失字体颜色的问题。 ## [0.6.0] - 2024-02-08 diff --git a/lib/packages/html_muncher/lib/src/html_muncher.dart b/lib/packages/html_muncher/lib/src/html_muncher.dart index c3b7806a..c80b339f 100644 --- a/lib/packages/html_muncher/lib/src/html_muncher.dart +++ b/lib/packages/html_muncher/lib/src/html_muncher.dart @@ -124,6 +124,8 @@ class Muncher { /// Munch state to use when munching. final MunchState state = MunchState(); + static final _colorRe = RegExp(r'^(#)?[0-9a-fA-F]{1,6}$'); + /// Map to store div classes and corresponding munch functions. Map? _divMap; @@ -644,11 +646,18 @@ class Muncher { // Set to an invalid color value if "color" attribute not found. final attr = colorString ?? element.attributes['color']; int? colorValue; - if (attr != null && attr.startsWith('#')) { - colorValue = int.tryParse( - element.attributes['color']?.substring(1).padLeft(8, 'ff') ?? 'g', - radix: 16, - ); + if (attr != null && _colorRe.hasMatch(attr)) { + if (attr.startsWith('#')) { + colorValue = int.tryParse( + element.attributes['color']?.substring(1).padLeft(8, 'ff') ?? 'g', + radix: 16, + ); + } else { + colorValue = int.tryParse( + element.attributes['color']?.padLeft(8, 'ff') ?? 'g', + radix: 16, + ); + } } Color? color; if (colorValue != null) {