Skip to content

Commit

Permalink
fix(html): Fix parsing hex color short hand format
Browse files Browse the repository at this point in the history
Fix parsing `#abc` which is short hand for `#aabbcc`.
  • Loading branch information
realth000 committed Sep 15, 2024
1 parent 89c0837 commit 824582a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/utils/html/css_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ extension StringToColorExt on String? {
// Parse as color value.
if (this != null && _colorRe.hasMatch(this!)) {
if (this!.startsWith('#')) {
colorValue = int.tryParse(this!.substring(1), radix: 16);
if (this!.length == 4) {
// #abc format short hand for #aabbcc.
colorValue = int.tryParse(
'${this![1]}${this![1]}${this![2]}'
'${this![2]}${this![3]}${this![3]}',
radix: 16,
);
} else {
// Normal #aabbcc format.
colorValue = int.tryParse(this!.substring(1), radix: 16);
}
} else {
colorValue = int.tryParse(this!, radix: 16);
}
Expand Down

0 comments on commit 824582a

Please sign in to comment.