HTML Inline Formatter
Self-contained HTML with inline styles on each token. No external CSS required.
Options
| Runtime | Options |
|---|---|
| Rust | language, theme, pre_class, italic, include_highlights, highlight_lines, header |
| Elixir | language, theme, pre_class, italic, include_highlights, highlight_lines, header |
| JavaScript | language, theme, preClass, italic, includeHighlights, highlightLines, header |
| Java | withLang(), withTheme(), withFormatter(Formatter.HTML_INLINE) |
| CLI | --theme, --highlight-lines |
Basic example
- JavaScript
- Rust
- Elixir
- Java
- CLI
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}))
use lumis::{highlight, HtmlInlineBuilder, languages::Language, themes};
let html = highlight(
"fn main() {}",
HtmlInlineBuilder::new()
.language(Language::Rust)
.theme(Some(themes::get("dracula").unwrap()))
.build()
.unwrap(),
);
Lumis.highlight!(
"fn main() {}",
formatter: {:html_inline, language: "rust", theme: "dracula"}
)
import io.roastedroot.lumis4j.core.Formatter;
import io.roastedroot.lumis4j.core.Lang;
import io.roastedroot.lumis4j.core.Lumis;
import io.roastedroot.lumis4j.core.Theme;
var lumis = Lumis.builder().build();
var highlighter = lumis.highlighter()
.withLang(Lang.RUST)
.withTheme(Theme.DRACULA)
.withFormatter(Formatter.HTML_INLINE)
.build();
var html = highlighter.highlight("fn main() {}").string();
lumis.close();
lumis highlight main.rs --formatter html-inline --theme dracula
Add classes and metadata
- JavaScript
- Rust
- Elixir
- Java
- CLI
const html = await highlight(
'const x = 1',
htmlInline({language: javascript, theme: dracula, preClass: 'code-block', includeHighlights: true})
)
let formatter = HtmlInlineBuilder::new()
.language(Language::Javascript)
.theme(Some(themes::get("dracula").unwrap()))
.pre_class(Some("code-block".to_string()))
.include_highlights(true)
.build()
.unwrap();
let html = highlight("const x = 1", formatter);
Lumis.highlight!(
"const x = 1",
formatter: {:html_inline, language: "javascript", theme: "dracula", pre_class: "code-block", include_highlights: true}
)
lumis4j does not currently expose preClass or includeHighlights for HTML Inline output.
The CLI does not expose preClass or includeHighlights for HTML Inline output.
Wrap with custom HTML
- JavaScript
- Rust
- Elixir
- Java
- CLI
const html = await highlight(
'const x = 1',
htmlInline({
language: javascript,
theme: dracula,
header: {openTag: '<figure><figcaption>index.js</figcaption>', closeTag: '</figure>'},
})
)
use lumis::formatters::html::HtmlElement;
let formatter = HtmlInlineBuilder::new()
.language(Language::Javascript)
.theme(Some(themes::get("dracula").unwrap()))
.header(Some(HtmlElement {
open_tag: "<figure><figcaption>index.js</figcaption>".to_string(),
close_tag: "</figure>".to_string(),
}))
.build()
.unwrap();
let html = highlight("const x = 1", formatter);
Lumis.highlight!(
"const x = 1",
formatter: {:html_inline,
language: "javascript",
theme: "dracula",
header: %{open_tag: "<figure><figcaption>index.js</figcaption>", close_tag: "</figure>"}
}
)
Custom HTML wrappers are not currently exposed by lumis4j.
Custom HTML wrappers are not available in the CLI formatter.
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