Module colorizer.parser.names
Names Parser This module provides a parser that identifies named colors from a given line of text.
It uses a Trie structure for efficient prefix-based matching of color names to #rrggbb values. The module supports multiple namespaces, enabling flexible configuration and handling of different types of color names (e.g., lowercase, uppercase, camelcase, custom names, Tailwind names).
Namespaces: lowercase: Contains color names converted to lowercase (e.g., "red" -> "#ff0000"). uppercase: Contains color names converted to uppercase (e.g., "RED" -> "#ff0000"). camelcase: Contains color names in camel case (e.g., "LightBlue" -> "#add8e6"). tailwindnames: Contains color names based on TailwindCSS conventions, including prefixes. namescustom: Contains user-defined color names, either as a table or a function returning a table.
The parser dynamically populates the Trie and namespaces based on the provided options. Unused namespaces are left empty, avoiding unnecessary memory usage. Color name matching respects the configured namespaces and user-defined preferences, such as whether to strip digits.
Functions
| lookup_name (name, m_opts) | Look up a color name and return its hex (for use by other parsers e.g. |
| parser (line, i, m_opts) | Parses a line to identify color names. |
| reset_cache () | Reset the color names cache. |
| update_color (name, hex, namespace) | Updates the color value for a given color name. |
Tables
| spec | Parser spec for the registry |
Functions
- lookup_name (name, m_opts)
- Look up a color name and return its hex (for use by other parsers e.g. xcolor).
- parser (line, i, m_opts)
- Parses a line to identify color names.
- reset_cache ()
- Reset the color names cache. Called from colorizer.setup
- update_color (name, hex, namespace)
- Updates the color value for a given color name.