Module colorizer.parser.rgb
This module provides a parser for identifying and converting `rgb()` and `rgba()` CSS functions to RGB hexadecimal format.
It supports decimal and percentage values for RGB channels, as well as an optional alpha (transparency) component. The function can interpret a variety of CSS syntax variations, making it useful for syntax highlighting or color parsing.
Functions
rgb_function_parser (line, i, opts) | Parses `rgb()` and `rgba()` CSS functions and converts them to RGB hexadecimal format. |
Functions
- rgb_function_parser (line, i, opts)
-
Parses `rgb()` and `rgba()` CSS functions and converts them to RGB hexadecimal format.
This function matches `rgb()` or `rgba()` functions in a line of text, extracting RGB and optional alpha values.
It supports decimal and percentage formats, alpha transparency, and comma or space-separated CSS syntax.
Parameters:
- line string The line of text to parse for the color function
- i number The starting index within the line where parsing should begin
- opts table Parsing options, including: - `prefix` (string): "rgb" or "rgba" to specify the CSS function type
Returns:
- number|nil The end index of the parsed `rgb/rgba` function within the line, or `nil` if parsing failed
- string|nil The RGB hexadecimal color (e.g., "ff0000" for red), or `nil` if parsing failed