Lumis Docs
Recipes

Line Highlighting

Highlight selected lines in Lumis for inline HTML, linked HTML, and CLI workflows.

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

In Rust, the npm package, Elixir and the CLI, every formatter takes the same lines. What differs is how it marks them, because each output format has a different thing to mark a line with. lumis4j does not expose line highlighting.

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
Terminala background colour, from background or the theme's highlighted style
BBCode Scopeda [highlighted] tag around the line

Terminal

A terminal has no class to hang a stylesheet off, so a highlighted line is painted with a background. Only the background is taken from the theme: a foreground would overwrite the colour every token on the line was already given. With neither a background nor a theme that styles highlighted, nothing marks the line.

use lumis::formatters::terminal::HighlightLines;
let highlight_lines = HighlightLines {
lines: vec![1..=1, 3..=4],
// Omit it to take the theme's `highlighted` background.
background: Some("#3a3a3a".to_string()),
};
terminal({language: javascript, theme: frappe, highlightLines: {lines: [1, [3, 4]]}});
{:terminal, theme: "catppuccin_frappe", highlight_lines: %{lines: [1, 3..4]}}
lumis highlight -f terminal -t catppuccin_frappe -H 1,3-4 main.rs
lumis highlight -f terminal -H 1,3-4 --highlight-lines-background '#3a3a3a' main.rs

BBCode Scoped

A highlighted line is wrapped in [highlighted]...[/highlighted], newline included, the way an HTML line sits inside its <div>. The tag is derived from the highlighted theme scope exactly as every other tag this formatter emits is derived from a scope, so there is nothing to configure; the consumer defines what [highlighted] looks like, as it already must for [keyword-rust].

lumis highlight -f bbcode-scoped -H 1,3-4 main.rs

Without highlight_lines these two formatters emit exactly what they did before. Neither carries line structure of its own, so lines only enter the stream when there is a line to mark — which is also why a scope spanning a newline is closed and reopened once you ask for highlighting, and not before.

On this page