1##################################### 2Documentation Contribution Guidelines 3##################################### 4 5The Trusted Firmware-M project uses `Sphinx`_ to generated the Official 6Documentation from `Restructed Text`_ `.rst` source files, 7 8The aim is to align as much as possible with the official 9`Python Documentation Guidelines`_ while keeping the consistency with the 10already existing files. 11 12The guidance below is provided as a help. It is not meant to be a definitive 13list. 14 15******** 16Overview 17******** 18 19The 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, 23 :doc:`integration guide </integration_guide/index>` can be used as a reference. 24- When a new style is to be expressed, consult the `Python Documentation Guidelines`_ 25 26************* 27List of rules 28************* 29The 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********************** 59Platform Documentation 60********************** 61 62The Documentation Build system provides an interface with the platform directory 63allowing maintainers to bundle platform specific documentation. **This behaviour 64needs to be explicitly enabled for each platform's space** by 65modifying the `platform/index.rst` (responsible for generating the 66:doc:`Platform Index File </platform/index>`) and adding a table of 67contents entry for the corresponding platform space. 68 69The format and structure of this entry is not strictly defined, and allows 70flexible control of the platform's documentation space. In most cases it can be 71set 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 PLATFORM_X/** 81 82**************** 83Common Use Cases 84**************** 85 86The section below describes with examples, a rule compliant implementation 87for most common documentation elements. 88 89Headers 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 112Code Blocks 113=========== 114 115 116The recommendation for code content, is to use the explicit code-block directive, 117ideally with a defined lexer for the language the block contains. 118 119A 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 141Restructured Text supports implicit code-blocks by indenting a section of text, 142surrounded by new lines. While this formatting is 143allowed, 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 160Tables 161====== 162 163For 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 177While the equivalent simple table code will render correctly in the output, it 178will 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 188Other types of tables such as list-tables and csv-tables are also permitted, as 189seen on :doc:`/getting_started/tfm_getting_started` and 190:doc:`/releases/1.0` 191 192 193External Links 194============== 195 196External 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 209Creating in-line links is permitted, but should be avoided if possible. It 210should be only used for consistency purposes or for a small ammount 211of 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 217If for the purposes of content, a link is to be referenced by multiple 218labels, 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 232Document Links 233============== 234 235A document included in the documentation can be referenced by the `doc:` notation 236 237.. code-block:: restructuredtext 238 239 :doc:`integration guide </integration_guide/tfm_integration_guide>` 240 241The path is relative to the root of the Trusted Firmware-M code. 242 243Reference specific section of a document 244======================================== 245 246In 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 251 :ref:`docs/getting_started/tfm_getting_started:Tool & Dependency overview` 252 253This can also be used to quickly scroll to the specific section of the current 254document. This technique can be used to add complex table in the bottom of a 255document and create clickable quick access references to it for improved user 256experience. 257 258 259Glossary term 260============= 261 262For technical terms and abbreviations, the recommended guidance is to add an 263entry to the :doc:`/glossary` and refer to it, using the `term:` 264directive 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 285References 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/lexers/ 297 298-------------- 299 300*Copyright (c) 2020-2021, Arm Limited. All rights reserved.* 301