README.adoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. = Asciidoctor Spring Backends
  2. Alternative HTML conversion for Asciidoctor with a Spring "look and feel".
  3. == Maven build integration
  4. You can use the https://github.com/asciidoctor/asciidoctor-maven-plugin[Asciidoctor Maven plugin] to generate your documentation.
  5. [source,xml]
  6. ----
  7. <plugin>
  8. <groupId>org.asciidoctor</groupId>
  9. <artifactId>asciidoctor-maven-plugin</artifactId>
  10. <version>2.1.0</version>
  11. <executions>
  12. <execution>
  13. <id>generate-html-documentation</id>
  14. <phase>prepare-package</phase>
  15. <goals>
  16. <goal>process-asciidoc</goal>
  17. </goals>
  18. <configuration>
  19. <backend>spring-html</backend>
  20. </configuration>
  21. </execution>
  22. </executions>
  23. <dependencies>
  24. <dependency>
  25. <groupId>io.spring.asciidoctor.backends</groupId>
  26. <artifactId>spring-asciidoctor-backends</artifactId>
  27. <version>${spring-asciidoctor-backends.version}</version>
  28. </dependency>
  29. </dependencies>
  30. </plugin>
  31. ----
  32. == Gradle build integration
  33. You can use the https://asciidoctor.org/docs/asciidoctor-gradle-plugin/[Asciidoctor Gradle plugin] to generate your documentation.
  34. [source,gradle]
  35. ----
  36. plugins {
  37. id 'org.asciidoctor.jvm.convert' version '3.1.0'
  38. }
  39. configurations {
  40. asciidoctorExtensions
  41. }
  42. dependencies {
  43. asciidoctorExtensions "io.spring.asciidoctor.backends:spring-asciidoctor-backends:${spring-asciidoctor-backends.version}"
  44. }
  45. asciidoctor {
  46. configurations "asciidoctorExtensions"
  47. sourceDir "src/asciidoc"
  48. outputOptions {
  49. backends "spring-html"
  50. }
  51. }
  52. ----
  53. == Features
  54. === Spring Look and Feel
  55. Spring specific stylesheets and javascript are produced with each HTML file that provides a Spring "look and feel".
  56. As much as possible, styling mirrors the look of https://spring.io[spring.io].
  57. One minor difference between the documentation output and https://spring.io[spring.io] is the choice of fonts.
  58. Since documentation tends to contain more content, we use system default fonts rather than "Metropolis" or "Open Sans".
  59. This aligns with https://markdotto.com/2018/02/07/github-system-fonts/[GitHub's font choice] and tends to produce better results then using a custom font.
  60. === Responsive Design
  61. Generated HTML includes responsive selectors that mean it should work well across a range of devices.
  62. We specifically optimize for desktop, tablet (both horizontal and vertical orientation) and smartphone.
  63. === Graceful Javascript Degradation
  64. Documentation pages generated by this backend should render correctly even if Javascript has been disabled.
  65. Some features will not appear if the user has disabled Javascript.
  66. === "Back to Index" Link
  67. For HTML output, if the current page is not `index.html`, you automatically get a link to `index.html`.
  68. This link appears above the table of contents.
  69. For many projects, this link never appears, because that project's build renders the documentation as `index.html`.
  70. You can customize the destination of the "Back to Index" link by specifying a `index-link` attribute in your document.
  71. For example, the following attribute would link to `https://spring.io`:
  72. [source, asciidoctor]
  73. ----
  74. :index-link: https://spring.io
  75. ----
  76. NOTE: Please do use a link that readers might reasonably think would be an index page.
  77. (The canonical case is the project's page on spring.io.)
  78. === Dark Mode
  79. A "dark mode" switcher is included at the top of each page.
  80. By default the theme will match the users system preferences, but it can be switched easily.
  81. Dark mode settings are saved using local storage so that the user doesn't need to change them on each reload.
  82. === Copy to Clipboard
  83. Code blocks have an additional "Copy to clipboard" button that appears when the user hovers over the block.
  84. The unfolded (see below) version of the code text is always used when copying to the clipboard.
  85. === Tabs
  86. Tab support is included in the site Javascript and can be used without needing the `spring-asciidoctor-extensions-block-switch` extension.
  87. The Javascript post-processes Asciidoctor's HTML output to collapse multiple blocks into one and provides tabs that can be used to switch between them.
  88. To use tabs, one block must have the `role="primary"` attribute, and one or more blocks must have a `role="secondary"` attribute.
  89. The tabs are named using the block titles.
  90. For example:
  91. [source,subs="verbatim,attributes"]
  92. ....
  93. [source,xml,indent=0,role="primary"]
  94. .Maven
  95. ----
  96. <dependency>
  97. <groupId>com.example</groupId>
  98. <artifactId>some-library</artifactId>
  99. <version>1.2.3</version>
  100. </dependency>
  101. ----
  102. [source,indent=0,role="secondary"]
  103. .Gradle
  104. ----
  105. compile 'com.example:some-library:1.2.3'
  106. ----
  107. ....
  108. You can also use blocks for more complex markup:
  109. [source,subs="verbatim,attributes"]
  110. ....
  111. [primary]
  112. .Maven
  113. --
  114. [source,xml,indent=0]
  115. ----
  116. <dependency>
  117. <groupId>com.example</groupId>
  118. <artifactId>some-library</artifactId>
  119. <version>1.2.3</version>
  120. </dependency>
  121. ----
  122. TIP: XML uses angle brackets.
  123. --
  124. [secondary]
  125. .Gradle
  126. --
  127. I can write things here.
  128. [source,indent=0]
  129. ----
  130. compile 'com.example:some-library:1.2.3'
  131. ----
  132. --
  133. ....
  134. === Code Folding
  135. Code folding allows non-pertinent sections of code to be hidden away for the majority of the time.
  136. The user can click on an "unfold code" button if they want to see the full code.
  137. Code folding is particularly useful when code samples have been externalized.
  138. There's often details needed to make the compiler happy that aren't all that relevant to the documentation.
  139. By default, all java imports will be automatically folded.
  140. Additional "fold" sections can also be defined using special `@fold:on` and `@fold:off` comments.
  141. For example, the following Java file will fold-away the fields:
  142. [source,subs="verbatim,attributes"]
  143. ....
  144. [source,java]
  145. ----
  146. public class Example {
  147. // @fold:on
  148. private final String first;
  149. private final String second;
  150. // @fold:off
  151. public Example(String first, String second) {
  152. this.first = first;
  153. this.second = second;
  154. }
  155. }
  156. ----
  157. ....
  158. You can also include replacement text that will be displayed when the code is folded.
  159. For example, the following Java file will show a `+++// getters / setters...+++` comment when the code is folded:
  160. [source,subs="verbatim,attributes"]
  161. ....
  162. [source,java]
  163. ----
  164. public class Example {
  165. private String first;
  166. private String second;
  167. // @fold:on // getters / setters...
  168. public String getFirst() {
  169. return this.first;
  170. }
  171. public void setFirst(String first) {
  172. this.first = first;
  173. }
  174. public String getSecond() {
  175. return this.second;
  176. }
  177. public void setSecond(String second) {
  178. this.second = second;
  179. }
  180. // @fold:off
  181. }
  182. ----
  183. ....
  184. You can use the `fold` attribute if you want change the default settings.
  185. The attribute can be used on the document or the block.
  186. The attribute value is a space delimited list containing one or more of the following flags:
  187. |===
  188. | Flag | Description
  189. | `default`
  190. | `imports` `tags`
  191. | `all`
  192. | Enable all folding
  193. | `none`
  194. | Disable all folding
  195. | `imports`
  196. | Fold import statements
  197. | `tags`
  198. | Fold `@fold:on` / `@fold:off` tags
  199. |===
  200. You can prefix the flag with `+` or `-` at the block level if you want to override a document setting.
  201. === Code Chomping
  202. Code chomping allows specific parts of a Java code block to be removed.
  203. It's mainly useful if you have externalized code files with details that are only required to make the compiler happy.
  204. By default, chomping will remove parts of the code that match specific comments as well as `@formatter:on`/`@formatter:off` comments.
  205. You can also turn on addition chomping for `headers`, `packages`
  206. The following chomp comments are supported:
  207. |===
  208. | Comment | Description
  209. | `/* @chomp:line <replacement> */`
  210. | Chomps the rest of the line and adds the replacement
  211. | `// @chomp:file`
  212. | Chomps the remainder of the file
  213. | `/**/`
  214. | Chomps the rest of the line and adds `+++...+++`
  215. |===
  216. For example, the following file:
  217. [source,subs="verbatim,attributes"]
  218. ....
  219. [source,java]
  220. ----
  221. public class Example {
  222. private final Something something;
  223. private final Other other;
  224. public Example() {
  225. this.something = /**/ new MockSomething();
  226. this.other = /* @chomp:line ... your thing */ new MyThing();
  227. }
  228. }
  229. ----
  230. ....
  231. Will be rendered as:
  232. [source,subs="verbatim,attributes"]
  233. ....
  234. public class Example {
  235. private final Something something;
  236. private final Other other;
  237. public Example() {
  238. this.something = ...
  239. this.other = ... your thing
  240. }
  241. }
  242. ....
  243. You can use the `chomp` attribute if you want change the default settings.
  244. The attribute can be used on the document or the block.
  245. The attribute value is a space delimited list containing one or more of the following flags:
  246. |===
  247. | Flag | Description
  248. | `default`
  249. | `tags` `formatters` `suppresswarnings`
  250. | `all`
  251. | Enable all chomping
  252. | `none`
  253. | Disable all chomping
  254. | `headers`
  255. | Chomp any file headers (up to `package`)
  256. | `packages`
  257. | Chomp the package declaration or replaces it with `chomp_package_replacement`
  258. | `tags`
  259. | Chomp on the comment tags listed above
  260. | `formatters`
  261. | Chomp any `@formatter:on`/`@formatter:off` comments
  262. | `suppresswarnings`
  263. | Chomp any `@SuppressWarnings` annotations
  264. |===
  265. You can prefix the flag with `+` or `-` at the block level if you want to override a document setting.
  266. The `chomp_package_replacement` attribute can be set on the block or the document if you want to replace the package rather than remove it.
  267. For example, the following document will replace all package declarations with `package com.example;`:
  268. [source,subs="verbatim,attributes"]
  269. ....
  270. = My Document
  271. :chomp_package_replacement: com.example
  272. ....
  273. === Anchor Rewriting
  274. Anchor rewriting can be used if you need to evolve a document and change previously published anchor links.
  275. For example, say you publish a document with the following typo:
  276. [source,asciidoctor]
  277. ----
  278. [[initializzzing]]
  279. == Initializing
  280. This is how to do it.
  281. ----
  282. You then fix the typo and publish a new revision:
  283. [source,asciidoctor]
  284. ----
  285. [[initializing]]
  286. == Initializing
  287. This is how to do it.
  288. ----
  289. You can add a rewrite rule so that any links to `+++https://example.com/doc#initializzzing+++` will be automatically changed to `+++https://example.com/doc#initializing+++`.
  290. To define the rewrite rules, add a `anchor-rewrite.properties` file to your `base_dir` (usually the same directory as your `index.adoc` file).
  291. For example, the following file would be used in the example above:
  292. [source,properties]
  293. .anchor-rewrite.properties
  294. ----
  295. initializzzing=initializing
  296. ----
  297. === Convention Based Code Import
  298. Convention based code imports allows you to quickly import code snippets from package names that are constructed using the section ID.
  299. For example, the following `.adoc` file will try to import the Java file `{docs-java}/my/exampleproject/SomeCode.java`.
  300. [source,subs="verbatim,attributes"]
  301. ....
  302. [[my.example-project]]
  303. == My Example Project
  304. include::code:SomeCode[]
  305. ....
  306. The following languages are supported by convention based imports:
  307. |===
  308. | Language | Root Directory Property | Extension
  309. | Java
  310. | `{docs-java}`
  311. | `.java`
  312. | Kotlin
  313. | `{docs-kotlin}`
  314. | `.kt`
  315. | Groovy
  316. | `{docs-groovy}`
  317. | `.grovy`
  318. |===
  319. If more than one language file is found then tabs will automatically be created to allow the user to see all the examples.
  320. An exception will be raised if no files are found.
  321. The package name is constructed by removing all `-` characters from the section ID and replacing all `.`'s with `/`.
  322. === Font Awesome Support
  323. Font Awesome support is available in the standard Asciidoctor HTML 5 backend, however, it is not available by default in this backend.
  324. This is to align with https://antora.org[Antora], which https://gitlab.com/antora/antora-ui-default/-/issues/58[doesn't currently support Font Awesome].
  325. If you want to enable Font Awesome 4 support in your documents you can set the `iconfont-fontawesome` attribute.
  326. This will allow you to use `+++icon:<name>[]+++` macros inside your markup, with images being resolved from the locally bundled `fontawesome.css` stylesheet.
  327. For example:
  328. [source,asciidoctor]
  329. ----
  330. = Asciidoctor Font Awesome Document
  331. :iconfont-fontawesome:
  332. The folder icon is icon:folder[].
  333. ----
  334. == Contributing
  335. If you're looking to contribute to this project, or you're just trying to navigate the code please take a look at the link:CONTRIBUTING.adoc[CONTRIBUTING] file.
  336. == License
  337. With the exception of link:src/main/css/asciidoctor.css[`asciidoctor.css`], use of this software is granted under the terms of the https://www.apache.org/licenses/LICENSE-2.0[Apache License, Version 2.0] (Apache-2.0).
  338. See link:LICENSE.txt[] to find the full license text.
  339. The contents of link:src/main/css/asciidoctor.css[`src/main/css/asciidoctor.css`] have been derived from https://gitlab.com/antora/antora-ui-default/-/blob/8751b86b76d6779fbbcf0fccd58fafcf73c49260/src/css/doc.css[gitlab.com/antora/antora-ui-default CSS] and as such use of this file alone is granted under the terms of the https://www.mozilla.org/en-US/MPL/2.0/[Mozilla Public License Version 2.0] (MPL-2.0).