Skip to main content

Highlight

This is the core Lumis workflow: choose a language, choose a formatter, then render output.

Simple 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(
'const x = 1',
htmlInline({language: javascript, theme: dracula})
);

Options by runtime

NeedCLIRustElixirJavaScriptJava
Set language--language.language(...)language: "..."language: ...withLang(...)
Set theme--theme.theme(...)theme: "..."theme: ...withTheme(...)
Choose output--formatterbuilder typeformatter: ...formatter factoryruntime-specific

Language detection

If you omit the language, Lumis tries to detect it using:

  • file extensions (.rs, .js, .ex, etc.)
  • filenames (Makefile, Dockerfile, Caddyfile)
  • shebangs (#!/usr/bin/env python)
  • Emacs mode lines (-*- mode: ruby -*-)

If detection fails, it falls back to plaintext.

Incomplete code

Lumis handles incomplete or malformed code without crashing. Tree-sitter produces a partial syntax tree and Lumis highlights what it can. This is useful for streaming scenarios where code arrives in chunks (e.g., LLM output).

Next steps