Debian Codegraph @

doc/usage/extensions/autosectionlabel.rst

raw
1 .. highlight:: rst
2
3 :mod:`sphinx.ext.autosectionlabel` -- Allow referencing sections by their title
4 ===============================================================================
5
6 .. module:: sphinx.ext.autosectionlabel
7 :synopsis: Allow referencing sections by their title.
8
9 .. versionadded:: 1.4
10
11 .. role:: code-py(code)
12 :language: Python
13
14 By default, cross-references to sections use labels (see :rst:role:`ref`).
15 This extension allows you to instead refer to sections by their title.
16
17 For example::
18
19 A Plain Title
20 -------------
21
22 This is the text of the section.
23
24 It refers to the section title, see :ref:`A Plain Title`.
25
26
27 Internally, this extension generates the labels for each section. If same
28 section names are used in whole of document, any one is used for a target by
29 default. The ``autosectionlabel_prefix_document`` configuration variable can be
30 used to make headings which appear multiple times but in different documents
31 unique.
32
33
34 Configuration
35 -------------
36
37 .. confval:: autosectionlabel_prefix_document
38 :type: :code-py:`bool`
39 :default: :code-py:`False`
40
41 True to prefix each section label with the name of the document it is in,
42 followed by a colon. For example, ``index:Introduction`` for a section
43 called ``Introduction`` that appears in document ``index.rst``. Useful for
44 avoiding ambiguity when the same section heading appears in different
45 documents.
46
47 .. confval:: autosectionlabel_maxdepth
48 :type: :code-py:`int | None`
49 :default: :code-py:`None`
50
51 If set, autosectionlabel chooses the sections for labeling by its depth. For
52 example, when set 1 to ``autosectionlabel_maxdepth``, labels are generated
53 only for top level sections, and deeper sections are not labeled. It
54 defaults to ``None`` (i.e. all sections are labeled).
55
56
57 Debugging
58 ---------
59
60 The ``WARNING: undefined label`` indicates that your reference in
61 :rst:role:`ref` is mis-spelled. Invoking :program:`sphinx-build` with ``-vvv``
62 (see :option:`-v`) will print all section names and the labels that have been
63 generated for them. This output can help finding the right reference label.