The module asciidoc-java implements a light Asciidoc syntax parser in plain Java. It aims at making it easier and lighter than using JRuby to embed Asciidoc in any Java based (native or not) application.

Its usage is pretty simple:

  1. You get a Parser instance to load the model of your document in memory (AST),

  2. You visit the model as you want (or reusing provided Visitor<?>) to render the loaded Document.

TIP

the Document instance is thread safe and can safely be reused accross multiple threads. The parser is also thread save but the visitors must be created per rendering instance.

Here is a basic example:

final var parser = new Parser(); (1)
final var doc = parser.parse(myDocContent, new Parser.ParserContext(ContextResolver.of(Path.of("asciidoc/content")))); (2)
final var renderer = new AsciidoctorLikeHtmlRenderer(); (3)
renderer.visit(doc); (4)
final var html = renderer.result(); (5)
  1. Create a parser instance, can be a singleton in an application,
  2. Load the document model, can also be a singleton in an application when the conditions depends on attributes,
  3. Create a renderer (here a html renderer, optionally you can pass it attributes using the other constructor),
  4. Visit the document,
  5. Get back the output of the renderer (html output here).
IMPORTANT
the asciidoc syntax is not 100% implemented yet, if you encounter anything you miss, feel free to open an issue or pull request on our bugtracker.