Debian Codegraph @

doc/usage/domains/index.rst

raw
1 .. highlight:: rst
2
3 .. _usage-domains:
4
5 =======
6 Domains
7 =======
8
9 .. versionadded:: 1.0
10
11 Originally, Sphinx was conceived for a single project, the documentation of the
12 Python language. Shortly afterwards, it was made available for everyone as a
13 documentation tool, but the documentation of Python modules remained deeply
14 built in -- the most fundamental directives, like ``function``, were designed
15 for Python objects. Since Sphinx has become somewhat popular, interest
16 developed in using it for many different purposes: C/C++ projects, JavaScript,
17 or even reStructuredText markup (like in this documentation).
18
19 While this was always possible, it is now much easier to easily support
20 documentation of projects using different programming languages or even ones
21 not supported by the main Sphinx distribution, by providing a **domain** for
22 every such purpose.
23
24 A domain is a collection of markup (reStructuredText :term:`directive`\ s and
25 :term:`role`\ s) to describe and link to :term:`object`\ s belonging together,
26 e.g. elements of a programming language. Directive and role names in a domain
27 have names like ``domain:name``, e.g. ``py:function``. Domains can also
28 provide custom indices (like the Python Module Index).
29
30 Having domains means that there are no naming problems when one set of
31 documentation wants to refer to e.g. C++ and Python classes. It also means
32 that extensions that support the documentation of whole new languages are much
33 easier to write.
34
35 This section describes what the domains that are included with Sphinx provide.
36 The domain API is documented as well, in the section :ref:`domain-api`.
37
38 Built-in domains
39 ----------------
40
41 The following domains are included within Sphinx:
42
43 .. toctree::
44 :maxdepth: 1
45
46 standard
47 c
48 cpp
49 javascript
50 mathematics
51 python
52 restructuredtext
53
54
55 Third-party domains
56 -------------------
57
58 Several third-party domains are available as extensions, including:
59
60 * `Ada <https://pypi.org/project/sphinxcontrib-adadomain/>`__
61 * `Antlr4 <https://pypi.org/project/sphinx-syntax/>`__
62 * `Bazel <https://pypi.org/project/sphinx-bazel/>`__
63 * `BibTex <https://pypi.org/project/sphinxcontrib-bibtex/>`__
64 * `Bison/YACC <https://pypi.org/project/sphinx-syntax/>`__
65 * `Chapel <https://pypi.org/project/sphinxcontrib-chapeldomain/>`__
66 * `CMake <https://pypi.org/project/sphinxcontrib-moderncmakedomain/>`__
67 * `Common Lisp <https://pypi.org/project/sphinxcontrib-cldomain/>`__
68 * `Erlang <https://pypi.org/project/sphinxcontrib-erlangdomain/>`__
69 * `Fortran <https://pypi.org/project/sphinx-fortran/>`__
70 * `GraphQL <https://pypi.org/project/graphqldomain/>`__
71 * `Go <https://pypi.org/project/sphinxcontrib-golangdomain/>`__
72 * `HTTP <https://pypi.org/project/sphinxcontrib-httpdomain/>`__
73 * `Hy <https://pypi.org/project/sphinxcontrib-hydomain/>`__
74 * `Lua <https://pypi.org/project/sphinx-lua-ls/>`__
75 * `MATLAB <https://pypi.org/project/sphinxcontrib-matlabdomain/>`__
76 * `PHP <https://pypi.org/project/sphinxcontrib-phpdomain/>`__
77 * `Ruby <https://pypi.org/project/sphinxcontrib-rubydomain/>`__
78 * `Rust <https://pypi.org/project/sphinxcontrib-rust/>`__
79 * `Verilog <https://pypi.org/project/sphinx-verilog-domain/>`__
80 * `VHDL <https://pypi.org/project/sphinx-vhdl/>`__
81 * `Visual Basic <https://pypi.org/project/sphinx-vb-domain/>`__
82
83 Other domains may be found on the Python Package Index
84 (via the `Framework :: Sphinx :: Domain`__ classifier),
85 `GitHub <https://github.com/search?q=sphinx%20domain&type=repositories>`__, or
86 `GitLab <https://gitlab.com/explore/projects?name=sphinx%20domain>`__.
87
88 __ https://pypi.org/search/?c=Framework+%3A%3A+Sphinx+%3A%3A+Domain
89
90 .. NOTE: The following all seem unmaintained, last released 2018 or earlier.
91 The links are preserved in this comment for reference.
92
93 * `CoffeeScript <https://pypi.org/project/sphinxcontrib-coffee/>`__
94 * `DotNET <https://pypi.org/project/sphinxcontrib-dotnetdomain/>`__
95 * `dqn <https://pypi.org/project/sphinxcontrib-dqndomain/>`__
96 * `Jinja <https://pypi.org/project/sphinxcontrib-jinjadomain/>`__
97 * `JSON <https://pypi.org/project/sphinx-jsondomain/>`__
98 * `Lasso <https://pypi.org/project/sphinxcontrib-lassodomain/>`__
99 * `Operation <https://pypi.org/project/sphinxcontrib-operationdomain/>`__
100 * `Scala <https://pypi.org/project/sphinxcontrib-scaladomain/>`__
101 * `Lua <https://pypi.org/project/sphinxcontrib-luadomain/>`__
102
103
104 .. _basic-domain-markup:
105
106 Basic Markup
107 ------------
108
109 Most domains provide a number of :dfn:`object description directives`, used to
110 describe specific objects provided by modules. Each directive requires one or
111 more signatures to provide basic information about what is being described, and
112 the content should be the description.
113
114 A domain will typically keep an internal index of all entities to aid
115 cross-referencing.
116 Typically, it will also add entries in the shown general index.
117 If you want to suppress the addition of an entry in the shown index, you can
118 give the directive option flag ``:no-index-entry:``.
119 If you want to exclude the object description from the table of contents, you
120 can give the directive option flag ``:no-contents-entry:``.
121 If you want to typeset an object description, without even making it available
122 for cross-referencing, you can give the directive option flag ``:no-index:``
123 (which implies ``:no-index-entry:``).
124 If you do not want to typeset anything, you can give the directive option flag
125 ``:no-typesetting:``. This can for example be used to create only a target and
126 index entry for later reference.
127 Though, note that not every directive in every domain may support these
128 options.
129
130 .. versionadded:: 3.2
131 The directive option ``noindexentry`` in the Python, C, C++, and Javascript
132 domains.
133
134 .. versionadded:: 5.2.3
135 The directive option ``:nocontentsentry:`` in the Python, C, C++, Javascript,
136 and reStructuredText domains.
137
138 .. versionadded:: 7.2
139 The directive option ``no-typesetting`` in the Python, C, C++, Javascript,
140 and reStructuredText domains.
141
142 .. versionchanged:: 7.2
143
144 * The directive option ``:noindex:`` was renamed
145 to ``:no-index:``.
146 * The directive option ``:noindexentry:`` was renamed
147 to ``:no-index-entry:``.
148 * The directive option ``:nocontentsentry:`` was renamed
149 to ``:no-contents-entry:``.
150
151 The previous names are retained as aliases,
152 but will be deprecated and removed
153 in a future version of Sphinx.
154
155 An example using a Python domain directive::
156
157 .. py:function:: spam(eggs)
158 ham(eggs)
159
160 Spam or ham the foo.
161
162 This describes the two Python functions ``spam`` and ``ham``. (Note that when
163 signatures become too long, you can break them if you add a backslash to lines
164 that are continued in the next line. Example::
165
166 .. py:function:: filterwarnings(action, message='', category=Warning, \
167 module='', lineno=0, append=False)
168 :no-index:
169
170 (This example also shows how to use the ``:no-index:`` flag.)
171
172 The domains also provide roles that link back to these object descriptions.
173 For example, to link to one of the functions described in the example above,
174 you could say ::
175
176 The function :py:func:`spam` does a similar thing.
177
178 As you can see, both directive and role names contain the domain name and the
179 directive name.
180
181 The directive option ``:no-typesetting:`` can be used to create a target
182 (and index entry) which can later be referenced
183 by the roles provided by the domain.
184 This is particularly useful for literate programming:
185
186 .. code-block:: rst
187
188 .. py:function:: spam(eggs)
189 :no-typesetting:
190
191 .. code:: python
192
193 def spam(eggs):
194 pass
195
196 The function :py:func:`spam` does nothing.
197
198 .. rubric:: Default Domain
199
200 For documentation describing objects from solely one domain, authors will not
201 have to state again its name at each directive, role, etc... after
202 having specified a default. This can be done either via the config
203 value :confval:`primary_domain` or via this directive:
204
205 .. rst:directive:: .. default-domain:: name
206
207 Select a new default domain. While the :confval:`primary_domain` selects a
208 global default, this only has an effect within the same file.
209
210 If no other default is selected, the Python domain (named ``py``) is the
211 default one, mostly for compatibility with documentation written for older
212 versions of Sphinx.
213
214 Directives and roles that belong to the default domain can be mentioned without
215 giving the domain name, i.e. ::
216
217 .. function:: pyfunc()
218
219 Describes a Python function.
220
221 Reference to :func:`pyfunc`.
222
223 Cross-referencing syntax
224 ~~~~~~~~~~~~~~~~~~~~~~~~
225
226 For cross-reference roles provided by domains,
227 the same :ref:`cross-referencing modifiers <xref-modifiers>` exist
228 as for general cross-references.
229 In short:
230
231 * You may supply an explicit title and reference target:
232 ``:py:mod:`mathematical functions <math>``` will refer to the ``math`` module,
233 but the link text will be "mathematical functions".
234
235 * If you prefix the content with an exclamation mark (``!``),
236 no reference/hyperlink will be created.
237
238 * If you prefix the content with ``~``, the link text will only be the last
239 component of the target.
240 For example, ``:py:meth:`~queue.Queue.get``` will
241 refer to ``queue.Queue.get`` but only display ``get`` as the link text.