blob: 5e99a9d985e1c30f7bf56be518c0eb75d61a9f42 [file] [log] [blame]
thmsdt21d59412022-08-02 13:28:17 +02001.. This work is licensed under a Creative Commons Attribution 4.0
2.. International License. http://creativecommons.org/licenses/by/4.0
3.. Copyright 2017 AT&T Intellectual Property. All rights reserved.
4.. Copyright 2022 ONAP
5
6.. _creating-rst:
7
8Creating ReStructuredText
9=========================
10
11ReStructuredText markup conventions
12-----------------------------------
13For detailed information on ReStructuredText and how to best use the format,
14see:
15
16- `ReStructured Text Primer <http://docutils.sourceforge.net/docs/user/rst/quickstart.html>`_
17- `ReStructured Text Quick Reference <http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_
18
19
20Templates and Examples
21----------------------
22Templates are available that capture the kinds of information
23useful for different types of projects and provide some examples of
24restructured text. We organize templates in the following way to:
25
26 - help authors understand relationships between documents
27
28 - keep the user audience context in mind when writing and
29
30 - tailor sections for different kinds of projects.
31
32
33**Sections** Represent a certain type of content. A section
34is **provided** in an project repository, to describe something about
35the characteristics, use, capability, etc. of things in that repository.
36A section may also be **referenced** from other sections and in
37other repositories. For example, an API specification provided in a project
38repository might be referenced to in a Platform API Reference Guide.
39The notes in the beginning of each section template provide
40additional detail about what is typically covered and where
41there may be references to the section.
42
43**Collections** Are a set of sections that are typically provided
44for a particular type of project, repository, guide, reference manual, etc.
45For example, a collection for a platform component, an SDK, etc.
46
47You can: browse the template *collections* and *sections* below;
48show source to look at the Restructured Text and Sphinx directives used.
49
50Sections
51++++++++
52
53Section examples are available here: :ref:`Templates<templates>`
54
55Collections
56+++++++++++
57
58In addition to these simple templates and examples
59there are many open source projects (e.g. Open Daylight, Open Stack)
60that are using Sphinx and Readthedocs where you may find examples
61to start with. Working with project teams we will continue to enhance
62templates here and capture frequently asked questions on the developer
63wiki question topic `documentation <https://wiki.onap.org/questions/topics/16384055/documentation>`_.
64
65Each project should:
66
67 - decide what is relevant content
68
69 - determine the best way to create/maintain it in the CI/CD process and
70
71 - work with the documentation team to reference content from the
72 master index and guides.
73
74Consider options including filling in a template, identifying existing
75content that can be used as is or easily converted, and use of Sphinx
76directives/extensions to automatically generate restructured text
77from other source you already have.
78
79Collection examples are available here: :ref:`Templates<templates>`
80
81Links and References
82--------------------
83It's pretty common to want to reference another location in the
84ONAP documentation and it's pretty easy to do with
85reStructuredText. This is a quick primer, more information is in the
86`Sphinx section on Cross-referencing arbitrary locations
87<http://www.sphinx-doc.org/en/stable/markup/inline.html>`_.
88
89Within a single document, you can reference another section simply by::
90
91 This is a reference to `The title of a section`_
92
93Assuming that somewhere else in the same file there a is a section
94title something like::
95
96 The title of a section
97 ^^^^^^^^^^^^^^^^^^^^^^
98
99It's typically better to use ``:ref:`` syntax and labels to provide
100links as they work across files and are resilient to sections being
101renamed. First, you need to create a label something like::
102
103 .. _a-label:
104
105 The title of a section
106 ^^^^^^^^^^^^^^^^^^^^^^
107
108.. note:: The underscore (_) before the label is required.
109
110Then you can reference the section anywhere by simply doing::
111
112 This is a reference to :ref:`a-label`
113
114or::
115
116 This is a reference to :ref:`a section I really liked <a-label>`
117
118.. note:: When using ``:ref:``-style links, you don't need a trailing
119 underscore (_).
120
121Because the labels have to be unique, it usually makes sense to prefix
122the labels with the project name to help share the label space, e.g.,
123``sfc-user-guide`` instead of just ``user-guide``.
124
125Index File
126----------
127
128The index file must relatively reference your other rst files in that directory.
129
130Here is an example index.rst :
131
132.. code-block:: bash
133
134 *******************
135 Documentation Title
136 *******************
137
138 .. toctree::
139 :numbered:
140 :maxdepth: 2
141
142 documentation-example
143
144Source Files
145------------
146
147Document source files have to be written in reStructuredText format (rst).
148Each file would be built as an html page.
149
150Here is an example source rst file :
151
152.. code-block:: bash
153
154 =============
155 Chapter Title
156 =============
157
158 Section Title
159 =============
160
161 Subsection Title
162 ----------------
163
164 Hello!
165
166Writing RST Markdown
167--------------------
168
169See http://sphinx-doc.org/rest.html .
170
171**Hint:**
172You can add html content that only appears in html output by using the
173'only' directive with build type
174('html' and 'singlehtml') for an ONAP document. But, this is not encouraged.
175
176.. code-block:: bash
177
178 .. only:: html
179 This line will be shown only in html version.
180
181
182Creating Indices
183----------------
184
185Building an index for your Sphinx project is relatively simple. First, tell Sphinx that
186you want it to build an index by adding something like this after your TOC tree:
187
188.. code-block:: rst
189
190 Indices and Search
191 ==================
192
193 * :ref:`genindex`
194 * :ref:`search`
195
196**Hint:**
197Note that search was included here. It works out of the box with any Sphinx project, so you
198don't need to do anything except include a reference to it in your :code:`index.rst` file.
199
200Now, to generate a index entry in your RST, do one of the following:
201
202.. code-block:: rst
203
204 Some content that requires an :index:`index`.
205
206or
207
208.. code-block:: rst
209
210 .. index::
211 single: myterm
212
213 Some header containing myterm
214 =============================
215
216In the second case, Sphinx will create a link in the index to the paragraph that follows
217the index entry declaration.
218
219When your project is built, Sphinx will generate an index page populated with the entries
220you created in the source RST.
221
222These are simple cases with simple options. For more information about indexing with Sphinx,
223please see the `official Sphinx documentation <http://www.sphinx-doc.org/en/stable/markup/misc.html>`_.
224
225
226Jenkins Jobs
227------------
228
229Verify Job
230++++++++++
231
232The verify job name is **doc-{stream}-verify-rtd**
233
234Proposed changes in files in any repository with top level docs folder
235in the repository and RST files in below this folder
236will be verified by this job as part of a gerrit code review.
237
238.. Important::
239 The contributing author and every reviewer on a gerrit code review
240 should always review the Jenkins log before approving and merging a
241 change. The log review should include:
242
243 * Using a browser or other editor to search for a pattern in the
244 *console log* that matches files in the patch set. This will quickly
245 identify errors and warnings that are related to the patch set and
246 repository being changed.
247
248 * Using a browser to click on the *html* folder included in the log
249 and preview how the proposed changes will look when published at
250 Read The Docs. Small changes can be easily made in the patch set.
251
252Merge Job
253+++++++++
254
255The merge job name is **doc-{stream}-merge-rtd**.
256
257When a committer merges a patch that includes files matching the
258path described above, the doc project merge job will trigger an
259update at readthedocs. There may be some delay after the merge job
260completes until new version appears at Read The Docs.
261
262Testing
263=======
264
265One RST File
266------------
267It is recommended that all rst content is validated by `doc8 <https://pypi.python.org/pypi/doc8>`_ standards.
268To validate your rst files using doc8, install doc8.
269
270.. code-block:: bash
271
272 sudo pip install doc8
273
274doc8 can now be used to check the rst files. Execute as,
275
276.. code-block:: bash
277
278 doc8 --ignore D000,D001 <file>
279
280
281
282One Project
283-----------
284To test how the documentation renders in HTML, follow these steps:
285
286Install `virtual environment <https://pypi.org/project/virtualenv>`_ & create one.
287
288.. code-block:: bash
289
290 sudo pip install virtualenv
291 virtualenv onap_docs
292
293Activate `onap_docs` virtual environment.
294
295.. code-block:: bash
296
297 source onap_docs/bin/activate
298
299.. note:: Virtual environment activation has to be performed before attempting to build documentation.
300 Otherwise, tools necessary for the process might not be available.
301
302Download a project repository.
303
304.. code-block:: bash
305
306 git clone http://gerrit.onap.org/r/<project>
307
308Download the doc repository.
309
310.. code-block:: bash
311
312 git clone http://gerrit.onap.org/r/doc
313
314Change directory to doc & install requirements.
315
316.. code-block:: bash
317
318 cd doc
319 pip install -r etc/requirements.txt
320
321.. warning::
322
323 Just follow the next step (copying conf.py from Doc project to your project)
324 if that is your intention, otherwise skip it. Currently all projects should already have a conf.py file.
325 Through the next step, this file and potential extensions in your project get overriden.
326
327Copy the conf.py file to your project folder where RST files have been kept:
328
329.. code-block:: bash
330
331 cp docs/conf.py <path-to-project-folder>/<folder where are rst files>
332
333Copy the static files to the project folder where RST files have been kept:
334
335.. code-block:: bash
336
337 cp -r docs/_static/ <path-to-project-folder>/<folder where are rst files>
338
339Build the documentation from within your project folder:
340
341.. code-block:: bash
342
343 sphinx-build -b html <path-to-project-folder>/<folder where are rst files> <path-to-output-folder>
344
345Your documentation shall be built as HTML inside the
346specified output folder directory.
347
348You can use your Web Browser to open
349and check resulting html pages in the output folder.
350
351.. note:: Be sure to remove the `conf.py`, the static/ files and the output folder from the `<project>/docs/`. This is for testing only. Only commit the rst files and related content.
352
353.. _building-all-documentation:
354
355All Documentation
356-----------------
357To build the all documentation under doc/, follow these steps:
358
359Install `tox <https://pypi.org/project/tox>`_.
360
361.. code-block:: bash
362
363 sudo pip install tox
364
365Download the DOC repository.
366
367.. code-block:: bash
368
369 git clone http://gerrit.onap.org/r/doc
370
371Build documentation using tox local environment & then open using any browser.
372
373.. code-block:: bash
374
375 cd doc
376 tox -elocal
377 firefox docs/_build/html/index.html
378
379.. note:: Make sure to run `tox -elocal` and not just `tox`.
380 This updates all submodule repositories that are integrated
381 by the doc project.
382
383There are additional tox environment options for checking External
384URLs and Spelling. Use the tox environment options below and then
385look at the output with the Linux `more` or similar command
386scan for output that applies to the files you are validating.
387
388.. code-block:: bash
389
390 tox -elinkcheck
391 more < docs/_build/linkcheck/output.txt
392
393 tox -espellcheck
394 more < docs/_build/spellcheck/output.txt