1

我不得不承认我是 AsciiDoc 和 ASciiDoctor 的新手......

我想要完成的是用 groovy 呈现给定的 AsciiDoc 模板(https://github.com/masch70/arc42-template-asciidoc)。我的解决方案是使用 AsciiDoctor Java 接口,它似乎是对运行 jRuby 的 AsciiDoc 的重写。到目前为止,代码运行良好:

@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,
])

但它似乎忽略了对我来说看起来不错的包含部分:

include::sections/02_architecture_constraints.ad[]

不是包含文件,而是呈现文件的链接。

AsciiDoctor 手册说支持包含:http ://asciidoctor.org/docs/user-manual/#include-directive ,所以问题是,我做错了什么?

4

2 回答 2

2

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.

于 2014-02-10T23:26:47.357 回答
1

我建议你试试asciidoctor gradle 插件

于 2014-06-05T14:32:06.840 回答