@@ -568,11 +568,12 @@ end --}}}
568
568
569
569
local function detect_colors (str ) -- {{{
570
570
local hex_pattern = " #%x%x%x%x%x%x%x?%x?"
571
+ local short_hex_pattern = " #%x%x%x"
571
572
local rgb_pattern = " rgba?%(%s*%d+%s*,%s*%d+%s*,%s*%d+%s*.*%)"
572
573
local hsl_pattern = " hsla?%(%s*%d+%s*,%s*%d+%s*%%*,%s*%d+%s*%%*.*%)"
573
574
574
575
local results = {}
575
- local patterns = { hex_pattern , rgb_pattern , hsl_pattern }
576
+ local patterns = { hex_pattern , short_hex_pattern , rgb_pattern , hsl_pattern }
576
577
577
578
for _ , pattern in ipairs (patterns ) do
578
579
local start_index = 1
@@ -633,13 +634,15 @@ end --}}}
633
634
local function sandwich_processor (str ) -- {{{
634
635
local hex_capture_pattern = " #(%x%x%x%x%x%x)"
635
636
local hexa_capture_pattern = " #(%x%x%x%x%x%x)(%x%x)"
637
+ local short_hex_capture_pattern = " #(%x%x%x)"
636
638
local rgba_capture_pattern = " rgba%(%s*(%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*,?%s*(%d+%.?%d*)%s*%)"
637
639
local hsla_capture_pattern = " hsla%(%s*(%d+)%s*,%s*(%d+)%s*%%*,%s*(%d+)%s*%%,?%s*(%d+%.?%d*)%s*%)"
638
640
local rgb_capture_pattern = " rgb%(%s*(%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*,?%s*%)"
639
641
local hsl_capture_pattern = " hsl%(%s*(%d+)%s*,%s*(%d+)%s*%%*,%s*(%d+)%s*%%,?%s*%)"
640
642
641
643
local _ , _ , hex_val , hex_trans = string.find (str , hexa_capture_pattern )
642
644
local _ , _ , hex = string.find (str , hex_capture_pattern )
645
+ local _ , _ , short_hex = string.find (str , short_hex_capture_pattern )
643
646
local _ , _ , ra , ga , ba , rgba = string.find (str , rgba_capture_pattern )
644
647
local _ , _ , ha , sa , la , hsla = string.find (str , hsla_capture_pattern )
645
648
local _ , _ , r , g , b = string.find (str , rgb_capture_pattern )
@@ -648,6 +651,11 @@ local function sandwich_processor(str) --{{{
648
651
return { " hex" , hex_val , hex_trans }
649
652
elseif hex then
650
653
return { " hex" , hex }
654
+ elseif short_hex then
655
+ local red = short_hex :sub (1 , 1 )
656
+ local green = short_hex :sub (2 , 2 )
657
+ local blue = short_hex :sub (3 , 3 )
658
+ return { " hex" , red .. red .. green .. green .. blue .. blue }
651
659
elseif ra then
652
660
return { " rgb" , tonumber (ra ), tonumber (ga ), tonumber (ba ), tonumber (rgba ) }
653
661
elseif ha then
0 commit comments