Skip to main content

Line Highlighting

Line highlighting lets you emphasize key lines without changing the rest of the block.

Common patterns

  • highlight a few exact lines
  • highlight a range such as 3..5
  • use theme styling or your own CSS class / inline style

Examples

import {highlight} from '@lumis-sh/lumis';
import {htmlInline} from '@lumis-sh/lumis/formatters';
import javascript from '@lumis-sh/lumis/langs/javascript';
import dracula from '@lumis-sh/themes/dracula';
const html = await highlight(
'line 1\nline 2\nline 3\nline 4',
htmlInline({
language: javascript,
theme: dracula,
highlightLines: {lines: [1, [3, 4]], style: 'theme'},
})
);

For linked HTML, use htmlLinked({ highlightLines: { lines: [1, [3, 4]], class: 'active-line' } }).

Custom style example

import {highlight} from '@lumis-sh/lumis';
import {htmlInline} from '@lumis-sh/lumis/formatters';
import javascript from '@lumis-sh/lumis/langs/javascript';
import dracula from '@lumis-sh/themes/dracula';
const html = await highlight(
'line 1\nline 2\nline 3\nline 4',
htmlInline({
language: javascript,
theme: dracula,
highlightLines: {
lines: [2, [4, 4]],
style: 'background-color: rgba(255, 221, 87, 0.18); border-left: 3px solid #ffd54f;',
},
})
);

What changes between formatters

FormatterHighlight style
HTML Inlinetheme style or custom inline CSS
HTML LinkedCSS class names
HTML Multi-Themestheme style or custom inline CSS
Terminalno line highlight styling
BBCode Scopedno line highlight styling