DyeLight’s character highlighting uses absolute positions across the entire text content. This approach simplifies highlighting compared to line-based systems, as you don’t need to calculate line numbers or offsets.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragaeeb/dyelight/llms.txt
Use this file to discover all available pages before exploring further.
How it works
Character highlights are defined bystart and end positions that count from the beginning of the text, treating the entire content as a single string. The start position is inclusive, while the end position is exclusive.
Multi-line spanning
One of the key benefits of absolute positioning is that highlights automatically span across line breaks without special handling. The newline character (\n) is simply another character in the sequence.
renderHighlightedLine function (from DyeLight.tsx:63) handles the complexity of splitting highlights across line boundaries internally, so you don’t need to worry about it.
Styling highlights
You can style highlights using either CSS classes or inline styles:Using CSS classes
Using inline styles
You can combine both
className and style on the same highlight. Inline styles will take precedence over class styles for any conflicting properties.Character range types
TheCharacterRange type defines the structure for highlights:
Overlapping highlights
When highlights overlap, DyeLight renders them in the order they appear in the array, with later highlights taking visual precedence. The component automatically handles overlaps by clamping ranges and skipping already-highlighted portions (seeDyeLight.tsx:85-119).
RTL text support
Character highlighting works seamlessly with right-to-left (RTL) text. Simply set thedir prop:
unicodeBidi styles (see DyeLight.tsx:12-18) to ensure highlights render correctly in both LTR and RTL contexts.