-- The MIT License (MIT) -- -- Copyright © 2026 Scott E. Graves -- -- Permission is hereby granted, free of charge, to any person obtaining a copy of this software -- and associated documentation files (the “Software”), to deal in the Software without restriction, -- including without limitation the rights to use, copy, modify, merge, publish, distribute, -- sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in all copies or -- substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -- BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- local hipatterns = require("mini.hipatterns") local color_group = function(_, match) local hex = match if #match == 4 or #match == 5 then local red, green, blue = match:sub(2, 2), match:sub(3, 3), match:sub(4, 4) hex = "#" .. red .. red .. green .. green .. blue .. blue end return hipatterns.compute_hex_color_group(hex:sub(1, 7), "bg") end local named_color_group = function(_, match) -- Match colorizer's default of accepting lower- and CamelCase names, but -- not names written entirely in uppercase. if #match > 1 and match == match:upper() then return nil end local ok, color = pcall(vim.api.nvim_get_color_by_name, match) if not ok or color < 0 then return nil end return hipatterns.compute_hex_color_group( string.format("#%06x", color), "bg" ) end hipatterns.setup( { highlighters = { hex_color = hipatterns.gen_highlighter.hex_color(), hex_short = { pattern = { "()#%x%x%x()%f[^%x]", "()#%x%x%x%x()%f[^%x]" }, group = color_group }, named_color = { pattern = "%f[%w]()[%a][%w]*()%f[^%w]", group = named_color_group } } } )