1#####################################
2Documentation Contribution Guidelines
3#####################################
4
5The Trusted Firmware-M project uses `Sphinx`_ to generate the Official
6Documentation from `reStructuredText`_ `.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**********************
58Platform Documentation
59**********************
60
61The Documentation Build system provides an interface with the platform directory
62allowing maintainers to bundle platform specific documentation. Platforms are
63grouped by vendor. **This behaviour needs to be explicitly enabled for each
64vendor's space** by providing the `<vendor>/index.rst` (responsible for generating the
65Platform Index File, as seen linked in :doc:`TF-M Platforms </platform/index>`)
66contents entry for the corresponding vendor's space in :doc:`TF-M Platforms </platform/index>`.
67The format and structure of this entry is not strictly defined, and allows
68flexible control of vendor's and platform's documentation space.
69Follow the :ref:`platform_documentation` document for more details.
70
71****************
72Common Use Cases
73****************
74
75The section below describes with examples, a rule compliant implementation
76for most common documentation elements.
77
78Headers
79=======
80
81.. code-block:: restructuredtext
82
83    ###################
84    Document Title (H1)
85    ###################
86
87    ******************
88    Chapter Title (H2)
89    ******************
90
91    Chapter Section (H3)
92    ====================
93
94    Chapter Sub-Section (H4)
95    ------------------------
96
97    Subsection of Chapter sub-section (H5)
98    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99
100Code Blocks
101===========
102
103The recommendation for code content, is to use the explicit code-block directive,
104ideally with a defined lexer for the language the block contains.
105
106A list of compatible lexers can be found at `Pygments Lexers`_
107
108.. code-block:: restructuredtext
109
110    .. code-block:: bash
111
112        ls
113        pwd
114
115    .. code-block:: doscon
116
117        dir
118
119    .. code-block:: c
120
121        static struct rn_object_t;
122
123    .. code-block:: python3
124
125        print("Hello TF-M")
126
127
128reStructuredText supports implicit code-blocks by indenting a section of text,
129surrounded by new lines. While this formatting is
130allowed, it should be avoided if possible.
131
132.. code-block:: restructuredtext
133
134    The quick brown fox jumps over the lazy dog
135
136        ls
137        pwd
138
139.. Note::
140
141    Mixing two different code-block formats in the same document will break
142    the whole document's rendering. When editing an existing document, please
143    follow the existing format.
144
145    **New documents should always use the explicit format.**
146
147Tables
148======
149
150For adding new tables the `table::` notation should be used.
151
152.. code-block:: restructuredtext
153
154    .. table:: Components table
155       :widths: auto
156
157       +--------------+--------------+-------------+
158       | **Title A**  | **Title B**  | **Title C** |
159       +==============+==============+=============+
160       | Text A       | Text B       | Text C      |
161       +--------------+--------------+-------------+
162
163
164While the equivalent simple table code will render correctly in the output, it
165will not be added to the index (So it cannot be referenced if needed)
166
167.. code-block:: restructuredtext
168
169   +--------------+--------------+-------------+
170   | **Title A**  | **Title B**  | **Title C** |
171   +==============+==============+=============+
172   | Text A       | Text B       | Text C      |
173   +--------------+--------------+-------------+
174
175Other types of tables such as list-tables and csv-tables are also permitted, as
176seen on :doc:`/getting_started/tfm_getting_started` and
177:doc:`/releases/1.0`
178
179
180External Links
181==============
182
183External links should be placed in the bottom of a document.
184
185.. code-block:: restructuredtext
186
187    The quick brown fox jumps over the lazy dog according to `Link_A`_
188
189    .. _Link_A: https://www.aaa.org
190    .. _Link_B: https://www.bbb.org
191
192    --------------
193
194    *Copyright (c) XYZ *
195
196Creating in-line links is permitted, but should be avoided if possible. It
197should be only used for consistency purposes or for a small amount
198of short links.
199
200.. code-block:: restructuredtext
201
202    The quick brown fox jumps over the lazy dog according to `Link_A <https://www.aaa.org>`_
203
204If for the purposes of content, a link is to be referenced by multiple
205labels, internal linking is the recommended approach.
206
207.. code-block:: restructuredtext
208
209    The quick brown fox jumps over the lazy dog according to `Link_A_New`_
210
211    .. _Link_A: https://www.aaa.org
212    .. _Link_A_New: `Link_A`_
213
214    --------------
215
216    *Copyright (c) XYZ *
217
218Document Links
219==============
220
221A document included in the documentation can be referenced by the `doc:` notation
222
223.. code-block:: restructuredtext
224
225    :doc:`integration guide </integration_guide/tfm_integration_guide>`
226
227The path is relative to the root of the Trusted Firmware-M code.
228
229Trusted Firmware-M project is spread among multiple repositories: Trusted Firmware-M, TF-M Tests,
230TF-M Tools and TF-M Extras. Every repository has its own documentation, and since
231:doc:`v2.0.0<../releases/2.0.0>`, they can be found under `Links`.
232
233Using `Intersphinx`_, it is now possible to use cross-reference roles from Sphinx to reference
234documentation from different projects (repositories), like TF-M Tests. Referencing documentation
235using the `doc:` notation is preferred and helps to avoid broken cross-references if the link of
236the document changes.
237
238For example, to get this: :doc:`Adding TF-M Regression Test Suite
239<TF-M-Tests:tfm_test_suites_addition>`; the reStructuredText would look like this:
240
241.. code-block:: restructuredtext
242
243    :doc:`Adding TF-M Regression Test Suite <TF-M-Tests:tfm_test_suites_addition>`
244
245As can be seen, it is quite similar to cross-referencing in Sphinx, except the path to the document
246is preceded with the external project name. For TF-M Tests, it is ``TF-M-Tests``. The names of
247other projects configured to be referenced using `Intersphinx`_ can be seen in the `conf.py`_ file
248under ``intersphinx_mapping``.
249
250Reference specific section of a document
251========================================
252
253In order to reference a specific section of a document, up to level 4 headers
254(if they are included in the index), the `ref:` keyword can be used
255
256.. code-block:: restructuredtext
257
258    :ref:`docs/getting_started/tfm_getting_started:Tool & Dependency overview`
259
260This can also be used to quickly scroll to the specific section of the current
261document. This technique can be used to add complex table in the bottom of a
262document and create clickable quick access references to it for improved user
263experience.
264
265Glossary term
266=============
267
268For technical terms and abbreviations, the recommended guidance is to add an
269entry to the :doc:`/glossary` and refer to it, using the `term:`
270directive
271
272.. code-block:: restructuredtext
273
274    HAL
275    Hardware Abstraction Layer
276        Interface to abstract hardware-oriented operations and provides a set of
277        APIs to the upper layers.
278
279    .....
280
281    As described in the design document :term:`HAL` abstracts the
282    hardware-oriented and platform specific
283    .......
284
285.. Note::
286
287   The ":term:" directive does not work when used in special formatting.
288   Using \*:term:`HAL`\* **will not link to the glossary term**.
289
290References
291==========
292
293#. `Sphinx`_
294#. `reStructuredText`_
295#. `Python Documentation Guidelines`_
296#. `Pygments Lexers`_
297#. `Intersphinx`_
298
299.. _Sphinx: https://www.sphinx-doc.org/en/master/
300.. _reStructuredText: https://docutils.sourceforge.io/rst.html
301.. _Python Documentation Guidelines: https://devguide.python.org/documentation/style-guide/
302.. _Pygments Lexers: https://pygments.org/docs/api/#lexers
303.. _Intersphinx: https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
304.. _conf.py: https://git.trustedfirmware.org/plugins/gitiles/TF-M/trusted-firmware-m.git/+/HEAD/docs/conf.py
305
306--------------
307
308*Copyright (c) 2020-2025, Arm Limited. All rights reserved.*
309