@@ -2,15 +2,21 @@ local files = require "files"
2
2
local guide = require " parser.guide"
3
3
4
4
local colorPattern = string.rep (' %x' , 8 )
5
+ local hex6Pattern = string.format (" ^#%s" , string.rep (' %x' , 6 ))
5
6
--- @param source parser.object
6
7
--- @return boolean
7
8
local function isColor (source )
8
9
--- @type string
9
10
local text = source [1 ]
10
- if text :len () ~ = 8 then
11
- return false
11
+ if text :len () = = 8 then
12
+ return text : match ( colorPattern )
12
13
end
13
- return text :match (colorPattern )
14
+
15
+ if text :len () == 7 then
16
+ return text :match (hex6Pattern )
17
+ end
18
+
19
+ return false
14
20
end
15
21
16
22
@@ -25,6 +31,16 @@ local function textToColor(colorText)
25
31
}
26
32
end
27
33
34
+ --- @param colorText string
35
+ --- @return Color
36
+ local function hexTextToColor (colorText )
37
+ return {
38
+ alpha = 255 ,
39
+ red = tonumber (colorText :sub (2 , 3 ), 16 ) / 255 ,
40
+ green = tonumber (colorText :sub (4 , 5 ), 16 ) / 255 ,
41
+ blue = tonumber (colorText :sub (6 , 7 ), 16 ) / 255 ,
42
+ }
43
+ end
28
44
29
45
--- @param color Color
30
46
--- @return string
@@ -63,10 +79,12 @@ local function colors(uri)
63
79
--- @type string
64
80
local colorText = source [1 ]
65
81
82
+ local color = colorText :match (colorPattern ) and textToColor (colorText ) or hexTextToColor (colorText )
83
+
66
84
colorValues [# colorValues + 1 ] = {
67
85
start = source .start + 1 ,
68
86
finish = source .finish - 1 ,
69
- color = textToColor ( colorText )
87
+ color = color
70
88
}
71
89
end
72
90
end )
0 commit comments