aboutsummaryrefslogtreecommitdiff
path: root/docs/contributing/doc_guidelines.rst
blob: e217dde57164affee237da2ec7c1719a981dc3ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#####################################
Documentation Contribution Guidelines
#####################################

The Trusted Firmware-M project uses `Sphinx`_ to generated the Official
Documentation from `Restructed Text`_ `.rst` source files,

The aim is to align as much as possible with the official
`Python Documentation Guidelines`_ while keeping the consistency with the
already existing files.

The guidance below is provided as a help. It is not meant to be a definitive
list.

********
Overview
********

The following short-list provides a quick summary of the rules.

- If the patch modifies a present file, the file's style should be followed
- If creating a new file,
  :doc:`integration guide </docs/getting_started/tfm_sw_requirement>` can be used as a reference.
- When a new style is to be expressed, consult the `Python Documentation Guidelines`_

*************
List of rules
*************
The following rules should be considered:

#. H1 document title headers should be expressed by # with over-line
   (rows on top and bottom) of the text
#. Only ONE H1 header should allowed per document, ideally placed
   on top of the page.
#. H2 headers should be expressed by * with over-line
#. H2 header's text should be UNIQUE in per document basis
#. H3 headers should be expressed by an underline of '='
#. H4 headers should be expressed by an underline of '-'
#. H3 and H4 headers have no limitation about naming.
   They can have similar names on the same document, as long as
   they have different parents.
#. H5 headers should be expressed by an underline of '^'
#. H5 headers will be rendered in document body but not in
   menus on the navigation bar
#. Do not use more than 5 levels of heading
#. When writing guides, which are expected to be able to be readable by
   command line tools, it would be best practice to add long complicated
   tables, and UML diagrams in the bottom of the page and using internal
   references(auto-label)
#. No special formatting should be allowed in Headers
   (code, underline, strike-through etc)
#. Long URLs and external references should be placed at the bottom of the
   page and referenced in the body of the document
#. New introduced terms and abbreviations should be added to Glossary and
   directly linked by the `:term:` notation across all documents using it.


**********************
Platform Documentation
**********************

The Documentation Build system provides an interface with the platform directory
allowing maintainers to bundle platform specific documentation. **This behaviour
needs to be explicitly enabled for each platform's space** by
modifying the `platform/ext/index.rst` (responsible for generating the
:doc:`Platform Index File </platform/ext/index>`) and adding a table of
contents entry for the corresponding platform space.

The format and structure of this entry is not strictly defined, and allows
flexible control of the platform's documentation space. In most cases it can be
set to recursively match all documents under that directory.

.. code-block:: restructuredtext

    .. toctree::
        :maxdepth: 4
        :caption: PLATFORM_X_CAPTION
        :glob:

        target/PLATFORM_X/**

****************
Common Use Cases
****************

The section below describes with examples, a rule compliant implementation
for most common documentation elements.

Headers
=======


.. code-block:: restructuredtext

    ###################
    Document Title (H1)
    ###################

    ******************
    Chapter Ttitle(H2)
    ******************

    Chapter Section (H3)
    ====================

    Chapter Sub-Section (H4)
    ------------------------

    Subsection of Chapter sub-section (H5)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Code Blocks
===========


The recommendation for code content, is to use the explicit code-block directive,
ideally with a defined lexer for the language the block contains.

A list of compatible lexers can be found at `Pygments Lexers`_

.. code-block:: restructuredtext

    .. code-block:: bash

        ls
        pwd

    .. code-block:: doscon

        dir

    .. code-block:: c

        static struct rn_object_t;

    .. code-block:: python3

        print("Hello TF-M")


Restructured Text supports implicit code-blocks by indenting a section of text,
surrounded by new lines. While this formatting is
allowed, it should be avoided if possible.

.. code-block:: restructuredtext

    The quick brown fox jumps over the lazy dog

        ls
        pwd

.. Note::

    Mixing two different code-block formats in the same document will break
    the whole document's rendering. When editing an existing document, please
    follow the existing format.

    **New documents should always use the explicit format.**

Tables
======

For adding new tables the `table::` notation should be used.

.. code-block:: restructuredtext

    .. table:: Components table
       :widths: auto

       +--------------+--------------+-------------+
       | **Title A**  | **Title B**  | **Title C** |
       +==============+==============+=============+
       | Text A       | Text B       | Text C      |
       +--------------+--------------+-------------+


While the equivalent simple table code will render correctly in the output, it
will not be added to the index (So it cannot be referenced if needed)

.. code-block:: restructuredtext

   +--------------+--------------+-------------+
   | **Title A**  | **Title B**  | **Title C** |
   +==============+==============+=============+
   | Text A       | Text B       | Text C      |
   +--------------+--------------+-------------+

Other types of tables such as list-tables and csv-tables are also permitted, as
seen on :doc:`/docs/getting_started/tfm_sw_requirement` and
:doc:`/docs/reference/releases/1.0`


External Links
==============

External links should be placed in the bottom of a document.

.. code-block:: restructuredtext

    The quick brown fox jumps over the lazy dog according to `Link_A`_

    .. _Link_A: https://www.aaa.org
    .. _Link_B: https://www.bbb.org

    --------------

    *Copyright (c) XYZ *

Creating in-line links is permitted, but should be avoided if possible. It
should be only used for consistency purposes or for a small ammount
of short links.

.. code-block:: restructuredtext

    The quick brown fox jumps over the lazy dog according to `Link_A <https://www.aaa.org>`_

If for the purposes of content, a link is to be referenced by multiple
labels, internal linking is the recommended approach.

.. code-block:: restructuredtext

    The quick brown fox jumps over the lazy dog according to `Link_A_New`_

    .. _Link_A: https://www.aaa.org
    .. _Link_A_New: `Link_A`_

    --------------

    *Copyright (c) XYZ *


Document Links
==============

A document included in the documentation can be referenced by the `doc:` notation

.. code-block:: restructuredtext

    :doc:`integration guide </docs/getting_started/tfm_sw_requirement>`

The path is relative to the root of the Trusted Firmware-M code.

Reference specific section of a document
========================================

In order to reference a specific section of a document, up to level 4 headers
(if they are included in the index), the `ref:` keyword can be used

.. code-block:: restructuredtext

    :ref:`docs/getting_started/tfm_sw_requirement:Tool & Dependency overview`

This can also be used to quickly scroll to the specific section of the current
document. This technique can be used to add complex table in the bottom of a
document and create clickable quick access references to it for improved user
experience.


Glossary term
=============

For technical terms and abbreviations, the recommended guidance is to add an
entry to the :doc:`/docs/reference/glossary` and refer to it, using the `term:`
directive


.. code-block:: restructuredtext

    HAL
    Hardware Abstraction Layer
        Interface to abstract hardware-oriented operations and provides a set of
        APIs to the upper layers.

    .....

    As described in the design document :term:`HAL` abstracts the
    hardware-oriented and platform specific
    .......

.. Note::

   The ":term:" directive does not work when used in special formatting.
   Using \*:term:`HAL`\* **will not link to the glossary term**.

References
==========

#. `Sphinx`_
#. `Restructed Text`_
#. `Python Documentation Guidelines`_
#. `Pygments Lexers`_

.. _Sphinx: https://www.sphinx-doc.org/en/master/
.. _Restructed Text: https://docutils.sourceforge.io/rst.html
.. _Python Documentation Guidelines: https://devguide.python.org/documenting/#style-guide
.. _Pygments Lexers: https://pygments.org/docs/lexers/

--------------

*Copyright (c) 2020, Arm Limited. All rights reserved.*