Skip to main content

HTML Inline Formatter

Self-contained HTML with inline styles on each token. No external CSS required.

Options

RuntimeOptions
Rustlanguage, theme, pre_class, italic, include_highlights, highlight_lines, header
Elixirlanguage, theme, pre_class, italic, include_highlights, highlight_lines, header
JavaScriptlanguage, theme, preClass, italic, includeHighlights, highlightLines, header
JavawithLang(), withTheme(), withFormatter(Formatter.HTML_INLINE)
CLI--theme, --highlight-lines

Basic example

import {highlight} from '@lumis-sh/lumis'
import {htmlInline} from '@lumis-sh/lumis/formatters'
import rust from '@lumis-sh/lumis/langs/rust'
import dracula from '@lumis-sh/themes/dracula'
const html = await highlight('fn main() {}', htmlInline({language: rust, theme: dracula}))

Add classes and metadata

const html = await highlight(
'const x = 1',
htmlInline({language: javascript, theme: dracula, preClass: 'code-block', includeHighlights: true})
)

Wrap with custom HTML

const html = await highlight(
'const x = 1',
htmlInline({
language: javascript,
theme: dracula,
header: {openTag: '<figure><figcaption>index.js</figcaption>', closeTag: '</figure>'},
})
)

Output format

HTML Inline emits the full block structure with inline styles on each token:

<pre class="lumis" style="background-color: #282c34; color: #abb2bf;">
<code class="language-rust" translate="no" tabindex="0">
<div class="line" data-line="1">
<span style="color: #e5c07b;">fn</span>
<span style="color: #61afef;">main</span>
</div>
</code>
</pre>
  • <pre class="lumis"> is the outer wrapper and carries the block background
  • <code class="language-*"> identifies the language and keeps the block focusable
  • <div class="line" data-line="N"> wraps each line
  • <span style="..."> carries the token colors and font styles inline

When to use it

  • self-contained HTML
  • email / CMS / markdown export
  • no external stylesheet pipeline