From 3d0dc2e81a494a1e5af161684f7400e2e4719f40 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 2 Nov 2024 13:37:14 +0100 Subject: [PATCH] feat: support color dots for 4 character hex. - Support color dot for 4-letter hex (`#fffa` which is equal to `#ffffffaa`). - Unit test added. --- modules/markup/markdown/color_util.go | 2 +- modules/markup/markdown/color_util_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/markup/markdown/color_util.go b/modules/markup/markdown/color_util.go index 355fef3fc0..efbde6b730 100644 --- a/modules/markup/markdown/color_util.go +++ b/modules/markup/markdown/color_util.go @@ -6,7 +6,7 @@ package markdown import "regexp" var ( - hexRGB = regexp.MustCompile(`^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$`) + hexRGB = regexp.MustCompile(`^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$`) hsl = regexp.MustCompile(`^hsl\([ ]*([012]?[0-9]{1,2}|3[0-5][0-9]|360),[ ]*([0-9]{0,2}|100)\%,[ ]*([0-9]{0,2}|100)\%\)$`) hsla = regexp.MustCompile(`^hsla\(([ ]*[012]?[0-9]{1,2}|3[0-5][0-9]|360),[ ]*([0-9]{0,2}|100)\%,[ ]*([0-9]{0,2}|100)\%,[ ]*(1|1\.0|0|(0\.[0-9]+))\)$`) rgb = regexp.MustCompile(`^rgb\(([ ]*((([0-9]{1,2}|100)\%)|(([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))),){2}([ ]*((([0-9]{1,2}|100)\%)|(([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))))\)$`) diff --git a/modules/markup/markdown/color_util_test.go b/modules/markup/markdown/color_util_test.go index c6e0555a35..9f6448cf8c 100644 --- a/modules/markup/markdown/color_util_test.go +++ b/modules/markup/markdown/color_util_test.go @@ -17,6 +17,7 @@ func TestMatchColor(t *testing.T) { {"#ddeeffa0", true}, {"#ddeefe", true}, {"#abcdef", true}, + {"#fffa", true}, {"#abcdeg", false}, {"#abcdefg0", false}, {"black", false},