blob: 583ea7c2abaec6d523e6b473fdb8f68f2d6dc054 [file] [log] [blame]
Minos Galanakisc13a5d82020-10-27 11:57:27 +00001#####################################
2Documentation Contribution Guidelines
3#####################################
4
Elena Uziunaiteb94b3a12023-12-22 15:11:50 +00005The Trusted Firmware-M project uses `Sphinx`_ to generate the Official
Antonio de Angelis9d496a52025-01-07 21:18:00 +00006Documentation from `reStructuredText`_ `.rst` source files,
Minos Galanakisc13a5d82020-10-27 11:57:27 +00007
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,
Anton Komlev91281f02022-04-22 09:24:20 +010023 :doc:`integration guide </integration_guide/index>` can be used as a reference.
Minos Galanakisc13a5d82020-10-27 11:57:27 +000024- 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
Minos Galanakisc13a5d82020-10-27 11:57:27 +000057**********************
58Platform Documentation
59**********************
60
61The Documentation Build system provides an interface with the platform directory
Anton Komlev90657c12023-01-17 13:01:22 +000062allowing 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
Matthew Dalzell988bbd62025-06-05 15:49:26 +010065Platform 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>`.
Minos Galanakisc13a5d82020-10-27 11:57:27 +000067The format and structure of this entry is not strictly defined, and allows
Anton Komlev90657c12023-01-17 13:01:22 +000068flexible control of vendor's and platform's documentation space.
69Follow the :ref:`platform_documentation` document for more details.
Minos Galanakisc13a5d82020-10-27 11:57:27 +000070
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
Minos Galanakisc13a5d82020-10-27 11:57:27 +000081.. code-block:: restructuredtext
82
83 ###################
84 Document Title (H1)
85 ###################
86
87 ******************
Elena Uziunaitee791f012023-11-20 17:24:01 +000088 Chapter Title (H2)
Minos Galanakisc13a5d82020-10-27 11:57:27 +000089 ******************
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
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000103The 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
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000128reStructuredText supports implicit code-blocks by indenting a section of text,
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000129surrounded 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
Anton Komlev3356ba32022-03-31 22:02:11 +0100176seen on :doc:`/getting_started/tfm_getting_started` and
177:doc:`/releases/1.0`
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000178
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
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000197should be only used for consistency purposes or for a small amount
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000198of 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
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000218Document Links
219==============
220
221A document included in the documentation can be referenced by the `doc:` notation
222
223.. code-block:: restructuredtext
224
Anton Komlev3356ba32022-03-31 22:02:11 +0100225 :doc:`integration guide </integration_guide/tfm_integration_guide>`
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000226
227The path is relative to the root of the Trusted Firmware-M code.
228
Elena Uziunaiteb94b3a12023-12-22 15:11:50 +0000229Trusted 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
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000239<TF-M-Tests:tfm_test_suites_addition>`; the reStructuredText would look like this:
Elena Uziunaiteb94b3a12023-12-22 15:11:50 +0000240
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
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000250Reference 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
Summer Qin6d5c91c2021-05-24 15:32:44 +0800258 :ref:`docs/getting_started/tfm_getting_started:Tool & Dependency overview`
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000259
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
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000265Glossary term
266=============
267
268For technical terms and abbreviations, the recommended guidance is to add an
Anton Komlev3356ba32022-03-31 22:02:11 +0100269entry to the :doc:`/glossary` and refer to it, using the `term:`
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000270directive
271
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000272.. 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`_
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000294#. `reStructuredText`_
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000295#. `Python Documentation Guidelines`_
296#. `Pygments Lexers`_
Elena Uziunaiteb94b3a12023-12-22 15:11:50 +0000297#. `Intersphinx`_
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000298
299.. _Sphinx: https://www.sphinx-doc.org/en/master/
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000300.. _reStructuredText: https://docutils.sourceforge.io/rst.html
Awadhy Mohammed3ba2d062023-03-02 10:43:07 +0000301.. _Python Documentation Guidelines: https://devguide.python.org/documentation/style-guide/
302.. _Pygments Lexers: https://pygments.org/docs/api/#lexers
Elena Uziunaiteb94b3a12023-12-22 15:11:50 +0000303.. _Intersphinx: https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
Matthew Dalzell988bbd62025-06-05 15:49:26 +0100304.. _conf.py: https://git.trustedfirmware.org/plugins/gitiles/TF-M/trusted-firmware-m.git/+/HEAD/docs/conf.py
Minos Galanakisc13a5d82020-10-27 11:57:27 +0000305
306--------------
307
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000308*Copyright (c) 2020-2025, Arm Limited. All rights reserved.*