feat(hipatterns): made tailwind ft and style configurable
This commit is contained in:
@ -10,15 +10,25 @@ M.plugin = {
|
|||||||
local hi = require("mini.hipatterns")
|
local hi = require("mini.hipatterns")
|
||||||
return {
|
return {
|
||||||
-- custom LazyVim option to enable the tailwind integration
|
-- custom LazyVim option to enable the tailwind integration
|
||||||
tailwind = true,
|
tailwind = {
|
||||||
|
enabled = true,
|
||||||
|
ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" },
|
||||||
|
-- full: the whole css class will be highlighted
|
||||||
|
-- compact: only the color will be highlighted
|
||||||
|
style = "full",
|
||||||
|
},
|
||||||
highlighters = {
|
highlighters = {
|
||||||
hex_color = hi.gen_highlighter.hex_color({ priority = 2000 }),
|
hex_color = hi.gen_highlighter.hex_color({ priority = 2000 }),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
if opts.tailwind then
|
-- backward compatibility
|
||||||
local tailwind_ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" }
|
if opts.tailwind == true then
|
||||||
|
opts.tailwind =
|
||||||
|
{ enabled = true, ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" } }
|
||||||
|
end
|
||||||
|
if type(opts.tailwind) == "table" and opts.tailwind.enabled then
|
||||||
-- reset hl groups when colorscheme changes
|
-- reset hl groups when colorscheme changes
|
||||||
vim.api.nvim_create_autocmd("ColorScheme", {
|
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||||
callback = function()
|
callback = function()
|
||||||
@ -27,9 +37,18 @@ M.plugin = {
|
|||||||
})
|
})
|
||||||
opts.highlighters.tailwind = {
|
opts.highlighters.tailwind = {
|
||||||
pattern = function()
|
pattern = function()
|
||||||
return vim.tbl_contains(tailwind_ft, vim.bo.filetype) and "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]"
|
if not vim.tbl_contains(opts.tailwind.ft, vim.bo.filetype) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if opts.tailwind.style == "full" then
|
||||||
|
return "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]"
|
||||||
|
elseif opts.tailwind.style == "compact" then
|
||||||
|
return "%f[%w:-][%w:-]+%-()[a-z%-]+%-%d+()%f[^%w:-]"
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
group = function(_, match)
|
group = function(_, _, m)
|
||||||
|
---@type string
|
||||||
|
local match = m.full_match
|
||||||
---@type string, number
|
---@type string, number
|
||||||
local color, shade = match:match("[%w-]+%-([a-z%-]+)%-(%d+)")
|
local color, shade = match:match("[%w-]+%-([a-z%-]+)%-(%d+)")
|
||||||
shade = assert(tonumber(shade))
|
shade = assert(tonumber(shade))
|
||||||
|
Reference in New Issue
Block a user