Skip to content

A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.



Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Asciidoctor Extensions Lab

This repository is a lab for experimenting with Ruby-based Asciidoctor extensions using the Extensions API. Please do not use this code in production. The code is untested. It is also not packaged and distributed. The purpose of these examples is to demonstrate how extensions are set up, how to write them, and what they can do. The examples also offer patterns that can be reused when implementing your own extension.

In order to use the extensions in this repository, you need to clone the repository. Then, you need to pass the location of the extension you want to use to Asciidoctor using the -r CLI option or require it in your Ruby script if you are using the Asciidoctor API.

If you only want to test the extensions in this repository, skip ahead to Using an extension.

If you want to use one of the extensions from this lab in production, and perhaps develop it further, please import it into a new project and distribute it as a RubyGem. If you’re prepared to maintain it for the community, you can submit a request in the project chat to graduate it a top-level project in the Asciidoctor organization. When writing your own extension, we recommend that you study the extensions section in the Asciidoctor documentation.

Extension types

We have the following types of extensions in the lab:

  • Preprocessor - processes the AsciiDoc source before it is parsed

  • IncludeProcessor - intercepts the AsciiDoc include directive

  • TreeProcessor - processes the AsciiDoc document (AST) after block-level parsing is complete

  • Postprocessor - processes the converted output before it is written to the output stream (or disk)

  • DocinfoProcessor - contributes additional content to the header or footer of the output document

  • BlockProcessor - adds a custom delimited block

  • BlockMacroProcessor - adds a custom block macro

  • InlineMacroProcessor - adds a custom inline macro

The type of extension (e.g, -block-macro) is always used in the name of the extension registration file and directory to make it easy to distinguish. You can also look for examples using git grep. For example, to look for a BlockMacroProcessor, run the following command:

$ git grep BlockMacroProcessor lib/

You’ll get a result like this:

lib/gist-block-macro/extension.rb:class GistBlockMacro < Extensions::BlockMacroProcessor
lib/pass-block-macro/extension.rb:class PassBlockMacro < Extensions::BlockMacroProcessor
lib/tree-block-macro/extension.rb:class TreeBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor

Extension files

Each extension consists of several files:

  • A file that registers the extension (sometimes also contains the extension)

  • A file with the extension itself (when not defined in the registration file)

  • A file with sample AsciiDoc source to use to test the extension

  • Auxiliary assets needed by the extension

For example, the emoji-inline-macro extension has four files:

The registration file (e.g., emoji-inline-macro.rb) goes in the lib directory whereas the remaining files go inside a directory whose base name matches the name of the registration file (e.g., emoji-inline-macro).

Extension catalog

The following extensions are available in the lab.

AutoXrefTreeprocessor, lib/autoxref-treeprocessor.rb

Refers images, tables, listings, sections by their numbers.

BackToTopDocinfoProcessor, lib/back-to-top-docinfo-processor.rb

Adds a floating back to top button to the bottom right corner of the page.

ChartBlockMacro, lib/chart-block-macro.rb

Adds a chart block and block macro to AsciiDoc powered by c3js, chartist or chartjs. Replaced by Asciidoctor Chart.

ChromeInlineMacro, lib/chrome-inline-macro.rb

Adds an inline macro for linking to a chrome:// URI.

CopyToClipboardDocinfoProcessor, lib/copy-to-clipboard-docinfo-processor.rb

Adds a source toolbox with a copy to clipboard button to all source blocks.

CopyrightFooterPostprocessor, lib/copyright-footer-postprocessor.rb

Adds a copyright to the document footer based on the value of the copyright attribute.

CustomAdmonitionBlock, lib/custom-admonition-block.rb

Introduces a new admonition block type, complete with a custom icon.

DocstatInlineMacro, lib/docstat-inline-macro.rb

A macro that displays the word count and estimated reading time of the current document.

DumpAttributesBlockMacro, lib/dump-attributes-block-macro.rb

Dumps the document attributes as attribute entries in a source block.

EmojiInlineMacro, lib/emoji-inline-macro.rb

Adds an emoji inline macro for inserting emoji by name.

EnableSourcemapPreprocessor, lib/enable-sourcemap-preprocessor.rb

Specifies sourcemap attribute for document.

ExternalHeaderAttributesPreprocessor, lib/external-header-attributes-preprocessor.rb

Reads additional AsciiDoc attributes from a YAML-based configuration file and adds them to the document header.

FoldLinesTreeProcessor, lib/fold-lines-tree-processor.rb

Replaces newlines (i.e., line feeds) in paragraphs with a single space.

FootnotesBlockMacro, lib/footnotes-block-macro.rb

Consumes the footnotes from the document catalog and puts them into a dedicated section.

FrontMatterPreprocessor, lib/front-matter-preprocessor.rb

Emulates the built-in behavior of Asciidoctor to sweep away YAML front matter into the front-matter attribute.

GitMetadataInlineMacro, lib/git-metadata-inline-macro.rb

Provide information on references using a macro (e.g. commits, branches and tags).

GitMetadataPreprocessor, lib/git-metadata-preprocessor.rb

Provide information on the local git repository, e.g. the branch or tag name or the commit id.

GistBlockMacro, lib/gist-block-macro.rb

Adds a block macro to embed a gist into an AsciiDoc document.

GlobIncludeProcessor, lib/glob-include-processor.rb

Enhances the include directive to support a glob expression to include all matching files.

GoogleAnalyticsDocinfoProcessor, lib/google-analytics-docinfoprocessor.rb

Adds the Google Analytics code for the account identified by the google-analytics-account attribute to the bottom of the HTML document.

HardbreaksPreprocessor, lib/hardbreaks-preprocessor.rb

Adds hardbreaks to the end of all non-empty lines that aren’t section titles.

HighlightTreeprocessor, lib/highlight-treeprocessor.rb

Highlights source blocks using the highlight command.

ImplicitApidocInlineMacro, lib/implicit-apidoc-inline-macro.rb

Adds an inline macro for linking to the Javadoc of a class in the Java EE API.

ImplicitHeaderIncludeProcessor, lib/implicit-header-include-processor.rb

Skips the implicit author line below the document title in included documents.

LicenseUrlDocinfoProcessor, lib/license-url-docinfoprocessor.rb

Adds a link to the license specified by the license attribute to the document header.

LoremBlockMacro, lib/lorem-block-macro.rb

Generates lorem ipsum text using the Middleman lorem extension. (Requires middleman >= 4.0.0).

ManInlineMacro, lib/man-inline-macro.rb

Adds an inline macro for linking to another man page (used in the Git documentation).

MathematicalTreeprocessor, lib/mathematical-treeprocessor.rb

Converts all latexmath blocks to SVG using the Mathematical library. Replaced by Asciidoctor Mathematical.

MarkdownLinkInlineMacro, lib/markdown-link-inline-macro.rb

Parses a Markdown-style link.

MentionsInlineMacro, lib/mentions-inline-macro.rb

Detects Twitter-style username mentions and converts them to links.

MultipageHtml5Converter, lib/multipage-html5-converter.rb

A converter that chunks the HTML5 output into multiple pages. This extension is merely a proof of concept. You can find a complete implementation of a multipage HTML converter at

MultirowTableHeaderTreeProcessor, lib/multirow-table-header-tree-processor.rb

Promotes additional rows from the table body to the table head(er). Number of header rows is controlled by the hrows attribute on the table block.

NestedOpenBlock, lib/nested-open-block.rb

Allows open blocks to be nested by repurposing the example container as an open block.

NumberParagraphsTreeProcessor, lib/number-paragraphs-tree-processor.rb

Naively numbers paragraphs based on position.

PassBlockMacro, lib/pass-block-macro.rb

Adds a pass block macro to AsciiDoc.

PickInlineMacro, lib/pick-inline-macro.rb

Adds an inline macro for selecting between two values based on the value of another attribute.

PullquoteInlineMacro, lib/pullquote-inline-macro.rb

Adds an inline macro to pull a quote out of the flow and display it in a sidebar.

RubyAttributesPreprocessor, lib/ruby-attributes-preprocessor.rb

Makes information about the Ruby runtime available to the document by defining document attributes for all constants that begin with RUBY_ (e.g, ruby-version).

SectnumoffsetTreeprocessor, lib/sectnumoffset-treeprocessor.rb

Increments all level-1 section numbers (and subsequently all subsections) by the value of the sectnumoffset attribute.

ShellSessionTreeProcessor, lib/shell-session-treeprocessor.rb

Detects a shell command and trailing output and styles it for display in HTML.

ShoutBlock, lib/shout-block.rb

Converts all text inside a delimited block named shout to uppercase and adds trailing exclamation marks.

ShowCommentsPreprocessor, lib/showcomments-preprocessor.rb

Converts line comments to visual elements (normally dropped).

SlimBlock, lib/slim-block.rb

Passes the content in blocks named slim to the Slim template engine for processing.

StepsPostprocessor, lib/steps-postprocessor.rb

Styles an ordered list as a procedure list.

TelInlineMacro, lib/tel-inline-macro.rb

Adds an inline macro for linking to a tel: URI.

TermInlineMacro, lib/term-inline-macro.rb

Demonstrates how to convert an inline macro into a span of text with a role.

TexPreprocessor, lib/tex-preprocessor.rb

Interprets tex markup embedded inside of AsciiDoc.

TextqlBlock, lib/textql-block.rb

Adds a block for using textql to process data in an AsciiDoc document.

TreeBlockMacro, lib/tree-block-macro.rb

Adds a block macro to show the output of the tree command.

UndoReplacementsPostprocessor, lib/undo-replacements-postprocessor.rb

Reverses the text replacements that are performed by Asciidoctor.

UriIncludeProcessor, lib/uri-include-processor.rb

Emulates the built-in behavior of Asciidoctor to include content from a URI.

ViewResultDocinfoProcessor, lib/view-result-docinfoprocessor.rb

Adds an interactive toggle to block content marked as a view result.

WhitespaceIncludeProcessor, lib/whitespace-include-processor.rb

An include processor that substitutes tabs with spaces (naively) in included source code.

XmlEntityPostprocessor, lib/xml-entity-postprocessor.rb

Converts named entities to character entities so they can be resolved without the use of external entity declarations.

Using an extension

Before creating your own extensions, it would be wise to run one yourself. First, make sure Asciidoctor is installed:

$ gem install asciidoctor

Next, run the extension from the root directory of the project:

$ asciidoctor -r lib/emoji-inline-macro.rb lib/emoji-inline-macro/sample.adoc
# asciidoctor: FAILED: 'lib/emoji-inline-macro.rb' could not be loaded
# Use --trace for backtrace

Oops! We forgot to include the leading ./ when using the -r flag Let’s try again:

$ asciidoctor -r ./lib/emoji-inline-macro.rb lib/emoji-inline-macro/sample.adoc

All right, it ran! The output file, sample.html, was created in the same directory as the source file, sample.adoc.

The relevant bits of the input and output are shown below.

Faster than a emoji:turtle[1x]!

This is an example of how you can emoji:heart[lg] Asciidoctor and Twitter Emoji.
<div class="paragraph">
<p>Faster than a <i class="twa twa-1x twa-turtle"></i>!</p>
<div class="paragraph">
<p>This is an example of how you can <i class="twa twa-lg twa-heart"></i> Asciidoctor and Twitter Emoji.</p>
Certain extensions require additional libraries. Please consult the extension’s registration file for details about what is required to use it.

Adding an extension

You can find examples of various ways to define an extension in the lib/shout-block.rb extension.

Shorthand (DSL)

If you’re creating a trivial extension, you can define the extension using the extension DSL directly in the registration file. Create a new file in the lib directory. Include the extension type in the name of the file so others are clear what type of extension it is.

Asciidoctor::Extensions.register do
  block do
    named :sample
    on_context :open

    process do |parent, reader, attrs|
      create_paragraph parent, reader.lines, attrs


If you’re creating a more complex extension or want to enable reuse, you’re encouraged to move the extension code to the extension.rb inside a directory with the same base name as the registration file. In the case of a block, block macro or inline macro, this enables you to register the extension multiple times.

RUBY_ENGINE == 'opal' ? (require 'sample-block/extension') : (require_relative 'sample-block/extension')

Asciidoctor::Extensions.register do
  block SampleBlock
class SampleBlock < Asciidoctor::Extensions::BlockProcessor
  named :sample
  on_context :open

  def process parent, reader, attrs
    create_paragraph parent, reader.lines, attrs

It’s customary to provide a sample AsciiDoc file named sample.adoc inside the extension subdirectory that others can use to try the extension. You should also add your extension to the Extension catalog section along with a short description of what it does.

Other extensions

See this list of official and community extensions for Asciidoctor.

You may also be interested in these extensions which were submitted, but never merged:

Copyright © 2014-present The Asciidoctor Project. Free use of this software is granted under the terms of the MIT License.

See the LICENSE file for details.


A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.



Code of conduct