documentation.html 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="generator" content="Asciidoctor 2.0.15">
  8. <meta name="author" content="pxzxj, pudge.zxj@gmail.com, 2021/12/12">
  9. <title>技术文档编写指南</title>
  10. <link rel="stylesheet" href="css/site.css">
  11. <link href="css/custom.css" rel="stylesheet">
  12. <script src="js/setup.js"></script><script defer src="js/site.js"></script>
  13. </head>
  14. <body class="article toc2 toc-left"><div id="banner-container" class="container" role="banner">
  15. <div id="banner" class="contained" role="banner">
  16. <div id="switch-theme">
  17. <input type="checkbox" id="switch-theme-checkbox" />
  18. <label for="switch-theme-checkbox">Dark Theme</label>
  19. </div>
  20. </div>
  21. </div>
  22. <div id="tocbar-container" class="container" role="navigation">
  23. <div id="tocbar" class="contained" role="navigation">
  24. <button id="toggle-toc"></button>
  25. </div>
  26. </div>
  27. <div id="main-container" class="container">
  28. <div id="main" class="contained">
  29. <div id="doc" class="doc">
  30. <div id="header">
  31. <h1>技术文档编写指南</h1>
  32. <div class="details">
  33. <span id="author" class="author">pxzxj</span><br>
  34. <span id="author2" class="author">pudge.zxj@gmail.com</span><br>
  35. <span id="author3" class="author">2021/12/12</span><br>
  36. </div>
  37. <div id="toc" class="toc2">
  38. <div id="toctitle">Table of Contents</div>
  39. <span id="back-to-index"><a href="index.html">Back to index</a></span><ul class="sectlevel1">
  40. <li><a href="#_introduction">1. Introduction</a></li>
  41. <li><a href="#_docs_as_code">2. Docs as Code</a></li>
  42. <li><a href="#_asciidoc">3. AsciiDoc</a>
  43. <ul class="sectlevel2">
  44. <li><a href="#_quickstart">3.1. QuickStart</a></li>
  45. <li><a href="#_syntax">3.2. Syntax</a></li>
  46. <li><a href="#_asciidoc_vs_markdown">3.3. AsciiDoc vs Markdown</a></li>
  47. </ul>
  48. </li>
  49. <li><a href="#_asciidoctor">4. Asciidoctor</a>
  50. <ul class="sectlevel2">
  51. <li><a href="#_intellij_idea_plugin">4.1. Intellij IDEA Plugin</a></li>
  52. <li><a href="#_asciidoctor_maven_plugin">4.2. Asciidoctor-Maven-Plugin</a></li>
  53. <li><a href="#_spring_backend">4.3. Spring Backend</a>
  54. <ul class="sectlevel3">
  55. <li><a href="#_install">4.3.1. Install</a></li>
  56. <li><a href="#_spring_look_and_feel">4.3.2. Spring Look and Feel</a></li>
  57. <li><a href="#_responsive_design">4.3.3. Responsive Design</a></li>
  58. <li><a href="#_back_to_index_link">4.3.4. "Back to Index" Link</a></li>
  59. <li><a href="#_dark_mode">4.3.5. Dark Mode</a></li>
  60. <li><a href="#_tabs">4.3.6. Tabs</a></li>
  61. <li><a href="#_code_folding">4.3.7. Code Folding</a></li>
  62. <li><a href="#_different_config_blocks">4.3.8. Different Config Blocks</a></li>
  63. </ul>
  64. </li>
  65. <li><a href="#_bilibili_extension">4.4. Bilibili Extension</a></li>
  66. </ul>
  67. </li>
  68. <li><a href="#_examples">5. Examples</a>
  69. <ul class="sectlevel2">
  70. <li><a href="#_html">5.1. Html</a></li>
  71. <li><a href="#_pdf">5.2. Pdf</a></li>
  72. <li><a href="#cicd">5.3. CI/CD</a></li>
  73. <li><a href="#_doc_review">5.4. Doc Review</a></li>
  74. </ul>
  75. </li>
  76. <li><a href="#_style">6. Style</a></li>
  77. <li><a href="#_best_practice">7. Best Practice</a></li>
  78. </ul>
  79. </div>
  80. </div>
  81. <div id="content">
  82. <div class="sect1">
  83. <h2 id="_introduction"><a class="anchor" href="#_introduction"></a>1. Introduction</h2>
  84. <div class="sectionbody">
  85. <div class="paragraph">
  86. <p>软件开发中文档跟代码同等重要,优秀的文档对软件的日常使用和后期维护都至关重要,另一方面结合国内软件厂商员工流动频繁的情况,完善文的档还能帮助新员工迅速熟悉项目及业务,
  87. 将人员变动的影响降到最低,保证项目持续稳定运作,当然最终也能在一定程度上节约企业成本。</p>
  88. </div>
  89. <div class="paragraph">
  90. <p>既然文档如此重要,那么项目组必须保证在整个项目周期中输出各类文档,包括但不限于架构设计文档、详细设计文档、代码评审记录等。
  91. 然而大部分项目组的现状是文档缺失、管理混乱、随便写一下草草了事,其中原因当然跟需求变化快、开发周期紧、人员不足有关,
  92. 但是文档编写工具也会极大地影响编写效率和管理方式。
  93. 目前开发相关文档基本都是使用 <code>Word</code> 进行编写的,使用 <code>Word</code> 会存在下面几点问题:</p>
  94. </div>
  95. <div class="dlist">
  96. <dl>
  97. <dt class="hdlist1">版本管理困难 </dt>
  98. <dd>
  99. <p><code>Word</code> 文档是复杂格式的文档,使用版本管理软件无法方便地查看或对比每一次的修改内容。</p>
  100. </dd>
  101. <dt class="hdlist1">协作编写困难 </dt>
  102. <dd>
  103. <p>同样是因为 <code>Word</code> 文档的复杂格式,无法多人协作在一个文档上编辑,只能手动合并,合并后的文档以及无法区分特定内容的真正作者。</p>
  104. </dd>
  105. <dt class="hdlist1">代码支持性差 </dt>
  106. <dd>
  107. <p><code>Word</code> 文档主要还是用于文本内容,代码的展示效果很差,除非手工再进行复杂的格式调整。</p>
  108. </dd>
  109. <dt class="hdlist1">格式调整耗时 </dt>
  110. <dd>
  111. <p>想要获得期望的整洁美观效果,通常需要不断调整文档格式,<code>Word</code> 的格式调整等都需要鼠标操作,键鼠切换通用会降低文档编写效率,这也正是Intellij IDEA提供了如此多快捷键的原因。</p>
  112. </dd>
  113. <dt class="hdlist1">需要单独上传 </dt>
  114. <dd>
  115. <p>通常是再桌面新建一个文档,如果要上传到SVN或者Git上还需要手动复制到对应目录,很多开发文档已经写了但忘记上传。</p>
  116. </dd>
  117. <dt class="hdlist1">需要单独下载 </dt>
  118. <dd>
  119. <p>文档编写完成之后必然要供其它人查看,而要查看 <code>Word</code> 编写的文档需要专门从SVN或Git上拣出。</p>
  120. </dd>
  121. </dl>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="sect1">
  126. <h2 id="_docs_as_code"><a class="anchor" href="#_docs_as_code"></a>2. Docs as Code</h2>
  127. <div class="sectionbody">
  128. <div class="paragraph">
  129. <p>针对上文描述的 <code>Word</code> 文档存在的诸多问题,国外的诸多企业开始基于 <code>Docs as Code</code> 的理念进行文档编写。<code>Docs as Code</code> 是指按照写代码的方式写文档,主要包括下面几点内容</p>
  130. </div>
  131. <div class="dlist">
  132. <dl>
  133. <dt class="hdlist1">使用简单文本编写文档 </dt>
  134. <dd>
  135. <p>这一点是最重要的要求,只有简单文本才能使用Git强大的版本管理功能。</p>
  136. </dd>
  137. <dt class="hdlist1">使用版本控制工具管理文档 </dt>
  138. <dd>
  139. <p>文档总是在不断变化的,使用SVN、Git等版本控制工具能够查看文档所有的历史记录以及作者等信息。同代码一样,文档也可以使用分支管理等功能为软件的不同版本提供不同的文档。</p>
  140. </dd>
  141. <dt class="hdlist1">文档评审 </dt>
  142. <dd>
  143. <p>代码需要评审,文档也是一样,只有评审通过的文档才能合并到主干。评审可以是线下会议的方式进行也可以是线上Review Commit或者Pull Request的方式进行。</p>
  144. </dd>
  145. <dt class="hdlist1">为文档编写测试 </dt>
  146. <dd>
  147. <p>使用测试验证文档中错别字、失效链接、代码片段等,这一点一般不做强制要求。</p>
  148. </dd>
  149. <dt class="hdlist1">文档自动化发布 </dt>
  150. <dd>
  151. <p>文档提交后能够自动发布到特定文档站点上供其它人查看。</p>
  152. </dd>
  153. </dl>
  154. </div>
  155. <div class="admonitionblock tip">
  156. <table>
  157. <tr>
  158. <td class="icon">
  159. <i class="fa icon-tip" title="Tip"></i>
  160. </td>
  161. <td class="content">
  162. 更多关于 <code>Docs as Code</code> 的介绍参考 <a href="https://www.writethedocs.org/guide/docs-as-code/">writethedocs站点</a>
  163. </td>
  164. </tr>
  165. </table>
  166. </div>
  167. </div>
  168. </div>
  169. <div class="sect1">
  170. <h2 id="_asciidoc"><a class="anchor" href="#_asciidoc"></a>3. AsciiDoc</h2>
  171. <div class="sectionbody">
  172. <div class="paragraph">
  173. <p><a href="https://asciidoctor.org/docs/what-is-asciidoc/">AsciiDoc</a> 是一种轻量级文本标记语言,可以用于创作笔记、文档、博客、电子书、网页、幻灯片、man手册,
  174. 它以简单文本的方式编写可以转换为html、pdf等多种格式,部分网站如GitHub支持直接将AsciiDoc内容呈现为html。</p>
  175. </div>
  176. <div class="sect2">
  177. <h3 id="_quickstart"><a class="anchor" href="#_quickstart"></a>3.1. QuickStart</h3>
  178. <div class="listingblock">
  179. <div class="content">
  180. <pre>= The First Asciidoc example: Subtitle <i class="conum" data-value="1"></i><b>(1)</b>
  181. Lars Vogel(c) 2016 vogella GmbH <i class="conum" data-value="2"></i><b>(2)</b>
  182. Version 0.3, 17.05.2021 <i class="conum" data-value="3"></i><b>(3)</b>
  183. :sectnums: <i class="conum" data-value="4"></i><b>(4)</b>
  184. :toc: <i class="conum" data-value="5"></i><b>(5)</b>
  185. :toclevels: 4 <i class="conum" data-value="6"></i><b>(6)</b>
  186. :toc-title: My Content <i class="conum" data-value="7"></i><b>(7)</b>
  187. :experimental: <i class="conum" data-value="8"></i><b>(8)</b>
  188. :description: Example AsciiDoc document <i class="conum" data-value="9"></i><b>(9)</b>
  189. :imagesdir: ./img <i class="conum" data-value="10"></i><b>(10)</b>
  190. This is the optional preamble (an untitled section body). Useful for
  191. writing simple sectionless documents consisting only of a preamble.
  192. == First section
  193. Some text
  194. == Second section
  195. More test</pre>
  196. </div>
  197. </div>
  198. <div class="olist arabic">
  199. <ol class="arabic">
  200. <li>
  201. <p>文档标题及副标题</p>
  202. </li>
  203. <li>
  204. <p>标题下一行列出作者信息</p>
  205. </li>
  206. <li>
  207. <p>文件修订版本</p>
  208. </li>
  209. <li>
  210. <p>需要展示各章节编号</p>
  211. </li>
  212. <li>
  213. <p>生出文档目录,toc即Table Of Contents</p>
  214. </li>
  215. <li>
  216. <p>默认toc仅展示两级目录,toclevel可以修改为其它值</p>
  217. </li>
  218. <li>
  219. <p>默认目录标题为 <code>Table Of Contents</code>,使用toc-title修改为其它值</p>
  220. </li>
  221. <li>
  222. <p>启用实验性功能</p>
  223. </li>
  224. <li>
  225. <p>文档的描述</p>
  226. </li>
  227. <li>
  228. <p>默认图片目录</p>
  229. </li>
  230. </ol>
  231. </div>
  232. </div>
  233. <div class="sect2">
  234. <h3 id="_syntax"><a class="anchor" href="#_syntax"></a>3.2. Syntax</h3>
  235. <div class="paragraph">
  236. <p>AsciiDoc相关语法参考 <a href="https://docs.asciidoctor.org/asciidoc/latest/">官方站点</a></p>
  237. </div>
  238. </div>
  239. <div class="sect2">
  240. <h3 id="_asciidoc_vs_markdown"><a class="anchor" href="#_asciidoc_vs_markdown"></a>3.3. AsciiDoc vs Markdown</h3>
  241. <div class="admonitionblock tip">
  242. <table>
  243. <tr>
  244. <td class="icon">
  245. <i class="fa icon-tip" title="Tip"></i>
  246. </td>
  247. <td class="content">
  248. <a href="https://docs.asciidoctor.org/asciidoc/latest/asciidoc-vs-markdown/">官方站点</a>详细对比了AsciiDoc和Markdown,本节内容主要是对其进行摘取和翻译
  249. </td>
  250. </tr>
  251. </table>
  252. </div>
  253. <div class="paragraph">
  254. <p>Markdown是最流行的轻量级文本标记语言,它的语法简单易于学习,很多开源项目的文档也都是使用Markdown编写的包括Dubbo、Nacos等,
  255. 然而语法简单也注定它无法满足一些复杂常见的文档编写需求包括表格、文档交叉引用、脚注、嵌入视频等。而AsciiDoc既保留了简洁的编写语法,
  256. 又考虑到了几乎所有场景的文档编写需求,很多技术书籍就是使用AsciiDoc编写完成后打印出版的。最重要的是AsciiDoc的语法设计为可扩展的,
  257. 用户完全可以根据自己的需求设计特殊AsciiDoc语法。</p>
  258. </div>
  259. <div class="paragraph">
  260. <p>下表对AsciiDoc语法和Markdown语法的比较,不过此处仅关注了AsciiDoc和Markdown都支持的语法</p>
  261. </div>
  262. <table class="tableblock frame-all grid-all fit-content">
  263. <colgroup>
  264. <col>
  265. <col>
  266. <col>
  267. </colgroup>
  268. <thead>
  269. <tr>
  270. <th class="tableblock halign-left valign-top">Language Feature</th>
  271. <th class="tableblock halign-left valign-top">Markdown</th>
  272. <th class="tableblock halign-left valign-top">AsciiDoc</th>
  273. </tr>
  274. </thead>
  275. <tbody>
  276. <tr>
  277. <td class="tableblock halign-left valign-top"><p class="tableblock">加粗(受约束)</p></td>
  278. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  279. <div class="content">
  280. <pre class="highlight"><code class="language-markdown" data-lang="markdown">**bold**</code></pre>
  281. </div>
  282. </div></div></td>
  283. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  284. <div class="content">
  285. <pre class="highlight"><code>*bold*</code></pre>
  286. </div>
  287. </div></div></td>
  288. </tr>
  289. <tr>
  290. <td class="tableblock halign-left valign-top"><p class="tableblock">加粗 (不受约束)</p></td>
  291. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  292. <div class="content">
  293. <pre class="highlight"><code class="language-markdown" data-lang="markdown">**b**old</code></pre>
  294. </div>
  295. </div></div></td>
  296. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  297. <div class="content">
  298. <pre class="highlight"><code>**b**old</code></pre>
  299. </div>
  300. </div></div></td>
  301. </tr>
  302. <tr>
  303. <td class="tableblock halign-left valign-top"><p class="tableblock">斜体 (受约束)</p></td>
  304. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  305. <div class="content">
  306. <pre class="highlight"><code class="language-markdown" data-lang="markdown">*italic*</code></pre>
  307. </div>
  308. </div></div></td>
  309. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  310. <div class="content">
  311. <pre class="highlight"><code>_italic_</code></pre>
  312. </div>
  313. </div></div></td>
  314. </tr>
  315. <tr>
  316. <td class="tableblock halign-left valign-top"><p class="tableblock">斜体 (不受约束)</p></td>
  317. <td class="tableblock halign-left valign-top"><p class="tableblock"><em>n/a</em></p></td>
  318. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  319. <div class="content">
  320. <pre class="highlight"><code>__i__talic</code></pre>
  321. </div>
  322. </div></div></td>
  323. </tr>
  324. <tr>
  325. <td class="tableblock halign-left valign-top"><p class="tableblock">等宽词 (受约束)</p></td>
  326. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  327. <div class="content">
  328. <pre class="highlight"><code class="language-markdown" data-lang="markdown">`monospace`</code></pre>
  329. </div>
  330. </div></div></td>
  331. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  332. <div class="content">
  333. <pre class="highlight"><code>`monospace`</code></pre>
  334. </div>
  335. </div></div></td>
  336. </tr>
  337. <tr>
  338. <td class="tableblock halign-left valign-top"><p class="tableblock">等宽词 (不受约束)</p></td>
  339. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  340. <div class="content">
  341. <pre class="highlight"><code class="language-markdown" data-lang="markdown">`m`onospace</code></pre>
  342. </div>
  343. </div></div></td>
  344. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  345. <div class="content">
  346. <pre class="highlight"><code>``m``onospace</code></pre>
  347. </div>
  348. </div></div></td>
  349. </tr>
  350. <tr>
  351. <td class="tableblock halign-left valign-top"><p class="tableblock">超链接</p></td>
  352. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  353. <div class="content">
  354. <pre class="highlight"><code class="language-markdown" data-lang="markdown">[Asciidoctor](https://asciidoctor.org)</code></pre>
  355. </div>
  356. </div></div></td>
  357. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  358. <div class="content">
  359. <pre class="highlight"><code>https://asciidoctor.org[Asciidoctor]</code></pre>
  360. </div>
  361. </div></div></td>
  362. </tr>
  363. <tr>
  364. <td class="tableblock halign-left valign-top"><p class="tableblock">相对路径链接</p></td>
  365. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  366. <div class="content">
  367. <pre class="highlight"><code class="language-markdown" data-lang="markdown">[user guide](user-guide.html)</code></pre>
  368. </div>
  369. </div></div></td>
  370. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  371. <div class="content">
  372. <pre class="highlight"><code>link:user-guide.html[user guide]
  373. xref:user-guide.adoc[user guide]</code></pre>
  374. </div>
  375. </div></div></td>
  376. </tr>
  377. <tr>
  378. <td class="tableblock halign-left valign-top"><p class="tableblock">文件链接</p></td>
  379. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  380. <div class="content">
  381. <pre class="highlight"><code class="language-markdown" data-lang="markdown">[get the PDF]({% raw %}{{ site.url }}{% endraw %}/assets/mydoc.pdf)</code></pre>
  382. </div>
  383. </div></div></td>
  384. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  385. <div class="content">
  386. <pre class="highlight"><code>link:{site-url}/assets/mydoc.pdf[get the PDF]</code></pre>
  387. </div>
  388. </div></div></td>
  389. </tr>
  390. <tr>
  391. <td class="tableblock halign-left valign-top"><p class="tableblock">交叉引用</p></td>
  392. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  393. <div class="content">
  394. <pre class="highlight"><code class="language-markdown" data-lang="markdown">See [Usage](#_usage).
  395. &lt;h2 id="_usage"&gt;Usage&lt;/h2&gt;</code></pre>
  396. </div>
  397. </div></div></td>
  398. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  399. <div class="content">
  400. <pre class="highlight"><code>See &lt;&lt;_usage&gt;&gt;.
  401. == Usage</code></pre>
  402. </div>
  403. </div></div></td>
  404. </tr>
  405. <tr>
  406. <td class="tableblock halign-left valign-top"><p class="tableblock">锚点</p></td>
  407. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  408. <div class="content">
  409. <pre class="highlight"><code class="language-markdown" data-lang="markdown">&lt;h2 id="usage"&gt;Usage&lt;/h2&gt;</code></pre>
  410. </div>
  411. </div></div></td>
  412. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  413. <div class="content">
  414. <pre class="highlight"><code>[#usage]
  415. == Usage</code></pre>
  416. </div>
  417. </div></div></td>
  418. </tr>
  419. <tr>
  420. <td class="tableblock halign-left valign-top"><p class="tableblock">内联图片</p></td>
  421. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  422. <div class="content">
  423. <pre class="highlight"><code class="language-markdown" data-lang="markdown">![Logo](/images/logo.png)</code></pre>
  424. </div>
  425. </div></div></td>
  426. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  427. <div class="content">
  428. <pre class="highlight"><code>image:logo.png[Logo]</code></pre>
  429. </div>
  430. </div></div></td>
  431. </tr>
  432. <tr>
  433. <td class="tableblock halign-left valign-top"><p class="tableblock">图片</p></td>
  434. <td class="tableblock halign-left valign-top"><p class="tableblock"><em>n/a</em></p></td>
  435. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  436. <div class="content">
  437. <pre class="highlight"><code>image::logo.png[Logo]</code></pre>
  438. </div>
  439. </div></div></td>
  440. </tr>
  441. <tr>
  442. <td class="tableblock halign-left valign-top"><p class="tableblock">章节标题</p></td>
  443. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  444. <div class="content">
  445. <pre class="highlight"><code class="language-markdown" data-lang="markdown">## Heading 2</code></pre>
  446. </div>
  447. </div></div></td>
  448. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  449. <div class="content">
  450. <pre class="highlight"><code>== Heading 2</code></pre>
  451. </div>
  452. </div></div></td>
  453. </tr>
  454. <tr>
  455. <td class="tableblock halign-left valign-top"><p class="tableblock">引用</p></td>
  456. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  457. <div class="content">
  458. <pre class="highlight"><code class="language-markdown" data-lang="markdown">&gt; Quoted text.
  459. &gt;
  460. &gt; Another paragraph in quote.</code></pre>
  461. </div>
  462. </div></div></td>
  463. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  464. <div class="content">
  465. <pre class="highlight"><code>____
  466. Quoted text.
  467. Another paragraph in quote.
  468. ____</code></pre>
  469. </div>
  470. </div></div></td>
  471. </tr>
  472. <tr>
  473. <td class="tableblock halign-left valign-top"><p class="tableblock">文本</p></td>
  474. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  475. <div class="content">
  476. <pre class="highlight"><code class="language-markdown" data-lang="markdown"> $ gem install asciidoctor</code></pre>
  477. </div>
  478. </div></div></td>
  479. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  480. <div class="title">Indented (by 1 or more spaces)</div>
  481. <div class="content">
  482. <pre class="highlight"><code> $ gem install asciidoctor</code></pre>
  483. </div>
  484. </div>
  485. <div class="listingblock">
  486. <div class="title">Delimited</div>
  487. <div class="content">
  488. <pre class="highlight"><code>....
  489. $ gem install asciidoctor
  490. ....</code></pre>
  491. </div>
  492. </div></div></td>
  493. </tr>
  494. <tr>
  495. <td class="tableblock halign-left valign-top"><p class="tableblock">代码</p></td>
  496. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  497. <div class="content">
  498. <pre class="highlight"><code class="language-markdown" data-lang="markdown">```java
  499. public class Person {
  500. private String name;
  501. public Person(String name) {
  502. this.name = name;
  503. }
  504. }
  505. ```</code></pre>
  506. </div>
  507. </div></div></td>
  508. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  509. <div class="content">
  510. <pre class="highlight"><code>[source,java]
  511. ----
  512. public class Person {
  513. private String name;
  514. public Person(String name) {
  515. this.name = name;
  516. }
  517. }
  518. ----</code></pre>
  519. </div>
  520. </div></div></td>
  521. </tr>
  522. <tr>
  523. <td class="tableblock halign-left valign-top"><p class="tableblock">无序列表</p></td>
  524. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  525. <div class="content">
  526. <pre class="highlight"><code class="language-markdown" data-lang="markdown">* apples
  527. * orange
  528. * temple
  529. * navel
  530. * bananas</code></pre>
  531. </div>
  532. </div></div></td>
  533. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  534. <div class="content">
  535. <pre class="highlight"><code>* apples
  536. * oranges
  537. ** temple
  538. ** navel
  539. * bananas</code></pre>
  540. </div>
  541. </div></div></td>
  542. </tr>
  543. <tr>
  544. <td class="tableblock halign-left valign-top"><p class="tableblock">有序列表</p></td>
  545. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  546. <div class="content">
  547. <pre class="highlight"><code class="language-markdown" data-lang="markdown">1. first
  548. 2. second
  549. 3. third</code></pre>
  550. </div>
  551. </div></div></td>
  552. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  553. <div class="content">
  554. <pre class="highlight"><code>. first
  555. . second
  556. . third</code></pre>
  557. </div>
  558. </div></div></td>
  559. </tr>
  560. <tr>
  561. <td class="tableblock halign-left valign-top"><p class="tableblock">文档头</p></td>
  562. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  563. <div class="title">Slapped on as &#8220;front matter&#8221;</div>
  564. <div class="content">
  565. <pre class="highlight"><code class="language-markdown" data-lang="markdown">---
  566. layout: docs
  567. title: Writing posts
  568. prev_section: defining-frontmatter
  569. next_section: creating-pages
  570. permalink: /docs/writing-posts/
  571. ---</code></pre>
  572. </div>
  573. </div></div></td>
  574. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  575. <div class="title">Native support!</div>
  576. <div class="content">
  577. <pre class="highlight"><code>= Writing posts
  578. :page-layout: base
  579. :showtitle:
  580. :prev_section: defining-frontmatter
  581. :next_section: creating-pages</code></pre>
  582. </div>
  583. </div></div></td>
  584. </tr>
  585. <tr>
  586. <td class="tableblock halign-left valign-top"><p class="tableblock">警告</p></td>
  587. <td class="tableblock halign-left valign-top"><p class="tableblock"><em>n/a</em></p></td>
  588. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  589. <div class="content">
  590. <pre class="highlight"><code>TIP: You can add line numbers to source listings by adding the word `numbered` in the attribute list after the language name.</code></pre>
  591. </div>
  592. </div></div></td>
  593. </tr>
  594. <tr>
  595. <td class="tableblock halign-left valign-top"><p class="tableblock">块标题</p></td>
  596. <td class="tableblock halign-left valign-top"><p class="tableblock"><em>n/a</em></p></td>
  597. <td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
  598. <div class="content">
  599. <pre class="highlight"><code>.Grocery list
  600. * Milk
  601. * Eggs
  602. * Bread</code></pre>
  603. </div>
  604. </div></div></td>
  605. </tr>
  606. </tbody>
  607. </table>
  608. <div class="admonitionblock note">
  609. <table>
  610. <tr>
  611. <td class="icon">
  612. <i class="fa icon-note" title="Note"></i>
  613. </td>
  614. <td class="content">
  615. 受约束的是指使用时前后必须有空格,不受约束的则表示可以在任何地方使用
  616. </td>
  617. </tr>
  618. </table>
  619. </div>
  620. </div>
  621. </div>
  622. </div>
  623. <div class="sect1">
  624. <h2 id="_asciidoctor"><a class="anchor" href="#_asciidoctor"></a>4. Asciidoctor</h2>
  625. <div class="sectionbody">
  626. <div class="paragraph">
  627. <p><a href="https://asciidoctor.org/">Asciidoctor</a> 是最流行的AsciiDoc处理软件,它使用Ruby编写,源码托管在GitHub上,
  628. 很多知名的项目如Spring、Hibernate、JUnit等都是使用Asciidoctor生成项目文档的。</p>
  629. </div>
  630. <div class="paragraph">
  631. <p>AsciiDoctor能够快速将asciidoc文档转换为Html5、Docbook、Pdf、Epub3等多种格式。
  632. 同时AsciiDoctor还提供了很多扩展接口,允许开发者根据特定需求扩展AsciiDoctor的功能,
  633. 下文介绍的 <code>Bilibili Extension</code> 以及 <code>Spring Backend</code> 就是对AsciiDoctor的扩展。</p>
  634. </div>
  635. <div class="paragraph">
  636. <p>Asciidoctor包含了多种不同形式的实现用于满足不同人员的需求,包括命令行工具、Intellij IDEA插件、浏览器插件、Maven插件、Gradle插件等,
  637. 本文选择对Java开发者比较友好的Intellij IDEA和maven插件进行介绍。</p>
  638. </div>
  639. <div class="sect2">
  640. <h3 id="_intellij_idea_plugin"><a class="anchor" href="#_intellij_idea_plugin"></a>4.1. Intellij IDEA Plugin</h3>
  641. <div class="paragraph">
  642. <p>搜索AsciiDoc插件安装即可。</p>
  643. </div>
  644. <div class="imageblock">
  645. <div class="content">
  646. <img src="images/install-from-marketplace.png" alt="install from marketplace">
  647. </div>
  648. </div>
  649. <div class="paragraph">
  650. <p>插件安装完成后新建.adoc结尾的文件就会自动使用此插件,左侧为使用asciidoc编写的原始内容,右侧为渲染后的效果。</p>
  651. </div>
  652. <div class="imageblock">
  653. <div class="content">
  654. <img src="images/asciidoc-intellij-idea-plugin-editor.png" alt="asciidoc intellij idea plugin editor">
  655. </div>
  656. </div>
  657. </div>
  658. <div class="sect2">
  659. <h3 id="_asciidoctor_maven_plugin"><a class="anchor" href="#_asciidoctor_maven_plugin"></a>4.2. Asciidoctor-Maven-Plugin</h3>
  660. <div class="paragraph">
  661. <p>Asciidoctor Maven Plugin可以将AsciiDoc文档转换为多种格式。跟其它Maven插件一样,在 <code>pom.xml</code> 中添加AsciiDoctor插件配置即可开始使用。</p>
  662. </div>
  663. <div class="listingblock">
  664. <div class="content">
  665. <pre class="highlight"><code class="language-xml" data-lang="xml">&lt;project&gt;
  666. ...
  667. &lt;build&gt;
  668. ...
  669. &lt;plugin&gt;
  670. &lt;groupId&gt;org.asciidoctor&lt;/groupId&gt;
  671. &lt;artifactId&gt;asciidoctor-maven-plugin&lt;/artifactId&gt;
  672. &lt;version&gt;2.2.1&lt;/version&gt;
  673. &lt;executions&gt;
  674. &lt;execution&gt;
  675. &lt;id&gt;convert-to-html&lt;/id&gt;
  676. &lt;phase&gt;generate-resources&lt;/phase&gt; <i class="conum" data-value="1"></i><b>(1)</b>
  677. &lt;goals&gt;
  678. &lt;goal&gt;process-asciidoc&lt;/goal&gt;
  679. &lt;/goals&gt;
  680. &lt;configuration&gt;
  681. &lt;outputDirectory&gt;${project.build.directory}/html&lt;/outputDirectory&gt; <i class="conum" data-value="2"></i><b>(2)</b>
  682. &lt;attributes&gt; <i class="conum" data-value="3"></i><b>(3)</b>
  683. &lt;source-highlighter&gt;coderay&lt;/source-highlighter&gt;
  684. &lt;imagesdir&gt;./images&lt;/imagesdir&gt;
  685. &lt;toc&gt;left&lt;/toc&gt;
  686. &lt;icons&gt;font&lt;/icons&gt;
  687. &lt;/attributes&gt;
  688. &lt;/configuration&gt;
  689. &lt;/execution&gt;
  690. &lt;/executions&gt;
  691. &lt;/plugin&gt;
  692. ...
  693. &lt;/project&gt;</code></pre>
  694. </div>
  695. </div>
  696. <div class="olist arabic">
  697. <ol class="arabic">
  698. <li>
  699. <p>配置插件执行阶段和目标</p>
  700. </li>
  701. <li>
  702. <p><code>Configuration</code> 中配置插件相关参数</p>
  703. </li>
  704. <li>
  705. <p>文档属性</p>
  706. </li>
  707. </ol>
  708. </div>
  709. <div class="paragraph">
  710. <p><code>Configuration</code> 中支持众多参数的配置,下面选择几个重要的进行说明,完整参数列表参考 <a href="https://docs.asciidoctor.org/maven-tools/latest/plugin/goals/process-asciidoc/">官方文档</a></p>
  711. </div>
  712. <div class="dlist">
  713. <dl>
  714. <dt class="hdlist1"><em><strong>sourceDirectory</strong></em> </dt>
  715. <dd>
  716. <p>源文件目录,默认检查 <em>/src/docs/asciidoc, /src/asciidoc和/src/main/asciidoc</em>。</p>
  717. </dd>
  718. <dt class="hdlist1"><em><strong>sourceDocumentName</strong></em> </dt>
  719. <dd>
  720. <p>源文件名称,默认检查 <code>sourceDirectory</code> 下的所有文件。</p>
  721. </dd>
  722. <dt class="hdlist1"><em><strong>sourceDocumentExtensions</strong></em> </dt>
  723. <dd>
  724. <p>源文件扩展名,默认包含<em>ad, adoc, and asciidoc</em>。</p>
  725. </dd>
  726. <dt class="hdlist1"><em><strong>outputDirectory</strong></em> </dt>
  727. <dd>
  728. <p>转换后文件输出目录,默认为<em>${project.build.directory}/generated-docs.</em>。</p>
  729. </dd>
  730. <dt class="hdlist1"><em><strong>backend</strong></em> </dt>
  731. <dd>
  732. <p>转换目标类型,默认是html5。</p>
  733. </dd>
  734. <dt class="hdlist1"><em><strong>doctype</strong></em> </dt>
  735. <dd>
  736. <p>支持book和article,默认使用article。</p>
  737. </dd>
  738. </dl>
  739. </div>
  740. </div>
  741. <div class="sect2">
  742. <h3 id="_spring_backend"><a class="anchor" href="#_spring_backend"></a>4.3. Spring Backend</h3>
  743. <div class="paragraph">
  744. <p>Asciidoctor提供了通用的文档输出格式,而不同框架或软件则可以根据自身需求进行扩展,Spring为了提升文档可读性创建了 <a href="https://github.com/spring-io/spring-asciidoctor-backends">spring-asciidoctor-backends</a>项目用于生成Spring风格的html文档。</p>
  745. </div>
  746. <div class="sect3">
  747. <h4 id="_install"><a class="anchor" href="#_install"></a>4.3.1. Install</h4>
  748. <div class="paragraph">
  749. <p>再Asciidoctor Maven插件中添加Spring Backend相关配置即可使用。</p>
  750. </div>
  751. <div class="listingblock">
  752. <div class="content">
  753. <pre class="highlight"><code class="language-xml" data-lang="xml">&lt;plugin&gt;
  754. &lt;groupId&gt;org.asciidoctor&lt;/groupId&gt;
  755. &lt;artifactId&gt;asciidoctor-maven-plugin&lt;/artifactId&gt;
  756. &lt;version&gt;2.1.0&lt;/version&gt;
  757. &lt;executions&gt;
  758. &lt;execution&gt;
  759. &lt;id&gt;generate-html-documentation&lt;/id&gt;
  760. &lt;phase&gt;prepare-package&lt;/phase&gt;
  761. &lt;goals&gt;
  762. &lt;goal&gt;process-asciidoc&lt;/goal&gt;
  763. &lt;/goals&gt;
  764. &lt;configuration&gt;
  765. &lt;backend&gt;spring-html&lt;/backend&gt; <i class="conum" data-value="1"></i><b>(1)</b>
  766. &lt;/configuration&gt;
  767. &lt;/execution&gt;
  768. &lt;/executions&gt;
  769. &lt;dependencies&gt;
  770. &lt;dependency&gt; <i class="conum" data-value="2"></i><b>(2)</b>
  771. &lt;groupId&gt;io.spring.asciidoctor.backends&lt;/groupId&gt;
  772. &lt;artifactId&gt;spring-asciidoctor-backends&lt;/artifactId&gt;
  773. &lt;version&gt;${spring-asciidoctor-backends.version}&lt;/version&gt;
  774. &lt;/dependency&gt;
  775. &lt;/dependencies&gt;
  776. &lt;/plugin&gt;
  777. &lt;repositories&gt;
  778. &lt;repository&gt; <i class="conum" data-value="3"></i><b>(3)</b>
  779. &lt;id&gt;spring-release&lt;/id&gt;
  780. &lt;name&gt;Spring Releases&lt;/name&gt;
  781. &lt;url&gt;https://repo.spring.io/release&lt;/url&gt;
  782. &lt;snapshots&gt;
  783. &lt;enabled&gt;false&lt;/enabled&gt;
  784. &lt;/snapshots&gt;
  785. &lt;/repository&gt;
  786. &lt;/repositories&gt;</code></pre>
  787. </div>
  788. </div>
  789. <div class="olist arabic">
  790. <ol class="arabic">
  791. <li>
  792. <p>backend设置为spring-html</p>
  793. </li>
  794. <li>
  795. <p>添加spring-backend依赖</p>
  796. </li>
  797. <li>
  798. <p>配置Spring Maven仓库</p>
  799. </li>
  800. </ol>
  801. </div>
  802. </div>
  803. <div class="sect3">
  804. <h4 id="_spring_look_and_feel"><a class="anchor" href="#_spring_look_and_feel"></a>4.3.2. Spring Look and Feel</h4>
  805. <div class="paragraph">
  806. <p>生成的html样式与Spring官网保持一致,左上角展示Spring的Logo。</p>
  807. </div>
  808. <div class="admonitionblock tip">
  809. <table>
  810. <tr>
  811. <td class="icon">
  812. <i class="fa icon-tip" title="Tip"></i>
  813. </td>
  814. <td class="content">
  815. 后期可能会允许使用自定义的Logo,参考 <a href="https://github.com/spring-io/spring-asciidoctor-backends/issues/24">Ability to override the banner logo</a>
  816. </td>
  817. </tr>
  818. </table>
  819. </div>
  820. </div>
  821. <div class="sect3">
  822. <h4 id="_responsive_design"><a class="anchor" href="#_responsive_design"></a>4.3.3. Responsive Design</h4>
  823. <div class="paragraph">
  824. <p>生成的html遵循响应式设计,能在各种设备上很好地展示,如台式机、平板电脑、智能手机等。</p>
  825. </div>
  826. </div>
  827. <div class="sect3">
  828. <h4 id="_back_to_index_link"><a class="anchor" href="#_back_to_index_link"></a>4.3.4. "Back to Index" Link</h4>
  829. <div class="paragraph">
  830. <p>如果当前页面部署index.html,那么提供一个Back to Index链接用于返回到首页</p>
  831. </div>
  832. </div>
  833. <div class="sect3">
  834. <h4 id="_dark_mode"><a class="anchor" href="#_dark_mode"></a>4.3.5. Dark Mode</h4>
  835. <div class="paragraph">
  836. <p>页面右上角支持切换黑夜模式,模式设置保存在本地,无需每次重新加载后设置</p>
  837. </div>
  838. </div>
  839. <div class="sect3">
  840. <h4 id="_tabs"><a class="anchor" href="#_tabs"></a>4.3.6. Tabs</h4>
  841. <div class="paragraph">
  842. <p>支持多个Tab页合并与切换,常见的如Maven和Gradle,Java和Groovy、Kotlin</p>
  843. </div>
  844. <div class="listingblock primary">
  845. <div class="title">Maven</div>
  846. <div class="content">
  847. <pre class="highlight"><code class="language-xml" data-lang="xml">&lt;dependency&gt;
  848. &lt;groupId&gt;com.example&lt;/groupId&gt;
  849. &lt;artifactId&gt;some-library&lt;/artifactId&gt;
  850. &lt;version&gt;1.2.3&lt;/version&gt;
  851. &lt;/dependency&gt;</code></pre>
  852. </div>
  853. </div>
  854. <div class="listingblock secondary">
  855. <div class="title">Gradle</div>
  856. <div class="content">
  857. <pre class="highlight"><code>compile 'com.example:some-library:1.2.3'</code></pre>
  858. </div>
  859. </div>
  860. </div>
  861. <div class="sect3">
  862. <h4 id="_code_folding"><a class="anchor" href="#_code_folding"></a>4.3.7. Code Folding</h4>
  863. <div class="paragraph">
  864. <p>折叠部分非核心代码,例如Java代码的import或者getter、setter</p>
  865. </div>
  866. <div class="listingblock">
  867. <div class="content">
  868. <pre class="highlight"><code class="language-java" data-lang="java"><span class="fold-block">public class Example {
  869. private String first;
  870. private String second;
  871. </span><span class="fold-block hide-when-unfolded"> // getters / setters...
  872. </span><span class="fold-block hide-when-folded"> public String getFirst() {
  873. return this.first;
  874. }
  875. public void setFirst(String first) {
  876. this.first = first;
  877. }
  878. public String getSecond() {
  879. return this.second;
  880. }
  881. public void setSecond(String second) {
  882. this.second = second;
  883. }
  884. </span><span class="fold-block">}
  885. </span></code></pre>
  886. </div>
  887. </div>
  888. </div>
  889. <div class="sect3">
  890. <h4 id="_different_config_blocks"><a class="anchor" href="#_different_config_blocks"></a>4.3.8. Different Config Blocks</h4>
  891. <div class="paragraph">
  892. <p>configblocks用于生成同一配置的yaml格式和properties格式,例如下面的源文件和渲染后效果</p>
  893. </div>
  894. <div class="listingblock">
  895. <div class="content">
  896. <pre>[source,yaml,configblocks]
  897. ----
  898. example:
  899. property:
  900. alpha: a
  901. ----</pre>
  902. </div>
  903. </div>
  904. <div class="listingblock primary">
  905. <div class="title">Properties</div>
  906. <div class="content">
  907. <pre class="highlight"><code class="language-properties" data-lang="properties">example.property.alpha=a</code></pre>
  908. </div>
  909. </div>
  910. <div class="listingblock secondary">
  911. <div class="title">Yaml</div>
  912. <div class="content">
  913. <pre class="highlight"><code class="language-yaml" data-lang="yaml">example:
  914. property:
  915. alpha: a</code></pre>
  916. </div>
  917. </div>
  918. <div class="admonitionblock note">
  919. <table>
  920. <tr>
  921. <td class="icon">
  922. <i class="fa icon-note" title="Note"></i>
  923. </td>
  924. <td class="content">
  925. 此功能还需要添加 <code>io.spring.asciidoctor:spring-asciidoctor-extensions-spring-boot</code> 依赖,参考 <a href="https://github.com/spring-io/spring-asciidoctor-extensions">spring-asciidoctor-extensions</a>
  926. </td>
  927. </tr>
  928. </table>
  929. </div>
  930. </div>
  931. </div>
  932. <div class="sect2">
  933. <h3 id="_bilibili_extension"><a class="anchor" href="#_bilibili_extension"></a>4.4. Bilibili Extension</h3>
  934. <div class="paragraph">
  935. <p>文档中插入视频是很常见的需求,可能是需要记录视频教程的学习笔记,也可能是使用视频对文档的内容做进一步说明。
  936. 默认Asciidoctor仅支持在文档中插入Youtube、vimeo视频或者本地视频文件,但国内开发者更多使用的是Bilibili,
  937. 因此开发了 <code>asciidoctor-bilibili-extension</code> 用于向AsciiDoc文档中插入Bilibili视频,
  938. 详细用法参考 <a href="https://github.com/pxzxj/asciidoctor-bilibili-extension">asciidoctor-bilibili-extension</a>。</p>
  939. </div>
  940. <div class="videoblock"><div class="content">
  941. <iframe width="640" height="480" src="https://player.bilibili.com/player.html?bvid=BV12t411m7RV&high_quality=1&page=1" border="0" frameborder="no" framespacing="0" scrolling="no" allowfullscreen="true"></iframe>
  942. </div></div>
  943. </div>
  944. </div>
  945. </div>
  946. <div class="sect1">
  947. <h2 id="_examples"><a class="anchor" href="#_examples"></a>5. Examples</h2>
  948. <div class="sectionbody">
  949. <div class="paragraph">
  950. <p>Asciidoctor提供了大量的 <a href="https://github.com/asciidoctor/asciidoctor-maven-examples">Maven示例</a>用于说明相关功能,本文选择常用的几类进行说明</p>
  951. </div>
  952. <div class="sect2">
  953. <h3 id="_html"><a class="anchor" href="#_html"></a>5.1. Html</h3>
  954. <div class="paragraph">
  955. <p>参考 <a href="https://github.com/asciidoctor/asciidoctor-maven-examples/tree/main/asciidoc-to-html-example">asciidoc-to-html-example</a>,也可以参考<a href="#cicd">CI/CD示例</a>。</p>
  956. </div>
  957. </div>
  958. <div class="sect2">
  959. <h3 id="_pdf"><a class="anchor" href="#_pdf"></a>5.2. Pdf</h3>
  960. <div class="paragraph">
  961. <p>参考 <a href="https://github.com/asciidoctor/asciidoctor-maven-examples/tree/main/asciidoctor-pdf-cjk-example">asciidoctor-pdf-cjk-example</a>,也可以参考<a href="#cicd">CI/CD示例</a>。</p>
  962. </div>
  963. </div>
  964. <div class="sect2">
  965. <h3 id="cicd"><a class="anchor" href="#cicd"></a>5.3. CI/CD</h3>
  966. <div class="paragraph">
  967. <p><code>Docs as Code</code> 要求文档同代码一样能够在CI/CD流水线中自动发布,例如可以将生成的html文件部署到nginx搭建的站点上就可以直接在浏览器中查看文档了,
  968. 由于文档是使用Maven插件生成的,因此整个发布过程与普通Java项目没有任何区别。
  969. 本文使用 <code>GitHub Action</code> 以及 <code>GitHub Pages</code> 演示CI/CD过程,示例代码参考 <a href="https://github.com/pxzxj/asciidoc-cicd-demo">asciidoc-cicd-demo</a>。</p>
  970. </div>
  971. </div>
  972. <div class="sect2">
  973. <h3 id="_doc_review"><a class="anchor" href="#_doc_review"></a>5.4. Doc Review</h3>
  974. <div class="paragraph">
  975. <p>代码需要评审,文档也一样,通过文档评审可以逐步提升文档质量以及团队文档编写能力。</p>
  976. </div>
  977. <div class="paragraph">
  978. <p>GitHub和GitLab都提供了强大的 <code>Review</code> 功能,可以对PR的内容进行评审和讨论,只有评审通过的内容才会合并。
  979. 以Spring Boot项目中的一个对 <code>README.adoc</code> 润色的 <a href="https://github.com/spring-projects/spring-boot/pull/28835">PR</a>为例,
  980. Spring成员查看提交的内容并提出疑问,原作者进行回复</p>
  981. </div>
  982. <div class="imageblock">
  983. <div class="content">
  984. <img src="images/doc-review.png" alt="doc review">
  985. </div>
  986. </div>
  987. </div>
  988. </div>
  989. </div>
  990. <div class="sect1">
  991. <h2 id="_style"><a class="anchor" href="#_style"></a>6. Style</h2>
  992. <div class="sectionbody">
  993. <div class="paragraph">
  994. <p>上文主要讨论了编写技术文档使用的工具,而文档编写的另一个重要主题是写作规范,
  995. 使用陈述句还是祈使句、使用第一人称还是第二人称等等这些语法细节也会影响最终文档的质量。</p>
  996. </div>
  997. <div class="paragraph">
  998. <p>Spring就非常重视文档写作规范, <a href="https://github.com/spring-io/spring-asciidoctor-backends/blob/main/guides/style-guide.adoc">spring-style</a>详细描述了编写Spring技术文档相关规范,
  999. 同时还根据开发者反馈对文档不断进行 <a href="https://github.com/spring-projects/spring-boot/issues/27895">优化</a>,可以说完善的文档也是Spring框架如此成功的重要原因之一。</p>
  1000. </div>
  1001. <div class="paragraph">
  1002. <p>Kubernetes的文档规范参考 <a href="https://kubernetes.io/docs/contribute/style/style-guide/">Documentation Style Guide</a></p>
  1003. </div>
  1004. <div class="paragraph">
  1005. <p>中文技术领域目前比较受开发者认可的是由阮一峰编写的 <a href="https://www.ruanyifeng.com/blog/2016/10/document_style_guide.html">中文技术文档的写作规范</a>,GitHub的Star数量已经接近一万。</p>
  1006. </div>
  1007. </div>
  1008. </div>
  1009. <div class="sect1">
  1010. <h2 id="_best_practice"><a class="anchor" href="#_best_practice"></a>7. Best Practice</h2>
  1011. <div class="sectionbody">
  1012. <div class="olist arabic">
  1013. <ol class="arabic">
  1014. <li>
  1015. <p>先列举文档的目录,再补充各章节的内容。</p>
  1016. </li>
  1017. <li>
  1018. <p>参考优秀的开源项目文档。</p>
  1019. </li>
  1020. <li>
  1021. <p>内容为王,时间紧急情况下优先保证内容,其次考虑格式美观。</p>
  1022. </li>
  1023. <li>
  1024. <p><strong>写</strong>,立即开始。</p>
  1025. </li>
  1026. </ol>
  1027. </div>
  1028. </div>
  1029. </div>
  1030. </div>
  1031. <div id="footer">
  1032. <div id="footer-text">
  1033. Last updated 2024-03-18 05:44:42 UTC
  1034. </div>
  1035. </div>
  1036. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
  1037. <script>
  1038. if (!hljs.initHighlighting.called) {
  1039. hljs.initHighlighting.called = true
  1040. ;[].slice.call(document.querySelectorAll('pre.highlight > code')).forEach(function (el) { hljs.highlightBlock(el) })
  1041. }
  1042. </script>
  1043. <script src="https://utteranc.es/client.js"
  1044. repo="pxzxj/articles"
  1045. issue-term="title"
  1046. label="utteranc"
  1047. theme="github-light"
  1048. crossorigin="anonymous"
  1049. async>
  1050. </script>
  1051. </div>
  1052. </div>
  1053. </div>
  1054. </body>
  1055. </html>