Installation
Usage
Add the text color extension to your editor:API Reference
defineTextColor()
Defines thetextColor mark and commands for adding and removing text color.
Returns: TextColorExtension
Commands
addTextColor
Applies a text color to the current selection or at the cursor position.attrs: TextColorAttrs- Object with acolorpropertycolor: string- Any valid CSS color value (hex, rgb, rgba, color name, etc.)
removeTextColor
Removes text color formatting from the current selection.TypeScript Types
TextColorAttrs
Attributes for thetextColor mark.
HTML Output
Text color is rendered as<span> elements with both inline styles and data attributes:
Parsing
The extension recognizes elements with:style="color: [value]"attributedata-text-color="[value]"attribute (takes priority)
The extension uses
data-text-color attribute to preserve exact color values, avoiding browser conversion of hex colors to rgba format."inherit" are ignored during parsing.
Example: Color Picker Integration
Here’s an example of integrating a color picker:Supported Color Formats
The extension accepts any valid CSS color value:- Hex:
#ff0000,#f00 - RGB:
rgb(255, 0, 0) - RGBA:
rgba(255, 0, 0, 0.5) - HSL:
hsl(0, 100%, 50%) - Named colors:
red,blue, etc.
Advanced Configuration
If you need more control, you can use the individual components:Related Extensions
- Background Color - Background color formatting
- Bold - Bold text formatting
- Italic - Italic text formatting