Extensions are how you turn on optional syntax and renderer behavior.
This repository ships these built-in extensions:
An extension can contribute to one or more of these areas:
Most applications just reuse the built-in extension factories and register them on the parser and renderers they use.
If you are only installing one extension, you can use withExtension(...) instead of building a collection. If you are installing a few extensions inline, withExtensions(...) is the varargs convenience form.
Set<Extension> extensions =
Set.of(
AutolinkExtension.create(),
StrikethroughExtension.create(),
TablesExtension.create(),
TaskListItemsExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
HtmlRenderer htmlRenderer = HtmlRenderer.builder().extensions(extensions).build();
Elemental2Renderer domRenderer = Elemental2Renderer.builder().extensions(extensions).build();
TextContentRenderer textRenderer = TextContentRenderer.builder().extensions(extensions).build();
MarkdownRenderer markdownRenderer = MarkdownRenderer.builder().extensions(extensions).build();
If you want the built-in extension set in one call, use:
List<Extension> extensions = ExtensionDiscovery.load();
That returns the bundled engine extensions in deterministic order.
Autolink turns bare URLs and email-like text into normal link nodes.
Extension extension = AutolinkExtension.create();
Parser parser = Parser.builder()
.extensions(List.of(extension))
.build();
Extension extension = AutolinkExtension.builder()
.linkTypes(AutolinkType.URL)
.build();
You can also pass a set:
Extension extension = AutolinkExtension.builder()
.linkTypes(EnumSet.of(AutolinkType.URL, AutolinkType.EMAIL))
.build();
Strikethrough supports ~text~ or ~~text~~ depending on configuration.
Extension extension = StrikethroughExtension.create();
Extension extension = StrikethroughExtension.builder()
.requireTwoTildes(true)
.build();
That mode rejects single-tilde strikethrough and only accepts double-tilde markers.
Tables use GitHub-style pipe table syntax.
Extension extension = TablesExtension.create();
Once enabled, pipe tables can be parsed and rendered through the supported output formats.
Example input:
| Name | Role |
| --- | --- |
| Ada | Engineer |
| Lin | Writer |
Task list items recognize checklist-style list syntax.
Example input:
- [ ] Open issue
- [x] Ship fix
Enabling the extension makes the parser rewrite those list items into task-aware AST nodes so the renderers can emit the correct checkbox output.
Extensions are additive.
Set<Extension> extensions =
Set.of(
AutolinkExtension.create(),
StrikethroughExtension.create(),
TablesExtension.create(),
TaskListItemsExtension.create());
You can register the same set on:
Not every extension affects every renderer in the same way.
Examples:
ExtensionDiscovery.load() when you want the built-in set without manually listing each extension.If you want predictable CSS hooks on rendered Markdown, install the optional class extension on the renderers you use:
List<Extension> extensions = List.of(new DuiClassExtension());
Parser parser = Parser.builder()
.extensions(extensions)
.build();
HtmlRenderer htmlRenderer = HtmlRenderer.builder()
.extensions(extensions)
.build();
Elemental2Renderer domRenderer = Elemental2Renderer.builder()
.extensions(extensions)
.build();
This is opt-in. The default parser and renderers do not add these classes unless you install the extension yourself.