|
| 1 | += AsciiDoc Syntax Style Guide |
| 2 | + |
| 3 | +== Inline Syntax |
| 4 | + |
| 5 | +=== Inline Semantics |
| 6 | + |
| 7 | +The main purpose of inline semantics is to provide a clear indication of the role of the text to the reader -- including artificial readers. |
| 8 | + |
| 9 | +We can convey semantics by way of: |
| 10 | + |
| 11 | +* declaration by element, role, or class |
| 12 | +* text style based on declaration |
| 13 | +* browser effects based on declaration and additional data |
| 14 | + |
| 15 | +We use the following inline semantic coding in DocOps Lab publications. |
| 16 | + |
| 17 | +// include::built/inline-semantics.adoc[] |
| 18 | + |
| 19 | +=== Syntax Preferences |
| 20 | + |
| 21 | +Use inline semantics liberally, even if you only insert the heavier syntax on a second or third pass. |
| 22 | + |
| 23 | +Formatting with simple `+++*+++`, `_`, and `+++`+++` characters on first drafting makes lots of sense -- or even missing some of these altogether until the second pass. |
| 24 | + |
| 25 | +But before you merge new text documents into your codebase, add role-based inline semantics wherever they are supported. |
| 26 | + |
| 27 | +Let the reader know and make use of special text, most importantly any *verbatim inline text*. |
| 28 | +// TODO: Add link to Docs-as-Code School lesson on "Inline Semantics" when available |
| 29 | +// link:[See the Docs-as-Code School lesson "`Inline Semantics`" for more.] |
| 30 | + |
| 31 | +Even if you are not ready to add such fine-grained tests to your pipeline, consider the value of having all your commands for a given runtime app labeled ahead of time (such as `.app-ruby`), and the advantage to the reader, as well. |
| 32 | + |
| 33 | +== Block Syntax |
| 34 | + |
| 35 | +// tag::block-semantics[] |
| 36 | +=== Block Semantics |
| 37 | + |
| 38 | +Use semantic indicators deliberately. |
| 39 | + |
| 40 | +The more you assert about a block of text you are writing, the better the placement and content of that block will be. |
| 41 | + |
| 42 | +Semantic assertions reside in the source markup, which may convey means of interpreting that same data visually in the output, as an indication to the reader. |
| 43 | + |
| 44 | +For instance, _warning_ admonitions should only deliver warning content, and the user should clearly see that a warning is interrupting the flow of the content in which it appears. |
| 45 | + |
| 46 | +// tag::warning-example-good[] |
| 47 | +[source,asciidoc] |
| 48 | +-------- |
| 49 | +[WARNING] |
| 50 | +==== |
| 51 | +Avoid misusing or overusing admonition blocks. |
| 52 | +==== |
| 53 | +-------- |
| 54 | +// end::warning-example-good[] |
| 55 | + |
| 56 | +Semantic notations in our source remind us to treat the content properly. |
| 57 | + |
| 58 | +// tag::warning-example-bad[] |
| 59 | +[source,asciidoc] |
| 60 | +-------- |
| 61 | +[WARNING] |
| 62 | +==== |
| 63 | +Avoid misusing or overusing admonition blocks. |
| 64 | +This will be hypocritically violated throughout this guide. |
| 65 | +==== |
| 66 | +-------- |
| 67 | +// end::warning-example-bad[] |
| 68 | + |
| 69 | +True as it may be, the second sentence in that admonition should be removed from the block. |
| 70 | +It can either be its own block, or it can be allowed to fade into the surrounding content. |
| 71 | + |
| 72 | +Sometimes the entire admonition may end up deserving this treatment. |
| 73 | + |
| 74 | +=== Use Delimited Blocks |
| 75 | + |
| 76 | +Generally, use explicit boundary lines to wrap significant blocks, rather than relying on other syntax cues to establish the "`type`" of block is intended. |
| 77 | +These lines are called link:https://docs.asciidoctor.org/asciidoc/latest/blocks/delimited/#linewise-delimiters[_linewise delimiters_]. |
| 78 | + |
| 79 | +For example, use the following syntax to wrap the contents of an admonition block: |
| 80 | + |
| 81 | +.Example admonition block syntax with linewise delimiter |
| 82 | +======== |
| 83 | +[source,asciidoc] |
| 84 | +-------- |
| 85 | +[NOTE] |
| 86 | +==== |
| 87 | +The content of an admonition block should be sandwiched between `====` lines. |
| 88 | +Use one-sentence-per-line even in admonitions. |
| 89 | +==== |
| 90 | +-------- |
| 91 | +======== |
| 92 | + |
| 93 | +The standard linewise delimiters for various AsciiDoc blocks are as follows: |
| 94 | + |
| 95 | +// tag::delimited-blocks-reference[] |
| 96 | +[horizontal] |
| 97 | +`====`:: For _admonitions_ and _examples_ |
| 98 | +`----`:: For code listing (verbatim) blocks |
| 99 | +`+++....+++`:: For literal (verbatim) blocks |
| 100 | +`+++****+++`:: For sidebar blocks |
| 101 | +`|===`:: For tables |
| 102 | +`+++____+++`:: For quote blocks |
| 103 | +`pass:[++++]`:: For raw/passthrough blocks |
| 104 | +`--`:: For open blocks |
| 105 | +// end::delimited-blocks-reference[] |
| 106 | + |
| 107 | +For code listings, literals, or really any block that might contain text that could be confused with the delimiter, vary the length by using a greater number of delimiter characters on the _outer_ block. |
| 108 | + |
| 109 | +.Example "`example`" block containing an admonition block |
| 110 | +[source,asciidoc] |
| 111 | +-------- |
| 112 | +[example] |
| 113 | +======== |
| 114 | +[NOTE] |
| 115 | +==== |
| 116 | +This is an example block containing an admonition block. |
| 117 | +==== |
| 118 | +======== |
| 119 | +-------- |
| 120 | + |
| 121 | +==== Exception: Brief admonitions |
| 122 | + |
| 123 | +Some blocks do not require delimiters. |
| 124 | +In cases of _repeated_, _nearly identical_ blocks, containing just one line of content, you can use the _single-line_ syntax where it is available. |
| 125 | + |
| 126 | +.Example single-line admonition block syntax |
| 127 | +[source,asciidoc] |
| 128 | +-------- |
| 129 | +NOTE: This is a single-line admonition block. |
| 130 | +-------- |
| 131 | + |
| 132 | +Exception to this exception:: |
| 133 | ++ |
| 134 | +-- |
| 135 | +We do not recommend the same-line syntax for admonition blocks other than `NOTE` and `TIP`. |
| 136 | +For `IMPORTANT`, `CAUTION`, and `WARNING`, use at least the 2-line syntax, if not explicit delimiters. |
| 137 | + |
| 138 | +[source,asciidoc] |
| 139 | +-------- |
| 140 | +[IMPORTANT] |
| 141 | +This is a critical notice, but it's not warning you of danger. |
| 142 | +-------- |
| 143 | +-- |
| 144 | + |
| 145 | +==== Exception: Single-line terminal commands |
| 146 | + |
| 147 | +Another common case is 1-line terminal commands, for which this guide recommends using a literal block with a `prompt` role added. |
| 148 | + |
| 149 | +// tag::prompt-single-line[] |
| 150 | +[source,asciidoc] |
| 151 | +-------- |
| 152 | +[.prompt] |
| 153 | + echo "Hello, world!" |
| 154 | +-------- |
| 155 | +// end::prompt-single-line[] |
| 156 | + |
| 157 | +The single preceding space notation affirms the use of a literal block for any consecutive lines of content preceded by a single space. |
| 158 | +For multi-line terminal commands/output, use the `....` syntax to distinguish the block. |
| 159 | + |
| 160 | +==== Exception to the exceptions |
| 161 | + |
| 162 | +Whenever additional options must be set for a block, such as a title or role, use the linewise delimiter syntax -- even in one-liner cases. |
| 163 | + |
| 164 | +// tag::prompt-multiline[] |
| 165 | +[source,asciidoc] |
| 166 | +-------- |
| 167 | +[.prompt,subs="+attributes"] |
| 168 | +.... |
| 169 | +echo "Hello, {what}!" |
| 170 | +.... |
| 171 | +-------- |
| 172 | +// end::prompt-multiline[] |
| 173 | + |
| 174 | +=== Example Blocks |
| 175 | + |
| 176 | +Use example blocks liberally. |
| 177 | +If something fits the description of being an example -- especially if the words "`example`" or "`sample`" are used in the title, caption, or surrounding text referring to a given block of _anything_... |
| 178 | +then *wrap it in an example block*. |
| 179 | + |
| 180 | +Instances of the following block types may commonly be instances of examples, and just as commonly they may not be. |
| 181 | + |
| 182 | +* figures (diagrams, illustrations, screenshots) |
| 183 | +* tables |
| 184 | +* code listings |
| 185 | +* literal blocks (sample prompts, logs, etc) |
| 186 | +* rich-text snippets (rendered results, a user story, etc) |
| 187 | + |
| 188 | +Whenever any such instances _are examples_, prepend and append them with example blocks, and prefer to title them at the exampple-block level rather than the inner-content level. |
| 189 | + |
| 190 | +.Example of a code block treated as an example |
| 191 | +[source,asciidoc] |
| 192 | +-------- |
| 193 | +:example-caption: Example |
| 194 | +
|
| 195 | +.require statement in Ruby |
| 196 | +==== |
| 197 | +[source,ruby] |
| 198 | +---- |
| 199 | +require 'jekyll' |
| 200 | +---- |
| 201 | +==== |
| 202 | +-------- |
| 203 | + |
| 204 | + |
| 205 | +== Special Syntax |
| 206 | + |
| 207 | +=== Attributes |
0 commit comments