1. Project
1.1. Description
Nowadays, projects hosted on GitHub often use a documentation-as-code, where documentation is written as text using formatting such as Markdown or Asciidoc.
AsciiDoc is used here because this formatting offers much higher flexibility and features than Markdown.
AsciiDoc is as simple as Markdown, for things that are doable in Markdown.
This Cookbook uses Asciidoctor is a fast text processor and publishing toolchain for converting AsciiDoc content to HTML5, EPUB3, PDF, DocBook 5
And for Confluence publishing, confluence-publisher allows, through a pre-defined set of folder structure to publish pages one-to-one with Confluence page hierarchical structure.
PlantUML is used to produce various diagrams from text, and Mingrammer python language for Architecture or deployment diagrams.
At last, few if/else are used (only at top of each adoc pages) to allow the documentation to be rendered on multiple targets:
-
GITHUB
-
PDF
-
HTML
-
Confluence
1.2. Tools
General tools enabling Doc-as-Code:
Writing text:
-
Visual Studio Code and plugins for PlantUML and AsciiDoc.
Diagrams:
-
Architecture with Mingrammer Diagrams
-
Classes, Use case, Flow diagrams with PlantUML
Publishing
-
To PDF/HTML/EPUB : AsciiDoctor
-
To Confluence : Confluence-Publisher
2. How-To
This chapter shows how to edit and publish documentation to the various destination mentioned above.
2.1. Pre-Requisits
$ make build
2.2. Editing
Using Visual Studio Code, install plugings such as AsciiDoc in order to render the .adoc files.
Follow syntax as documented in AsciiDoctor User Manual
2.3. Mingrammer Diagrams (standalone)
Mingrammer is tool of choice for architecture diagram as code.
Files are standard python files, easily understandable.
See example at assets-architecture-hla.py
Building assets is already part of next commands used to publish to PDF or Confluence. |
# Create python assets under *src/main/adoc/assets* folder (e.g. assets-architecture-hla.py)
$ make doc.publishAssets
# PNG files will be available under *build/adoc/images* folder (e.g. assets-architecture-hla.png)
2.4. Publishing
Building and Publishing the documentation can be done with targets:
-
Confluence
-
HTML
-
PDF Book
2.4.1. Editing/Publishing to PDF
Obviously, PDF are published in the form of Books while Confluence are set of Pages.
This make somewhat of a difference, but same doc can however be published to both targets.
_SampleProject-Book.adoc holds the book, which is essentially a structured set of includes from the various adoc files used to publish to Confluence.
See Theming Guide |
$ make doc.publishToPDF
The published documentation PDF book will be found under build/_SampleProject-Book.pdf |
2.4.2. Editing/Publishing to Confluence
This requires a Confluence instance, but thankfully a temporary instance can be started on localhost for testing.
$ confluence.start # Wait a bit for this to settle !
$ confluence.logs
$ confluence.stop
$ confluence.clean
Confluence comes from https://github.com/confluence-publisher/confluence-publisher-it Confluence is available at http://localhost:8090 The following users are configured: |
This is about editing the multiple adoc files starting from 00-Index.adoc, and recursively the folder with same name, etc
Each Confluence page is matching an adoc file, and title is the top first section.
Sub-pages are the recursive folder themselves holding other adoc files.
See Confluence Publisher GIT for details.
From current folder, edit the file named .env-confluence with your credentials. Don’t edit anything else.
ANCESTOR_ID is found by browsing Confluence page and clicking Edit button. |
$ make doc.publishToConfluence
The Confluence page will be found under the project page defined as ANCESTOR_ID. |
3. Template
This page demonstrates some of what could be found in an Asciidoc documentation.
3.1. Images
Sample Mingrammer python diagram:
See How-To in Mingrammer Diagrams section for details. |
3.2. Listing
This block is used to skip rendering.
= Document Title
3.3. Sources Block
This block is used to embed a chunk of file or code.
Source blocks are converted using the "code" macro. Only languages supported by the Code Block Macro can be used:
actionscript3
, applescript
, bash
, c#
, cpp
, css
, coldfusion
, delphi
, diff
, erl
, groovy
,
xml
, java
, jfx
, js
, php
, perl
, text
, powershell
, py
, ruby
, sql
, sass
, scala
,
vb
, yml
(since Confluence 6.7 only)
Example XML block:
<build>
<plugins>
<plugin>
<groupId>org.sahli.asciidoc.confluence.publisher</groupId>
<artifactId>asciidoc-confluence-publisher-maven-plugin</artifactId>
<version><!-- insert version here --></version>
<configuration>
<asciidocRootFolder>etc/docs</asciidocRootFolder>
<sourceEncoding>UTF-8<sourceEncoding> <!-- default -->
<rootConfluenceUrl>http://localhost:8090</rootConfluenceUrl>
<skipSslVerification>false</skipSslVerification>
<spaceKey>SPACE</spaceKey>
<ancestorId>327706</ancestorId>
<username>username</username> <!-- or read from property -->
<password>password</password> <!-- or read from property -->
<pageTitlePrefix xml:space="preserve">Doc :: </pageTitlePrefix>
<pageTitleSuffix xml:space="preserve"> [${project.version}]</pageTitleSuffix>
<versionMessage>Version ${project.version}</versionMessage>
<attributes>
<version>${project.version}</version>
<someOtherKey>value</someOtherKey>
</attributes>
</configuration>
</plugin>
</plugins>
</build>
Example Java block:
public class MyCode {
// comment
}
3.4. Source Blocks from External Files (Full Content)
Including source code from external files is supported:
public class Source {
// code from included source file
}
3.5. Source Blocks from External Files (Partial Content)
Restricting the source code to be included based on tags is supported:
public void myMethod() {
// method from included source file
}
Other advanced features like listing file names or callouts are not supported. |
3.6. Tables
Example simple Table:
Configuration Property | Description | Constraint |
---|---|---|
rootConfluenceUrl |
The root URL of the Confluence instance to publish to. |
mandatory |
ancestorId |
The id of the ancestor page under which the pages are appended. |
mandatory |
password |
The password of the user to use for publishing. |
mandatory |
publishingStrategy |
The strategy to use when publishing to confluence. Possible values:
|
optional (defaults to |
3.7. Attachments
If an AsciiDoc file references a non-AsciiDoc file (e.g. a text file, PDF, …) that non-AsciiDoc file is automatically added as an attachment to the corresponding Confluence page. Referenced non-AsciiDoc files are resolved relative to the location of the referencing AsciiDoc file.
Attachment links may specify a label.
3.8. Includes
Include files must be prefixed with an underscore. |
This is content from included file
3.9. Links within Pages
Links to content blocks within the same page are supported using AsciiDoc inline anchors and internal cross references:
Another paragraph with internal cross-reference to [paragraph-a]
Links to sections within the same page are supported either using anchors or custom section ids:
3.9.1. Section with Anchor
Paragraph with internal cross-reference to Section with Anchor
3.9.2. Section with Custom Id
Paragraph with internal cross-reference to Section with Custom Id
Links from one page to an inline anchor within another page are currently not supported. |
3.10. Paragraphs
AsciiDoc paragraphs are translated to Confluence paragraphs, supporting all typical styles, for example:
This is a paragraph with bold text.
This is a paragraph with italic text.
This is a paragraph with monospaced
text.
This is a paragraph with monospaced bold italic
text.
This is a paragraph with superscript and subscript text.
The title of a paragraph will rendered using a custom CSS class cp-paragraph-title
4. Diagrams
Here are diagrams which are automatically generated from text.
See PlantUML docs for details.
4.1. MindMap & Breakdown
4.2. Network
4.3. Activity diagram
4.4. Gant diagram
4.5. C4 diagrams
4.6. Relation diagram
4.7. UI diagram
4.8. Class diagram
4.9. Sequence diagram
4.10. Time diagram
5. Cross-References
5.1. Examples
Examples of Doc As Code source repository and rendering below.
Not all are using AsciiDoc, however the principle remains the same with text source getting processed and rendered to different targets:
-
Microsoft docs with 2000 repos (with per language repo): Microsoft Docs repos in GIT
-
One of the doc source and rendered:
-
-
Docker
-
Amazon user guides:
5.2. Demo
5.4. Applications & Tools
ASCIIDOC is tool of choice for all Designs, Architecture, Deployment Guides and User Guides.
-
Applications:
-
DocToolChain and DocToolChain GIT TOBETESTED more
-
Asciidoc FX with Asciidoc FX GIT TOBETESTED
-
Chrome extensions:
-
Sources:
-
Sanitize/Linters:
-
GitPitch