前言
- maven 3.5.0
- asciidoctor-maven-plugin 2.0.0-RC.1
- jdk 1.8
- eclipse 2019-09 R (4.13.0)
Asciidoc是个啥?
看着个介绍吧:https://my.oschina.net/gudaoxuri/blog/524132
怎么编辑Asciidoc
使用AsciidocFX编辑Asciidoc。https://github.com/asciidocfx/AsciidocFX
语法参考
https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/
怎么将Asciidoc转换成html、pdf或者…?
- 官方说,大多数Linux发行版都带有转换工具。如果你在用linux,那参考相关的手册即可。
- 用windows的话,图形化的工具可以参考。AsciidocFX就不错。
- windows下想用命令行转换的话,可以使用asciidoctor(https://asciidoctor.org)。asciidoctor是ruby开发的,安装ruby后,可以起飞。
- 如果熟练maven的话,用maven也可以在windows下进行转换。asciidoctor提供了maven的插件asciidoctor-maven-plugin。
asciidoctor-maven-plugin的使用
asciidoctor官方git地址:https://github.com/asciidoctor/asciidoctor-maven-plugin
asciidoctor示例:https://github.com/asciidoctor/asciidoctor-maven-examples
有啥不明白的,参考一下示例吧。
给个测试过的示例:
当目录结构是下面这样的时候
pom.xml是这样的
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ethereum_book</groupId>
<artifactId>ethereum_book</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<asciidoctor.maven.plugin.version>2.0.0-RC.1</asciidoctor.maven.plugin.version>
<asciidoctorj.version>2.1.0</asciidoctorj.version>
<jruby.version>9.2.8.0</jruby.version>
</properties>
<build>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor.maven.plugin.version}</version>
<dependencies>
<!-- Comment this section to use the default jruby artifact provided by the plugin -->
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>${jruby.version}</version>
</dependency>
<!-- Comment this section to use the default AsciidoctorJ artifact provided by the plugin -->
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>${asciidoctorj.version}</version>
</dependency>
</dependencies>
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<!-- Attributes common to all output formats -->
<attributes>
<endpoint-url>http://example.org</endpoint-url>
<sourcedir>${project.build.sourceDirectory}</sourcedir>
<project-version>${project.version}</project-version>
</attributes>
</configuration>
<executions>
<execution>
<id>asciidoc-to-html</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html5</backend>
<sourceHighlighter>coderay</sourceHighlighter>
<attributes>
<imagesdir>./</imagesdir>
<toc>left</toc>
<icons>font</icons>
<sectanchors>true</sectanchors>
<!-- set the idprefix to blank -->
<idprefix/>
<idseparator>-</idseparator>
<docinfo1>true</docinfo1>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
注:这个pom.xml在eclipse中会有下面这样的报错。不理报错就好了。
Plugin execution not covered by lifecycle configuration:
org.asciidoctor:asciidoctor-maven-plugin:2.0.0-RC.1:
process-asciidoc (execution: asciidoc-to-html, phase: generate-resources)
参考资料
Asciidoc官网
http://asciidoc.org/