在项目应用中,我们会写很多文档去传递我们的设计思想、开发经验、采坑经历等等。使用Asciidoc的格式对非技术人员就不是那么的友好,或者说传递性、通用性与PDF和网页相比就差很多了。在JVM项目中可以使用Maven的插件方式将.adoc文件格式转化为PDF、HTML、EPUB等文件格式。

快速入门

工程结构

|doc-demo
|-src
|--main
|---asciidoc
|----.adoc文件
|---resources
|----images
|pom.xml

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.demo</groupId><artifactId>docs</artifactId><version>1.1.0-SNAPSHOT</version><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><maven.compiler.encoding>UTF-8</maven.compiler.encoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><asciidoctorj.version>1.5.6</asciidoctorj.version><asciidoctorj.diagram.version>1.5.4.1</asciidoctorj.diagram.version><jruby.version>1.7.26</jruby.version></properties><build><!-- 默认命令,配置后可以直接使用mvn编译 --><defaultGoal>process-resources</defaultGoal><resources><resource><directory>src/main/resources</directory><targetPath>${project.build.directory}/book</targetPath></resource></resources><plugins><plugin><groupId>org.asciidoctor</groupId><artifactId>asciidoctor-maven-plugin</artifactId><version>1.5.5</version><executions><execution><id>output-html</id><phase>generate-resources</phase><goals><goal>process-asciidoc</goal></goals><configuration><backend>html5</backend><sourceHighlighter>prettify</sourceHighlighter><attributes><toc>left</toc><icons>font</icons><sectanchors>true</sectanchors><!-- set the idprefix to blank --><idprefix/></attributes></configuration></execution></executions><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><dependency><groupId>org.asciidoctor</groupId><artifactId>asciidoctorj-diagram</artifactId><version>${asciidoctorj.diagram.version}</version></dependency></dependencies><configuration><outputDirectory>${project.build.directory}/book</outputDirectory><sourceDocumentName>book.adoc</sourceDocumentName><imagesDir>./</imagesDir><preserveDirectories>false</preserveDirectories><requires><require>asciidoctor-diagram</require></requires></configuration></plugin></plugins></build></project>

执行mvn命令

mvn clean process-asciidoc

生成的HTML可以使用Http Server或者Nginx等服务进行部署,甚至可以使用Jenkins进行自动化部署。

生成PDF

工程结构

|doc-demo
|-src
|--main
|---asciidoc
|----data
|-----fonts
|-----themes
|----.adoc文件
|---resources
|----images
|pom.xml

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.tairanchina.csp.dmp</groupId><artifactId>docs</artifactId><version>1.1.0-SNAPSHOT</version><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><maven.compiler.encoding>UTF-8</maven.compiler.encoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><asciidoctorj.version>1.5.6</asciidoctorj.version><asciidoctorj.diagram.version>1.5.4.1</asciidoctorj.diagram.version><jruby.version>1.7.26</jruby.version><asciidoctorj.pdf.version>1.5.0-alpha-zh.16</asciidoctorj.pdf.version></properties><build><!--https://github.com/asciidoctor/asciidoctor-maven-examples--><!--https://github.com/asciidoctor/asciidoctor-maven-plugin/blob/master/README_zh-CN.adoc--><!-- 默认命令,配置后可以直接使用mvn编译 --><defaultGoal>process-resources</defaultGoal><resources><resource><directory>src/main/resources</directory><targetPath>${project.build.directory}/book</targetPath></resource></resources><plugins><plugin><groupId>org.asciidoctor</groupId><artifactId>asciidoctor-maven-plugin</artifactId><version>1.5.5</version><executions><execution><id>output-html</id><phase>generate-resources</phase><goals><goal>process-asciidoc</goal></goals><configuration><backend>html5</backend><sourceHighlighter>prettify</sourceHighlighter><attributes><toc>left</toc><icons>font</icons><sectanchors>true</sectanchors><!-- set the idprefix to blank --><idprefix/></attributes></configuration></execution><execution><id>output-pdf</id><phase>generate-resources</phase><goals><goal>process-asciidoc</goal></goals><configuration><backend>pdf</backend><sourceHighlighter>coderay</sourceHighlighter><doctype>book</doctype><attributes><icons>font</icons><pagenums/><toc/><idprefix/><idseparator>-</idseparator><pdf-fontsdir>data/fonts</pdf-fontsdir><pdf-stylesdir>data/themes</pdf-stylesdir><pdf-style>cn</pdf-style></attributes></configuration></execution></executions><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><dependency><groupId>org.asciidoctor</groupId><artifactId>asciidoctorj-diagram</artifactId><version>${asciidoctorj.diagram.version}</version></dependency><dependency><groupId>org.asciidoctor</groupId><artifactId>asciidoctorj-pdf</artifactId><version>${asciidoctorj.pdf.version}</version></dependency></dependencies><configuration><outputDirectory>${project.build.directory}/book</outputDirectory><sourceDocumentName>book.adoc</sourceDocumentName><imagesDir>./</imagesDir><preserveDirectories>false</preserveDirectories><requires><require>asciidoctor-diagram</require></requires></configuration></plugin></plugins></build></project>

执行mvn命令

mvn clean process-asciidoc

由于PDF格式插件没有安装中文字体,生成的PDF格式上会存在缺失,上方的fonts和themes可以对PDF的生成格式进行自定义,有时候为了方便,可以将其与asciidoctorj-pdf源码进行合并,手动打一个依赖包,放到自己的私服仓库中。

常见问题

  • 在生成PDF的时候,可能code部分会存在很多空格的问题,一般产生这样的问题不是字体问题,而是编写格式有问题,可以选择将``符号去掉。

参考资料

Example

Asciidoctor插件中文文档

Asciidoctor-PDF

中文乱码问题解决方案

Asciidoctor Maven插件使用相关推荐

  1. 【maven插件】asciidoctor-maven-plugin:编译Asciidoc

    前言 maven 3.5.0 asciidoctor-maven-plugin 2.0.0-RC.1 jdk 1.8 eclipse 2019-09 R (4.13.0) Asciidoc是个啥? 看 ...

  2. Maven(插件配置和生命周期的绑定)

    1.这篇文章很好,介绍的maven插件的. 2.maven的source插件为例,可以把源代码打成包. Goals Overview就可以查看该插件下面所有的目标. 这里我们要使用的是source:j ...

  3. maven插件报错之解决

    maven插件报错之解决 用m2eclipse创建Maven项目时报错 maveneclipsebuilddependenciesauthorizationplugins 用m2eclipse创建 ...

  4. 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上

    一个用于构建和推送Docker镜像的Maven插件. 使用Maven插件构建Docker镜像,将Docker镜像push到DockerHub上,或者私有仓库,上一篇文章是手写Dockerfile,这篇 ...

  5. [置顶]使用 maven 插件 maven-shade-plugin 对可执行 java 工程及其全部依赖 jar 进行打包...

    作者:chenzhou123520 出处:http://chenzhou123520.iteye.com/blog/1706242 使用 maven 插件 maven-shade-plugin 对 j ...

  6. 【Spring boot 实战】使用Maven插件构建Docker镜像

    本文主要介绍如何使用Maven插件将SpringBoot应用打包为Docker镜像,并上传到私有镜像仓库Docker Registry的过程. 使用Maven构建本地Docker镜像 我们以项目spr ...

  7. IntelliJ IDEA中Maven插件无法更新索引之解决办法

    为什么80%的码农都做不了架构师?>>>    Maven的仓库.索引 中央仓库:目前来说,http://repo1.maven.org/maven2/ 是真正的Maven中央仓库的 ...

  8. Hadoop开发环境配置2-eclipse集成maven插件

    1.下载eclipse:eclipse-SDK-4.5-win32-x86_64.zip 下载地址: http://archive.eclipse.org/eclipse/downloads/drop ...

  9. maven 插件之 AutoConfig 工具使用笔记

    AutoConfig 是一款 maven 插件,主要用于 Maven 项目打包使用.在我们的工作中,会将自己写的代码打成 jar 包或者 war 包发布到各种环境上.一般地,不用的环境所使用的数据库. ...

最新文章

  1. 如何给按钮加上链接功能
  2. 最长公共前缀(java实现)
  3. boost::fusion::convert用法的测试程序
  4. Openfire on Centos7
  5. 【Elasticsearch】Elasticsearch 索引生命周期管理
  6. 中国体力活动监测器(PAM)市场趋势报告、技术动态创新及市场预测
  7. 计算数字1至10的总和
  8. lisp把多段线顶点连成表_读取多段线顶点并将顶点坐标标到数组中
  9. Linux 天翼3G上网
  10. apache的虚拟目录配置
  11. JAVA的对象创建与调用的内存解析
  12. Unicode官网Code Charts下载。
  13. pads 2007 安装完成后, 出现 no license 的解决方法
  14. 利用JavaScript在canvas中画一棵树
  15. python snap7 简书_第14篇-Python中的Elasticsearch入门
  16. WPS之Excel表格如何设置下拉选项
  17. 编写一个静态方法 lg(), 接受一个整型参数 N,返回不大于 log2N 的最大整数。
  18. 计算机设计大赛国赛演讲稿
  19. MOXA NPort5630串口设备联网服务器
  20. “AI+教育”假套路还是真功夫,本质还是对AI能力的拷问

热门文章

  1. python相关软件安装流程图解——Windows下安装Redis以及可视化工具——Redis-x64-3.2.100——redis-desktop-manager-0.9.3.817...
  2. Spring系列(三) Bean装配的高级技术
  3. MyBatis-Spring-Boot 使用总结
  4. Android 一个页面上下两个ListView的页面显示
  5. gtest的Linux使用(Google test)
  6. 【转载】产品经理如何行之有效的提高执行力
  7. BZOJ-1507 文本编辑器(Editor)
  8. (六)基于霍夫变换的直线和圆检测
  9. C++ Primer Plus学习(十一)——类和动态内存分配
  10. python 处理xml pandas_在python中解析xml到pandas数据帧