diff --git a/lib/src/default_tags/basic_tags.dart b/lib/src/default_tags/basic_tags.dart index 8124911..fe8b9fc 100644 --- a/lib/src/default_tags/basic_tags.dart +++ b/lib/src/default_tags/basic_tags.dart @@ -64,13 +64,19 @@ 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; } }