1 ==========================
2 Sphinx Quickstart Template
3 ==========================
5 This article is intended to take someone in the state of “I want to write documentation and get it added to LLVM’s docs” and help them start writing documentation as fast as possible and with as little nonsense as possible.
13 LLVM documentation is written in `reStructuredText`_, a markup syntax similar to markdown (but much more powerful). The LLVM documentation site itself uses `Sphinx`_, a documentation generator originally written for Python documentation.
15 .. _`reStructuredText`: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
16 .. _`Sphinx`: http://www.sphinx-doc.org
18 How to use this template
19 ========================
21 This article is located in ``docs/SphinxQuickstartTemplate.rst``. To use it as a template, make a copy and open it in a text editor. You can then write your docs, and then send the new article to llvm-commits for review.
23 To view the restructuredText source file for this article, click **Show Source** on the right sidebar.
28 Focus on *content*. It is easy to fix the Sphinx (reStructuredText) syntax
29 later if necessary, although reStructuredText tries to imitate common
30 plain-text conventions so it should be quite natural. A basic knowledge of
31 reStructuredText syntax is useful when writing the document, so the last
32 ~half of this document (starting with `Example Section`_) gives examples
33 which should cover 99% of use cases.
35 Let me say that again: focus on *content*. But if you really need to verify
36 Sphinx's output, see ``docs/README.txt`` for information. Once you have finished with the content, please send the ``.rst`` file to
37 llvm-commits for review.
42 Before creating a new article, consider the following questions:
44 #. Why would I want to read this document?
46 #. What should I know to be able to follow along with this document?
48 #. What will I have learned by the end of this document?
50 A standard best practice is to make your articles task-oriented. You generally should not be writing documentation that isn't based around "how to" do something
51 unless there's already an existing "how to" article for the topic you're documenting. The reason for this is that without a "how to" article to read first, it might be difficult for
52 someone unfamiliar with the topic to understand a more advanced, conceptual article.
54 When creating a task-oriented article, follow existing LLVM articles by giving it a filename that starts with ``HowTo*.rst``. This format is usually the easiest for another person to understand and also the most useful.
56 Focus on content (yes, I had to say it again).
58 The rest of this document shows example reStructuredText markup constructs
59 that are meant to be read by you in your text editor after you have copied
60 this file into a new file for the documentation you are about to write.
65 An article can contain one or more sections (i.e., headings). Sections (like ``Example Section`` above) help give your document its
66 structure. Use the same kind of adornments (e.g. ``======`` vs. ``------``)
67 as are used in this document. The adornment must be the same length as the
68 text above it. For Vim users, variations of ``yypVr=`` might be handy.
70 Example Nested Subsection
71 -------------------------
73 Subsections can also be nested beneath other subsections. For more information on sections, see Sphinx's `reStructuredText Primer`_.
75 .. _`reStructuredText Primer`: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#sections
80 Text can be *emphasized*, **bold**, or ``monospace``.
82 To create a new paragraph, simply insert a blank line.
87 You can format a link `like this <https://llvm.org/>`_. A more `sophisticated syntax`_ allows you to place the ``.. _`link text`: <URL>`` block
88 pretty much anywhere else in the document. This is useful when linking to especially long URLs.
90 .. _`sophisticated syntax`: http://en.wikipedia.org/wiki/LLVM
95 restructuredText allows you to create ordered lists...
97 #. A list starting with ``#.`` will be automatically numbered.
99 #. This is a second list element.
101 #. Use indentation to create nested lists.
103 ...as well as unordered lists:
114 You can make blocks of code like this:
122 For a shell session, use a ``console`` code block (some existing docs use
125 .. code-block:: console
127 $ echo "Goodbye cruel world!"
130 If you need to show LLVM IR use the ``llvm`` code block.
134 define i32 @test1() {
139 Some other common code blocks you might need are ``c``, ``objc``, ``make``,
140 and ``cmake``. If you need something beyond that, you can look at the `full
141 list`_ of supported code blocks.
143 .. _`full list`: http://pygments.org/docs/lexers/
145 However, don't waste time fiddling with syntax highlighting when you could
146 be adding meaningful content. When in doubt, show preformatted text
147 without any syntax highlighting like this:
168 Generating the documentation
169 ============================
171 You can generate the HTML documentation from the sources locally if you want to
172 see what they would look like. In addition to the normal
173 `build tools <docs/GettingStarted.html>`_
174 you need to install `Sphinx`_ and the
175 `recommonmark <https://recommonmark.readthedocs.io/en/latest/>`_ extension.
177 On Debian you can install these with:
179 .. code-block:: console
181 sudo apt install -y sphinx-doc python-recommonmark-doc
183 On Ubuntu use pip to get an up-to-date version of recommonmark:
185 .. code-block:: console
187 sudo pip install sphinx recommonmark
189 Then run cmake to build the documentation inside the ``llvm-project`` checkout:
191 .. code-block:: console
195 cmake -DLLVM_ENABLE_SPHINX=On ../llvm
196 cmake --build . --target docs-llvm-html
198 In case you already have the Cmake build set up and want to reuse that,
199 just set the CMake variable ``LLVM_ENABLE_SPHINX=On``.
201 After that you find the generated documentation in ``build/docs/html``