public static class TextUtils.DocumentBuilder extends Object
All settings have sensible defaults — the minimal usage is:
TextUtils.documentBuilder().markdown(text).build().
The generated document supports two independent CSS layers:
theme(Theme)) — controls the overall
page appearance: fonts, headings, tables, blockquotes, backgrounds. Choose
from BASIC, MODERN, or
GITHUB (each with a dark variant), or
NONE for unstyled HTML. Default: TextUtils.Theme.GITHUB.highlightTheme(SyntaxHighlighter.HighlightTheme))
— controls code block colors when syntaxHighlight(boolean) is
enabled. 77 themes are available (16 curated + 61 extended).
See SyntaxHighlighter.HighlightTheme for the full catalog.When no highlight theme is specified, one is auto-selected to match the
document theme's brightness: light documents get
GITHUB, dark documents get
GITHUB_DARK.
String html = TextUtils.documentBuilder()
.markdown(text)
.title("API Reference")
.theme(TextUtils.Theme.GITHUB_DARK)
.syntaxHighlight(true)
.highlightTheme(SyntaxHighlighter.HighlightTheme.NORD)
.autoDetectLanguage(true)
.build();
| Modifier and Type | Method and Description |
|---|---|
TextUtils.DocumentBuilder |
autoDetectLanguage(boolean b)
Enables or disables automatic language detection for code blocks that do
not have an explicit
language-xxx class (i.e. |
TextUtils.DocumentBuilder |
bodyClass(String cls)
CSS class on the
<article> wrapper. |
String |
build()
Builds the complete HTML document.
|
TextUtils.DocumentBuilder |
charset(String cs)
Sets the character encoding declared in
<meta charset>. |
TextUtils.DocumentBuilder |
cssFrom(URI uri)
|
TextUtils.DocumentBuilder |
cssFrom(URL url)
|
TextUtils.DocumentBuilder |
cssUrl(String url)
URL string for an external stylesheet (used when
inlineCss(boolean) is false). |
TextUtils.DocumentBuilder |
customCss(String css)
Additional CSS appended after the theme CSS (default: none).
|
TextUtils.DocumentBuilder |
disposeHighlighterAfterBuild(boolean b)
If
true, the highlighting engine is disposed after build()
completes, releasing approximately 200–300 KB of memory. |
TextUtils.DocumentBuilder |
escapeNonAscii(boolean b)
Controls whether non-ASCII characters in the rendered HTML body are
replaced with numeric HTML entities (
&#xNNNN;). |
TextUtils.DocumentBuilder |
highlightTheme(SyntaxHighlighter.HighlightTheme t)
Sets the CSS theme for syntax-highlighted code blocks.
|
TextUtils.DocumentBuilder |
inlineCss(boolean b)
If
true (default), embeds the theme CSS in a <style>
block. |
TextUtils.DocumentBuilder |
lang(String l)
Sets the
lang attribute on <html> (default:
"en"). |
TextUtils.DocumentBuilder |
markdown(String md)
Sets the Markdown source text to convert.
|
TextUtils.DocumentBuilder |
syntaxHighlight(boolean b)
Enables or disables server-side syntax highlighting of fenced code blocks.
|
TextUtils.DocumentBuilder |
syntaxHighlighter(SyntaxHighlighter hl)
Provides an existing
SyntaxHighlighter instance to reuse. |
TextUtils.DocumentBuilder |
theme(TextUtils.Theme t)
Sets the CSS theme (default:
TextUtils.Theme.GITHUB). |
TextUtils.DocumentBuilder |
title(String t)
Sets the HTML
<title> element (default: none). |
public TextUtils.DocumentBuilder markdown(String md)
md - The Markdown source text.public TextUtils.DocumentBuilder title(String t)
<title> element (default: none).t - Applies the title.public TextUtils.DocumentBuilder lang(String l)
lang attribute on <html> (default:
"en").l - Applies the language (code).public TextUtils.DocumentBuilder charset(String cs)
<meta charset>.cs - Applies the @code cs} as CharSet for Strings (default "UTF-8").public TextUtils.DocumentBuilder theme(TextUtils.Theme t)
TextUtils.Theme.GITHUB). Use
TextUtils.Theme.NONE for no CSS.t - Applies the Theme.public TextUtils.DocumentBuilder inlineCss(boolean b)
true (default), embeds the theme CSS in a <style>
block. If false, use cssUrl(String) to provide an
external stylesheet link.b - true to enable theme CSS (default: true).public TextUtils.DocumentBuilder customCss(String css)
css - The additional css or null for none.public TextUtils.DocumentBuilder cssUrl(String url)
inlineCss(boolean) is false).url - Applies the URL for an external CSS file.public TextUtils.DocumentBuilder cssFrom(URI uri)
uri - Applies the URI for an external CSS file.public TextUtils.DocumentBuilder cssFrom(URL url)
url - Applies the URL for an external CSS file.public TextUtils.DocumentBuilder bodyClass(String cls)
<article> wrapper.cls - Applies the body class, default: "markdown-body".public TextUtils.DocumentBuilder syntaxHighlight(boolean b)
When enabled, the SyntaxHighlighter engine is loaded on demand and
all <pre><code class="language-xxx"> blocks in the output are processed.
A suitable highlight CSS theme is included automatically (can be overridden
with highlightTheme(SyntaxHighlighter.HighlightTheme)).
b - true to enable syntax highlighting (default: false).public TextUtils.DocumentBuilder syntaxHighlighter(SyntaxHighlighter hl)
SyntaxHighlighter instance to reuse.
Implies syntaxHighlight(true).
The provided instance is not disposed after build() —
the caller retains ownership. This is efficient when rendering multiple
documents, as the engine is initialized only once.
hl - An existing highlighter instance, or null to create on demand.public TextUtils.DocumentBuilder highlightTheme(SyntaxHighlighter.HighlightTheme t)
Implies syntaxHighlight(true).
If not set, a theme matching the document's TextUtils.Theme brightness
is selected automatically.
t - The highlight theme, or null for automatic selection.public TextUtils.DocumentBuilder autoDetectLanguage(boolean b)
language-xxx class (i.e. bare
<pre><code> blocks produced by unfenced or unlabeled code in
Markdown).
Implies syntaxHighlight(true).
When enabled, the highlighter's
highlightAuto method is
used. Only results whose relevance score meets or exceeds
SyntaxHighlighter.AUTO_DETECT_MIN_RELEVANCE are applied; below
this threshold the code block is left as plain escaped text.
When disabled (false), bare code blocks are left entirely
untouched — only blocks with an explicit language class are
highlighted.
b - true to enable auto-detection (default: true).SyntaxHighlighter.highlightCodeBlocks(String,boolean),
SyntaxHighlighter.AUTO_DETECT_MIN_RELEVANCEpublic TextUtils.DocumentBuilder disposeHighlighterAfterBuild(boolean b)
true, the highlighting engine is disposed after build()
completes, releasing approximately 200–300 KB of memory.
This is the default behavior for one-off document generation. If you
are rendering many documents, set this to false to avoid repeated
engine initialization.
b - true to dispose after build (default: true).public TextUtils.DocumentBuilder escapeNonAscii(boolean b)
&#xNNNN;).
When enabled (the default), the output document is pure ASCII and
renders correctly regardless of the HTTP Content-Type charset
sent by the web server. This prevents mojibake when the server does not
include charset=UTF-8 in the response headers.
Disable this if the serving infrastructure guarantees UTF-8 encoding and you prefer smaller output without entity escaping.
b - true to escape non-ASCII (default: true).TextUtils.escapeNonAscii(String)public String build()
IllegalStateException - if the Markdown engine could not be initialized.Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.