1. Resources
  2. Markdown
  3. Extensions

Extensions

Extensions are how you turn on optional syntax and renderer behavior.

This repository ships these built-in extensions:

  • Autolink
  • Strikethrough
  • GFM tables
  • Task list items
  • Optional Markdown class styling extensions

Extension Basics

An extension can contribute to one or more of these areas:

  • Parser behavior
  • AST post-processing
  • HTML rendering
  • Elemental2 DOM rendering
  • Plain-text rendering
  • Markdown rendering

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.

Simple Registration

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();

Bundled Discovery

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.

Basic Example

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

Strikethrough supports ~text~ or ~~text~~ depending on configuration.

Default Behavior

Extension extension = StrikethroughExtension.create();

Requiring Two Tildes

Extension extension = StrikethroughExtension.builder()
    .requireTwoTildes(true)
    .build();

That mode rejects single-tilde strikethrough and only accepts double-tilde markers.

Tables

Tables use GitHub-style pipe table syntax.

Basic Example

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

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.

Combining Extensions

Extensions are additive.

Set<Extension> extensions =
    Set.of(
        AutolinkExtension.create(),
        StrikethroughExtension.create(),
        TablesExtension.create(),
        TaskListItemsExtension.create());

You can register the same set on:

  • The parser
  • The HTML renderer
  • The Elemental2 renderer
  • The plain-text renderer
  • The Markdown renderer

Extension Behavior By Renderer

Not every extension affects every renderer in the same way.

Examples:

  • Autolink changes parsing and therefore affects all renderers through the AST
  • Strikethrough has parser and renderer hooks
  • Tables have parser and renderer hooks
  • Task lists have post-processing plus renderer hooks

Practical Advice

  • Register extensions on the parser first, then on the renderers that need them.
  • Use ExtensionDiscovery.load() when you want the built-in set without manually listing each extension.
  • Use builder APIs when you need to tune extension behavior.

Class Styling

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.

We are a group of passionate people who love what we do

Donate & Support Us