mirror of
https://github.com/norcalli/nvim-colorizer.lua.git
synced 2026-09-10 07:06:14 -04:00
fix: hsl: for multiple spaces in between
This commit is contained in:
parent
1f59884e0d
commit
2ae077973e
|
|
@ -12,6 +12,7 @@ local utils = require "colorizer.utils"
|
|||
local byte_is_alphanumeric = utils.byte_is_alphanumeric
|
||||
local byte_is_hex = utils.byte_is_hex
|
||||
local byte_is_valid_colorchar = utils.byte_is_valid_colorchar
|
||||
local count = utils.count
|
||||
local parse_hex = utils.parse_hex
|
||||
local percent_or_hex = utils.percent_or_hex
|
||||
|
||||
|
|
@ -100,7 +101,7 @@ function color.hsl_function_parser(line, i, opts)
|
|||
local min_commas, min_spaces = 2, 2
|
||||
local pattern = "^"
|
||||
.. opts.prefix
|
||||
.. "%(%s*([.%d]+)([deg]*)([turn]*)(,?)(%s?)%s*(%d+)%%(,?)(%s?)%s*(%d+)%%%s*(/?,?)%s*([.%d]*)([%%]?)%s*%)()"
|
||||
.. "%(%s*([.%d]+)([deg]*)([turn]*)(%s?)%s*(,?)%s*(%d+)%%(%s?)%s*(,?)%s*(%d+)%%%s*(/?,?)%s*([.%d]*)([%%]?)%s*%)()"
|
||||
|
||||
if opts.prefix == "hsl" then
|
||||
min_len = CSS_HSL_FN_MINIMUM_LENGTH
|
||||
|
|
@ -110,7 +111,7 @@ function color.hsl_function_parser(line, i, opts)
|
|||
return
|
||||
end
|
||||
|
||||
local h, deg, turn, csep1, ssep1, s, csep2, ssep2, l, sep3, a, percent_sign, match_end = line:sub(i):match(pattern)
|
||||
local h, deg, turn, ssep1, csep1, s, ssep2, csep2, l, sep3, a, percent_sign, match_end = line:sub(i):match(pattern)
|
||||
if not match_end then
|
||||
return
|
||||
end
|
||||
|
|
@ -129,11 +130,11 @@ function color.hsl_function_parser(line, i, opts)
|
|||
local s_seps = ("%s%s"):format(ssep1, ssep2)
|
||||
-- comma separator syntax
|
||||
if c_seps:match "," then
|
||||
if not (#c_seps:match ",*" == min_commas) then
|
||||
if not (count(c_seps, ",") == min_commas) then
|
||||
return
|
||||
end
|
||||
-- space separator syntax with decimal or percentage alpha
|
||||
elseif #s_seps:match "%s*" >= min_spaces then
|
||||
elseif count(s_seps, "%s") >= min_spaces then
|
||||
if a then
|
||||
if not (c_seps == "/") then
|
||||
return
|
||||
|
|
|
|||
|
|
@ -71,6 +71,14 @@ function utils.byte_is_valid_colorchar(byte)
|
|||
return utils.byte_is_alphanumeric(byte) or byte == ("-"):byte()
|
||||
end
|
||||
|
||||
---Count the number of character in a string
|
||||
---@param str string
|
||||
---@param pattern string
|
||||
---@return number
|
||||
function utils.count(str, pattern)
|
||||
return select(2, string.gsub(str, pattern, ""))
|
||||
end
|
||||
|
||||
--- Get last modified time of a file
|
||||
---@param path string: file path
|
||||
---@return number|nil: modified time
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ hsl(990 80% 50% / 0.4) hsl(720 80% 50% / 0.4)
|
|||
hsl(1turn 80% 50% / 0.4) hsl(0.4turn 80% 50% / 0.4) hsl(1.4turn 80% 50% / 0.4)
|
||||
hsla(300 50% 50%) hsla(300 50% 50% / 1)
|
||||
hsla(300 50% 50% / 0.4) hsla(300,50%,50%,05)
|
||||
hsla(360,50%,50%,1.0000000000000001)
|
||||
hsla(360 , 50% , 50% , 1.0000000000000001)
|
||||
]]
|
||||
|
||||
--[[ FAIL
|
||||
|
|
|
|||
Loading…
Reference in a new issue