Minos Galanakis | c13a5d8 | 2020-10-27 11:57:27 +0000 | [diff] [blame] | 1 | ##################################### |
| 2 | Documentation Contribution Guidelines |
| 3 | ##################################### |
| 4 | |
| 5 | The Trusted Firmware-M project uses `Sphinx`_ to generated the Official |
| 6 | Documentation from `Restructed Text`_ `.rst` source files, |
| 7 | |
| 8 | The aim is to align as much as possible with the official |
| 9 | `Python Documentation Guidelines`_ while keeping the consistency with the |
| 10 | already existing files. |
| 11 | |
| 12 | The guidance below is provided as a help. It is not meant to be a definitive |
| 13 | list. |
| 14 | |
| 15 | ******** |
| 16 | Overview |
| 17 | ******** |
| 18 | |
| 19 | The following short-list provides a quick summary of the rules. |
| 20 | |
| 21 | - If the patch modifies a present file, the file's style should be followed |
| 22 | - If creating a new file, |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame^] | 23 | :doc:`integration guide </docs/integration_guide/tfm_integration_guide>` can be used as a reference. |
Minos Galanakis | c13a5d8 | 2020-10-27 11:57:27 +0000 | [diff] [blame] | 24 | - When a new style is to be expressed, consult the `Python Documentation Guidelines`_ |
| 25 | |
| 26 | ************* |
| 27 | List of rules |
| 28 | ************* |
| 29 | The following rules should be considered: |
| 30 | |
| 31 | #. H1 document title headers should be expressed by # with over-line |
| 32 | (rows on top and bottom) of the text |
| 33 | #. Only ONE H1 header should allowed per document, ideally placed |
| 34 | on top of the page. |
| 35 | #. H2 headers should be expressed by * with over-line |
| 36 | #. H2 header's text should be UNIQUE in per document basis |
| 37 | #. H3 headers should be expressed by an underline of '=' |
| 38 | #. H4 headers should be expressed by an underline of '-' |
| 39 | #. H3 and H4 headers have no limitation about naming. |
| 40 | They can have similar names on the same document, as long as |
| 41 | they have different parents. |
| 42 | #. H5 headers should be expressed by an underline of '^' |
| 43 | #. H5 headers will be rendered in document body but not in |
| 44 | menus on the navigation bar |
| 45 | #. Do not use more than 5 levels of heading |
| 46 | #. When writing guides, which are expected to be able to be readable by |
| 47 | command line tools, it would be best practice to add long complicated |
| 48 | tables, and UML diagrams in the bottom of the page and using internal |
| 49 | references(auto-label) |
| 50 | #. No special formatting should be allowed in Headers |
| 51 | (code, underline, strike-through etc) |
| 52 | #. Long URLs and external references should be placed at the bottom of the |
| 53 | page and referenced in the body of the document |
| 54 | #. New introduced terms and abbreviations should be added to Glossary and |
| 55 | directly linked by the `:term:` notation across all documents using it. |
| 56 | |
| 57 | |
| 58 | ********************** |
| 59 | Platform Documentation |
| 60 | ********************** |
| 61 | |
| 62 | The Documentation Build system provides an interface with the platform directory |
| 63 | allowing maintainers to bundle platform specific documentation. **This behaviour |
| 64 | needs to be explicitly enabled for each platform's space** by |
| 65 | modifying the `platform/ext/index.rst` (responsible for generating the |
| 66 | :doc:`Platform Index File </platform/ext/index>`) and adding a table of |
| 67 | contents entry for the corresponding platform space. |
| 68 | |
| 69 | The format and structure of this entry is not strictly defined, and allows |
| 70 | flexible control of the platform's documentation space. In most cases it can be |
| 71 | set to recursively match all documents under that directory. |
| 72 | |
| 73 | .. code-block:: restructuredtext |
| 74 | |
| 75 | .. toctree:: |
| 76 | :maxdepth: 4 |
| 77 | :caption: PLATFORM_X_CAPTION |
| 78 | :glob: |
| 79 | |
| 80 | target/PLATFORM_X/** |
| 81 | |
| 82 | **************** |
| 83 | Common Use Cases |
| 84 | **************** |
| 85 | |
| 86 | The section below describes with examples, a rule compliant implementation |
| 87 | for most common documentation elements. |
| 88 | |
| 89 | Headers |
| 90 | ======= |
| 91 | |
| 92 | |
| 93 | .. code-block:: restructuredtext |
| 94 | |
| 95 | ################### |
| 96 | Document Title (H1) |
| 97 | ################### |
| 98 | |
| 99 | ****************** |
| 100 | Chapter Ttitle(H2) |
| 101 | ****************** |
| 102 | |
| 103 | Chapter Section (H3) |
| 104 | ==================== |
| 105 | |
| 106 | Chapter Sub-Section (H4) |
| 107 | ------------------------ |
| 108 | |
| 109 | Subsection of Chapter sub-section (H5) |
| 110 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 111 | |
| 112 | Code Blocks |
| 113 | =========== |
| 114 | |
| 115 | |
| 116 | The recommendation for code content, is to use the explicit code-block directive, |
| 117 | ideally with a defined lexer for the language the block contains. |
| 118 | |
| 119 | A list of compatible lexers can be found at `Pygments Lexers`_ |
| 120 | |
| 121 | .. code-block:: restructuredtext |
| 122 | |
| 123 | .. code-block:: bash |
| 124 | |
| 125 | ls |
| 126 | pwd |
| 127 | |
| 128 | .. code-block:: doscon |
| 129 | |
| 130 | dir |
| 131 | |
| 132 | .. code-block:: c |
| 133 | |
| 134 | static struct rn_object_t; |
| 135 | |
| 136 | .. code-block:: python3 |
| 137 | |
| 138 | print("Hello TF-M") |
| 139 | |
| 140 | |
| 141 | Restructured Text supports implicit code-blocks by indenting a section of text, |
| 142 | surrounded by new lines. While this formatting is |
| 143 | allowed, it should be avoided if possible. |
| 144 | |
| 145 | .. code-block:: restructuredtext |
| 146 | |
| 147 | The quick brown fox jumps over the lazy dog |
| 148 | |
| 149 | ls |
| 150 | pwd |
| 151 | |
| 152 | .. Note:: |
| 153 | |
| 154 | Mixing two different code-block formats in the same document will break |
| 155 | the whole document's rendering. When editing an existing document, please |
| 156 | follow the existing format. |
| 157 | |
| 158 | **New documents should always use the explicit format.** |
| 159 | |
| 160 | Tables |
| 161 | ====== |
| 162 | |
| 163 | For adding new tables the `table::` notation should be used. |
| 164 | |
| 165 | .. code-block:: restructuredtext |
| 166 | |
| 167 | .. table:: Components table |
| 168 | :widths: auto |
| 169 | |
| 170 | +--------------+--------------+-------------+ |
| 171 | | **Title A** | **Title B** | **Title C** | |
| 172 | +==============+==============+=============+ |
| 173 | | Text A | Text B | Text C | |
| 174 | +--------------+--------------+-------------+ |
| 175 | |
| 176 | |
| 177 | While the equivalent simple table code will render correctly in the output, it |
| 178 | will not be added to the index (So it cannot be referenced if needed) |
| 179 | |
| 180 | .. code-block:: restructuredtext |
| 181 | |
| 182 | +--------------+--------------+-------------+ |
| 183 | | **Title A** | **Title B** | **Title C** | |
| 184 | +==============+==============+=============+ |
| 185 | | Text A | Text B | Text C | |
| 186 | +--------------+--------------+-------------+ |
| 187 | |
| 188 | Other types of tables such as list-tables and csv-tables are also permitted, as |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame^] | 189 | seen on :doc:`/docs/getting_started/tfm_getting_started` and |
Summer Qin | abf6698 | 2021-04-06 17:22:15 +0800 | [diff] [blame] | 190 | :doc:`/docs/releases/1.0` |
Minos Galanakis | c13a5d8 | 2020-10-27 11:57:27 +0000 | [diff] [blame] | 191 | |
| 192 | |
| 193 | External Links |
| 194 | ============== |
| 195 | |
| 196 | External links should be placed in the bottom of a document. |
| 197 | |
| 198 | .. code-block:: restructuredtext |
| 199 | |
| 200 | The quick brown fox jumps over the lazy dog according to `Link_A`_ |
| 201 | |
| 202 | .. _Link_A: https://www.aaa.org |
| 203 | .. _Link_B: https://www.bbb.org |
| 204 | |
| 205 | -------------- |
| 206 | |
| 207 | *Copyright (c) XYZ * |
| 208 | |
| 209 | Creating in-line links is permitted, but should be avoided if possible. It |
| 210 | should be only used for consistency purposes or for a small ammount |
| 211 | of short links. |
| 212 | |
| 213 | .. code-block:: restructuredtext |
| 214 | |
| 215 | The quick brown fox jumps over the lazy dog according to `Link_A <https://www.aaa.org>`_ |
| 216 | |
| 217 | If for the purposes of content, a link is to be referenced by multiple |
| 218 | labels, internal linking is the recommended approach. |
| 219 | |
| 220 | .. code-block:: restructuredtext |
| 221 | |
| 222 | The quick brown fox jumps over the lazy dog according to `Link_A_New`_ |
| 223 | |
| 224 | .. _Link_A: https://www.aaa.org |
| 225 | .. _Link_A_New: `Link_A`_ |
| 226 | |
| 227 | -------------- |
| 228 | |
| 229 | *Copyright (c) XYZ * |
| 230 | |
| 231 | |
| 232 | Document Links |
| 233 | ============== |
| 234 | |
| 235 | A document included in the documentation can be referenced by the `doc:` notation |
| 236 | |
| 237 | .. code-block:: restructuredtext |
| 238 | |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame^] | 239 | :doc:`integration guide </docs/integration_guide/tfm_integration_guide>` |
Minos Galanakis | c13a5d8 | 2020-10-27 11:57:27 +0000 | [diff] [blame] | 240 | |
| 241 | The path is relative to the root of the Trusted Firmware-M code. |
| 242 | |
| 243 | Reference specific section of a document |
| 244 | ======================================== |
| 245 | |
| 246 | In order to reference a specific section of a document, up to level 4 headers |
| 247 | (if they are included in the index), the `ref:` keyword can be used |
| 248 | |
| 249 | .. code-block:: restructuredtext |
| 250 | |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame^] | 251 | :ref:`docs/getting_started/tfm_getting_started:Tool & Dependency overview` |
Minos Galanakis | c13a5d8 | 2020-10-27 11:57:27 +0000 | [diff] [blame] | 252 | |
| 253 | This can also be used to quickly scroll to the specific section of the current |
| 254 | document. This technique can be used to add complex table in the bottom of a |
| 255 | document and create clickable quick access references to it for improved user |
| 256 | experience. |
| 257 | |
| 258 | |
| 259 | Glossary term |
| 260 | ============= |
| 261 | |
| 262 | For technical terms and abbreviations, the recommended guidance is to add an |
Summer Qin | abf6698 | 2021-04-06 17:22:15 +0800 | [diff] [blame] | 263 | entry to the :doc:`/docs/glossary` and refer to it, using the `term:` |
Minos Galanakis | c13a5d8 | 2020-10-27 11:57:27 +0000 | [diff] [blame] | 264 | directive |
| 265 | |
| 266 | |
| 267 | .. code-block:: restructuredtext |
| 268 | |
| 269 | HAL |
| 270 | Hardware Abstraction Layer |
| 271 | Interface to abstract hardware-oriented operations and provides a set of |
| 272 | APIs to the upper layers. |
| 273 | |
| 274 | ..... |
| 275 | |
| 276 | As described in the design document :term:`HAL` abstracts the |
| 277 | hardware-oriented and platform specific |
| 278 | ....... |
| 279 | |
| 280 | .. Note:: |
| 281 | |
| 282 | The ":term:" directive does not work when used in special formatting. |
| 283 | Using \*:term:`HAL`\* **will not link to the glossary term**. |
| 284 | |
| 285 | References |
| 286 | ========== |
| 287 | |
| 288 | #. `Sphinx`_ |
| 289 | #. `Restructed Text`_ |
| 290 | #. `Python Documentation Guidelines`_ |
| 291 | #. `Pygments Lexers`_ |
| 292 | |
| 293 | .. _Sphinx: https://www.sphinx-doc.org/en/master/ |
| 294 | .. _Restructed Text: https://docutils.sourceforge.io/rst.html |
| 295 | .. _Python Documentation Guidelines: https://devguide.python.org/documenting/#style-guide |
| 296 | .. _Pygments Lexers: https://pygments.org/docs/lexers/ |
| 297 | |
| 298 | -------------- |
| 299 | |
Summer Qin | abf6698 | 2021-04-06 17:22:15 +0800 | [diff] [blame] | 300 | *Copyright (c) 2020-2021, Arm Limited. All rights reserved.* |