I have to admit that I am new to AsciiDoc and ASciiDoctor...
What I am trying to accomplish is to render a given AsciiDoc template (https://github.com/masch70/arc42-template-asciidoc) with groovy. My solution is to make use of the AsciiDoctor Java Interface which seems to be a rewrite of AsciiDoc running with jRuby. The code runs fine so far:
@Grab('org.asciidoctor:asciidoctor-java-integration:0.1.4')
import org.asciidoctor.*
def asciidoctor = Asciidoctor.Factory.create()
def output = asciidoctor.renderFile(new File('index.ad'),[
'in_place':true,
'section-numbers':true,
'header_footer':true,
])
but it seems that it ignores the include sections which look pretty ok to me:
include::sections/02_architecture_constraints.ad[]
Instead of including the file, a link to the file gets rendered.
The AsciiDoctor manual says includes are supported: http://asciidoctor.org/docs/user-manual/#include-directive , so the question is, what am I doing wrong?
Add a safe
option as well. By default the safe
option for API is SECURE
or 20 (integer value) which disables include
directives to be rendered. You can use any of the below key-value pair:
'safe':'SAFE'
'safe': 1
'safe':'SERVER'
'safe': 10
'safe':'UNSAFE' //If you want
'safe': 0
Below should work.
def output = asciidoctor.renderFile(new File('index.ad'),[
'in_place':true,
'header_footer':true,
'safe':'SAFE'
])
Refer Running AsciiDoctor Securely for more details.
UPDATE
toc
and section numbers
are attributes in CLI, so we just need to add required attributes to options.
Simplest way:
def output = asciidoctor.renderFile(new File('index.ad'),[
'in_place':true,
'header_footer':true,
'safe':'SAFE',
'attributes': [toc: true, numbered: true] //I suppose
])
But the above tightly couples with the underlying ascii doc implementations which we wanted to abstract in the first place. Asciidoctor provides useful Builder patterns to overcome this clutter.
import static org.asciidoctor.AttributesBuilder.attributes
import static org.asciidoctor.OptionsBuilder.options
import org.asciidoctor.Placement
Attributes attributes = attributes().tableOfContents(true)
.tableOfContents2(Placement.LEFT)
.sectionNumbers(true)
.get()
Options options = options().inPlace(true)
.headerFooter(true)
.attributes(attributes)
.get()
def output = asciidoctor.renderFile(new File('index.ad'), options)
Visit this package from asciidoctor java integration and it will be pretty much clear as to how things can be tailored easily.