Examples
Here you will find simple but complete examples of how to convert documents using the different configuration options available. The examples cover the main scenarios, but you can mix and match usage of instances, builders and maps freely to suite yous needs.
Setting attributes and options as Map collections
Asciidoctor asciidoctor = Asciidoctor.Factory.create(); (1)
Map<String, Object> attributes = AttributesBuilder.
.attributes()
.backend("docbook")
.icons("font")
.asMap(); (2)
Map<String, Object> options = OptionsBuilder
.options()
.inPlace(true)
.attributes(attributes) (3)
.asMap(); (4)
String outfile = asciidoctor.convertFile(new File("sample.adoc"), options); (5)
1 | Create Asciidoctor instance. |
2 | Defines attributes using builder fluent API and retrieves them as Map . |
3 | Registers the attributes map as attributes . |
4 | Converts options to java.util.Map instance. |
Setting attributes and options as instances
Asciidoctor asciidoctor = Asciidoctor.Factory.create(); (1)
Attributes attributes = AttributesBuilder.
.attributes()
.backend("docbook")
.icons("font")
.get(); (2)
Options options = OptionsBuilder
.options()
.inPlace(true)
.attributes(attributes)
.get(); (3)
String outfile = asciidoctor.convertFile(new File("sample.adoc"), options); (4)
1 | Create Asciidoctor instance. |
2 | Defines the attributes as an Attributes class instead of java.util.Map by calling get() . |
3 | Defines the options as an Options class instead of java.util.Map by calling get() . |
4 | Converts the document passing Options instance. |
All methods used to convert content are overloaded with OptionsBuilder parameter.
It is no longer required to call get nor asMap methods.
|
The icons attribute requires a String to set the value used to "draw" icons.
At this time, you can use two constants org.asciidoctor.Attributes.IMAGE_ICONS for using the same approach as AsciiDoc, that is using img tags, or org.asciidoctor.Attributes.FONT_ICONS for using icons from Font Awesome.
|
Setting attributes and options as builders
Asciidoctor asciidoctor = Asciidoctor.Factory.create(); (1)
AttributesBuilder attributes = AttributesBuilder.
.attributes()
.backend("docbook")
.icons("font"); (2)
OptionsBuilder options = OptionsBuilder
.options()
.inPlace(true)
.attributes(attributes); (3)
String outfile = asciidoctor.convertFile(new File("sample.adoc"), options); (4)
1 | Create Asciidoctor instance. |
2 | Defines the attributes as an AttributesBuilder by not using get() or `asMap(). |
3 | Defines the options as an OptionsBuilder by not using get() or `asMap(). |
4 | Converts the document passing OptionsBuilder instance. |