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 frappe from '@lumis-sh/themes/catppuccin_frappe';
const html = await highlight(
'line 1\nline 2\nline 3\nline 4',
htmlInline({
language: javascript,
theme: frappe,
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 frappe from '@lumis-sh/themes/catppuccin_frappe';
const html = await highlight(
'line 1\nline 2\nline 3\nline 4',
htmlInline({
language: javascript,
theme: frappe,
highlightLines: {
lines: [2, [4, 4]],
style: 'background-color: rgba(255, 221, 87, 0.18); border-left: 3px solid #ffd54f;',
},
})
);

Class without an inline style

Omitting the style uses the theme's highlighted style. To highlight by class alone, so a stylesheet or a utility framework owns the appearance, opt out of the inline style explicitly:

htmlInline({
language: javascript,
theme: frappe,
highlightLines: {lines: [2], style: null, class: 'bg-yellow-500'},
})

null opts out; leaving style off entirely still uses the theme.

What changes between formatters

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