Customize
Decorations
Add source ranges and line wrappers to highlighted HTML.
Add classes to source ranges without touching syntax tokens. Optionally wrap each line for line numbers or annotations.
Example
import { tokenize } from 'kirari'
import { renderDecorated } from 'kirari/decorations'
const source = 'const answer = 42\nconsole.log(answer)'
const html = renderDecorated(tokenize(source), {
decorations: [
{ start: 6, end: 12, className: 'kirari-inserted' },
],
lines: true,
})
Output: the first answer gets the inserted color; syntax colors stay.
Example
const answer = 42
console.log(answer)
- Ranges: UTF-16 offsets,
startinclusive,endexclusive. Overlaps combine classes. lines: truewraps each line in.kirari-linewith a 1-baseddata-line. Line endings stay outside.lineClassName({ number, start, end })adds a class per line.
Pass tokens that cover the whole source. Ranges must be nonempty, in bounds, and not split a surrogate pair. A range edge inside a CRLF needs lines: true. Output is escaped.