summaryrefslogtreecommitdiff
path: root/Documentation/internals/contributing/documentation-style.rst
blob: 2eec4c4d2694a839dd134704810c76f1f434077a (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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
..
      Copyright (c) 2016 Stephen Finucane <stephen@that.guru>

      Licensed under the Apache License, Version 2.0 (the "License"); you may
      not use this file except in compliance with the License. You may obtain
      a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
      WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
      License for the specific language governing permissions and limitations
      under the License.

      Convention for heading levels in Open vSwitch documentation:

      =======  Heading 0 (reserved for the title in a document)
      -------  Heading 1
      ~~~~~~~  Heading 2
      +++++++  Heading 3
      '''''''  Heading 4

      Avoid deeper levels because they do not render well.

===================
Documentation Style
===================

This file describes the documentation style used in all documentation found in
Open vSwitch. Documentation includes any documents found in ``Documentation``
along with any ``README``, ``MAINTAINERS``, or generally ``rst`` suffixed
documents found in the project tree.

.. note::

   This guide only applies to documentation for Open vSwitch v2.7. or greater.
   Previous versions of Open vSwitch used a combination of Markdown and raw
   plain text, and guidelines for these are not detailed here.

reStructuredText vs. Sphinx
---------------------------

`reStructuredText (rST)`__ is the syntax, while `Sphinx`__ is a documentation
generator.  Sphinx introduces a number of extensions to rST, like the ``:ref:``
role, which can and should be used in documentation, but these will not work
correctly on GitHub. As such, these extensions should not be used in any
documentation in the root level, such as the ``README``.

__ http://docutils.sourceforge.net/rst.html
__ http://www.sphinx-doc.org/

rST Conventions
---------------

Basics
~~~~~~

Many of the basic documentation guidelines match those of the
:doc:`coding-style`.

- Use reStructuredText (rST) for all documentation.

  Sphinx extensions can be used, but only for documentation in the
  ``Documentation`` folder.

- Limit lines at 79 characters.

  .. note::

     An exception to this rule is text within code-block elements that cannot
     be wrapped and links within references.

- Use spaces for indentation.

- Match indentation levels.

  A change in indentation level usually signifies a change in content nesting,
  by either closing the existing level or introducing a new level.

- Avoid trailing spaces on lines.

- Include a license (see this file) in all docs.

- Most importantly, always build and display documentation before submitting
  changes! Docs aren't unit testable, so visible inspection is necessary.

File Names
~~~~~~~~~~

- Use hyphens as space delimiters. For example: ``my-readme-document.rst``

  .. note::

     An exception to this rule is any man pages, which take an trailing number
     corresponding to the number of arguments required. This number is preceded
     by an underscore.

- Use lowercase filenames.

  .. note::

     An exception to this rule is any documents found in the root-level of the
     project.

Titles
~~~~~~

- Use the following headers levels.

  | ``=======``  Heading 0 (reserved for the title in a document)
  | ``-------``  Heading 1
  | ``~~~~~~~``  Heading 2
  | ``+++++++``  Heading 3
  | ``'''''''``  Heading 4

  .. note::

     Avoid using lower heading levels by rewriting and reorganizing the
     information.

- Under- and overlines should be of the same length as that of the heading
  text.

- Use "title case" for headers.

Code
~~~~

- Use ``::`` to prefix code.

- Don't use syntax highlighting such as ``.. highlight:: <syntax>`` or
  ``code-block:: <syntax>`` because it depends on external ``pygments``
  library.

- Prefix commands with ``$``.

- Where possible, include fully-working snippets of code. If there
  pre-requisites, explain what they are and how to achieve them.

Admonitions
~~~~~~~~~~~

- Use admonitions to call attention to important information.::

      .. note::

         This is a sample callout for some useful tip or trick.

  Example admonitions include: ``warning``, ``important``, ``note``, ``tip`` or
  ``seealso``.

- Use notes sparingly. Avoid having more than one per subsection.

Tables
~~~~~~

- Use either graphic tables, list tables or CSV tables.

Graphic tables
++++++++++++++

::

    .. table:: OVS-Linux kernel compatibility

      ============ ==============
      Open vSwitch Linux kernel
      ============ ==============
      1.4.x        2.6.18 to 3.2
      1.5.x        2.6.18 to 3.2
      1.6.x        2.6.18 to 3.2
      ============ ==============

::

    .. table:: OVS-Linux kernel compatibility

      +--------------+---------------+
      | Open vSwitch | Linux kernel  |
      +==============+===============+
      | 1.4.x        | 2.6.18 to 3.2 |
      +--------------+---------------+
      | 1.5.x        | 2.6.18 to 3.2 |
      +--------------+---------------+
      | 1.6.x        | 2.6.18 to 3.2 |
      +--------------+---------------+

.. note::
  The ``table`` role - ``.. table:: <name>`` -  can be safely omitted.

List tables
+++++++++++

::

    .. list-table:: OVS-Linux kernel compatibility
       :widths: 10 15
       :header-rows: 1

       * - Open vSwitch
         - Linux kernel
       * - 1.4.x
         - 2.6.18 to 3.2
       * - 1.5.x
         - 2.6.18 to 3.2
       * - 1.6.x
         - 2.6.18 to 3.2

CSV tables
++++++++++

::

    .. csv-table:: OVS-Linux kernel compatibility
       :header: Open vSwitch, Linux kernel
       :widths: 10 15

       1.4.x, 2.6.18 to 3.2
       1.5.x, 2.6.18 to 3.2
       1.6.x, 2.6.18 to 3.2

Cross-referencing
~~~~~~~~~~~~~~~~~

- To link to an external file or document, include as a link.::

      Here's a `link <http://openvswitch.org>`__ to the Open vSwitch website.


      Here's a `link`_ in reference style.

      .. _link: http://openvswitch.org

- You can also use citations.::

      Refer to the Open vSwitch documentation [1]_.

      References
      ----------

      .. [1]: http://openvswitch.org

- To cross-reference another doc, use the ``doc`` role.::

      Here is a link to the :doc:`/README.rst`

  .. note::

     This is a Sphinx extension. Do not use this in any top-level documents.

- To cross-reference an arbitrary location in a doc, use the ``ref`` role.::

      .. _sample-crossref

      Title
      ~~~~~

      Hello, world.

      Another Title
      ~~~~~~~~~~~~~

      Here is a cross-reference to :ref:`sample-crossref`.

  .. note::

     This is a Sphinx extension. Do not use this in any top-level documents.

Figures and Other Media
~~~~~~~~~~~~~~~~~~~~~~~

- All images should be in PNG format and compressed where possible. For PNG
  files, use OptiPNG and AdvanceCOMP's ``advpng``:

  ::

     $ optipng -o7 -zm1-9 -i0 -strip all <path_to_png>
     $ advpng -z4 <path_to_png>

- Any ASCII text "images" should be included in code-blocks to preserve
  formatting

- Include other reStructuredText verbatim in a current document

Comments
~~~~~~~~

- Comments are indicated by means of the ``..`` marker.::

      .. TODO(stephenfin) This section needs some work. This TODO will not
         appear in the final generated document, however.

Man Pages
---------

In addition to the above, man pages have some specific requirements:

- You **must** define the following sections:

  - Synopsis

  - Description

  - Options

  Note that `NAME` is not included - this is automatically generated by Sphinx
  and should not be manually defined. Also note that these do not need to be
  uppercase - Sphinx will do this automatically.

  Additional sections are allowed. Refer to `man-pages(8)` for information on
  the sections generally allowed.

- You **must not** define a `NAME` section.

  See above.

- The `OPTIONS` section must describe arguments and options using the
  `program`__ and `option`__ directives.

  This ensures the output is formatted correctly and that you can
  cross-reference various programs and commands from the documentation. For
  example::

      .. program:: ovs-do-something

      .. option:: -f, --force

          Force the operation

      .. option:: -b <bridge>, --bridge <bridge>

          Name or ID of bridge

  .. important::

     Option argument names should be enclosed in angle brackets, as above.

- Any references to the application or any other Open vSwitch application must
  be marked up using the `program` role.

  This allows for easy linking in the HTML output and correct formatting in the
  man page output. For example::

      To do something, run :program:`ovs-do-something`.

- The man page must be included in the list of man page documents found in
  `conf.py`__

Refer to existing man pages, such as :doc:`/ref/ovs-vlan-test.8` for a worked
example.

__ http://www.sphinx-doc.org/en/stable/domains.html#directive-program
__ http://www.sphinx-doc.org/en/stable/domains.html#directive-option
__ http://www.sphinx-doc.org/en/stable/config.html#confval-man_pages

Writing Style
-------------

Follow these guidelines to ensure readability and consistency of the Open
vSwitch documentation. These guidelines are based on the `/*IBM Style Guide/*
<https://www.ibm.com/developerworks/library/styleguidelines/>`__.

- Use standard US English

  Use a spelling and grammar checking tool as necessary.

- Expand initialisms and acronyms on first usage.

  Commonly used terms like CPU or RAM are allowed.

  .. list-table::
     :header-rows: 1

     * - Do not use
       - Do use
     * - OVS is a virtual switch. OVS has...
       - Open vSwitch (OVS) is a virtual switch. OVS has...
     * - The VTEP emulator is...
       - The Virtual Tunnel Endpoint (VTEP) emulator is...

- Write in the active voice

  The subject should do the verb's action, rather than be acted upon.

  .. list-table::
     :header-rows: 1

     * - Do not use
       - Do use
     * - A bridge is created by you
       - Create a bridge

- Write in the present tense

  .. list-table::
     :header-rows: 1

     * - Do not use
       - Do use
     * - Once the bridge is created, you can create a port
       - Once the bridge is created, create a port

- Write in second person

  .. list-table::
     :header-rows: 1

     * - Do not use
       - Do use
     * - To create a bridge, the user runs:
       - To create a bridge, run:

- Keep sentences short and concise

- Eliminate needless politeness

  Avoid "please" and "thank you"

Helpful Tools
-------------

There are a number of tools, online and offline, which can be used to preview
documents are you edit them:

- `ReText <https://github.com/retext-project/retext>`__

  A simple but powerful editor for Markdown and reStructuredText. ReText is
  written in Python.

- `restview <https://mg.pov.lt/restview/>`__

  A viewer for ReStructuredText documents that renders them on the fly.

Useful Links
------------

- `Quick reStructuredText
  <http://docutils.sourceforge.net/docs/user/rst/quickref.html>`__

- `Sphinx Documentation
  <http://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`__