From 1f4c3ff50079154de657d263fbbb86893a71ebbe Mon Sep 17 00:00:00 2001 From: kechuan <42696536+kechuan@users.noreply.github.com> Date: Fri, 14 Mar 2025 19:51:39 +0800 Subject: [PATCH 1/2] Patch ColorTag filter unformat HEXColor to prevent FormatException crash. --- lib/src/default_tags/basic_tags.dart | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/default_tags/basic_tags.dart b/lib/src/default_tags/basic_tags.dart index 8124911..974cce1 100644 --- a/lib/src/default_tags/basic_tags.dart +++ b/lib/src/default_tags/basic_tags.dart @@ -64,15 +64,20 @@ class ColorTag extends StyleTag { @override TextStyle transformStyle( TextStyle oldStyle, Map? attributes) { + RegExp hexColorRegExp = RegExp(r'^#?[0-9a-f]{6}$',caseSensitive : false); + if (attributes?.entries.isEmpty ?? true) { return oldStyle; } - String? hexColor = attributes?.entries.first.key; - if (hexColor == null) return oldStyle; - return oldStyle.copyWith(color: HexColor.fromHex(hexColor)); + String? hexColor = attributes?.entries.first.key ?? ""; + + if(hexColorRegExp.hasMatch(hexColor)){ + return oldStyle.copyWith(color: HexColor.fromHex(hexColor)); + } + + return oldStyle; } -} /// Basic implementation of the [h] tag. /// [_textSize] is used to define the new textSize. From d132f41db7da7486124852aaefebed47947d2c19 Mon Sep 17 00:00:00 2001 From: kechuan <42696536+kechuan@users.noreply.github.com> Date: Fri, 14 Mar 2025 20:15:16 +0800 Subject: [PATCH 2/2] lack of end symbol was edited in Web. no attention on it. --- lib/src/default_tags/basic_tags.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/default_tags/basic_tags.dart b/lib/src/default_tags/basic_tags.dart index 974cce1..fe8b9fc 100644 --- a/lib/src/default_tags/basic_tags.dart +++ b/lib/src/default_tags/basic_tags.dart @@ -78,6 +78,7 @@ class ColorTag extends StyleTag { return oldStyle; } +} /// Basic implementation of the [h] tag. /// [_textSize] is used to define the new textSize.