Debian Codegraph @

doc/usage/builders/index.rst

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 .. _builders:
2
3 ========
4 Builders
5 ========
6
7 .. module:: sphinx.builders
8 :synopsis: Available built-in builder classes.
9
10 These are the built-in Sphinx builders. More builders can be added by
11 :doc:`extensions </usage/extensions/index>`.
12
13 The builder's "name" must be given to the **-M** or **-b** command-line options of
14 :program:`sphinx-build` to select a builder.
15
16 The most common builders are:
17
18 **html**
19 Build HTML pages. This is the default builder.
20
21 **dirhtml**
22 Build HTML pages, but with a single directory per document. Makes for
23 prettier URLs (no ``.html``) if served from a webserver.
24
25 **singlehtml**
26 Build a single HTML with the whole content.
27
28 **htmlhelp**, **qthelp**, **devhelp**, **epub**
29 Build HTML files with additional information for building a documentation
30 collection in one of these formats.
31
32 **applehelp**
33 Build an Apple Help Book. Requires :program:`hiutil` and
34 :program:`codesign`, which are not Open Source and presently only
35 available on Mac OS X 10.6 and higher.
36
37 **latex**
38 Build LaTeX sources that can be compiled to a PDF document using
39 :program:`pdflatex`.
40
41 **man**
42 Build manual pages in groff format for UNIX systems.
43
44 **texinfo**
45 Build Texinfo files that can be processed into Info files using
46 :program:`makeinfo`.
47
48 **text**
49 Build plain text files.
50
51 **gettext**
52 Build gettext-style message catalogs (``.pot`` files).
53
54 **doctest**
55 Run all doctests in the documentation, if the :mod:`~sphinx.ext.doctest`
56 extension is enabled.
57
58 **linkcheck**
59 Check the integrity of all external links.
60
61 **xml**
62 Build Docutils-native XML files.
63
64 **pseudoxml**
65 Build compact pretty-printed "pseudo-XML" files displaying the
66 internal structure of the intermediate document trees.
67
68 --------------
69
70 .. module:: sphinx.builders.html
71 .. class:: StandaloneHTMLBuilder
72
73 This is the standard HTML builder. Its output is a directory with HTML
74 files, complete with style sheets and optionally the reStructuredText sources.
75 There are quite a few configuration values that customize
76 the output of this builder, see the chapter :ref:`html-options` for details.
77
78 .. autoattribute:: name
79
80 .. autoattribute:: format
81
82 .. autoattribute:: supported_image_types
83
84 .. module:: sphinx.builders.dirhtml
85 .. class:: DirectoryHTMLBuilder
86
87 This is a subclass of the standard HTML builder. Its output is a directory
88 with HTML files, where each file is called ``index.html`` and placed in a
89 subdirectory named like its page name. For example, the document
90 ``markup/rest.rst`` will not result in an output file ``markup/rest.html``,
91 but ``markup/rest/index.html``. When generating links between pages, the
92 ``index.html`` is omitted, so that the URL would look like ``markup/rest/``.
93
94 .. autoattribute:: name
95
96 .. autoattribute:: format
97
98 .. autoattribute:: supported_image_types
99
100 .. versionadded:: 0.6
101
102 .. module:: sphinx.builders.singlehtml
103 .. class:: SingleFileHTMLBuilder
104
105 This is an HTML builder that combines the whole project in one output file.
106 (Obviously this only works with smaller projects.) The file is named like
107 the root document. No indices will be generated.
108
109 .. autoattribute:: name
110
111 .. autoattribute:: format
112
113 .. autoattribute:: supported_image_types
114
115 .. versionadded:: 1.0
116
117 .. module:: sphinxcontrib.htmlhelp
118 .. class:: HTMLHelpBuilder
119
120 This builder produces the same output as the standalone HTML builder, but
121 also generates HTML Help support files that allow the Microsoft HTML Help
122 Workshop to compile them into a CHM file.
123
124 .. autoattribute:: name
125
126 .. autoattribute:: format
127
128 .. autoattribute:: supported_image_types
129
130 .. module:: sphinxcontrib.qthelp
131 .. class:: QtHelpBuilder
132
133 This builder produces the same output as the standalone HTML builder, but
134 also generates `Qt help`_ collection support files that allow the Qt
135 collection generator to compile them.
136
137 .. versionchanged:: 2.0
138
139 Moved to sphinxcontrib.qthelp from sphinx.builders package.
140
141 .. autoattribute:: name
142
143 .. autoattribute:: format
144
145 .. autoattribute:: supported_image_types
146
147 .. _Qt help: https://doc.qt.io/qt-4.8/qthelp-framework.html
148
149 .. module:: sphinxcontrib.applehelp
150 .. class:: AppleHelpBuilder
151
152 This builder produces an Apple Help Book based on the same output as the
153 standalone HTML builder.
154
155 If the source directory contains any ``.lproj`` folders, the one
156 corresponding to the selected language will have its contents merged with
157 the generated output. These folders will be ignored by all other
158 documentation types.
159
160 In order to generate a valid help book, this builder requires the command
161 line tool :program:`hiutil`, which is only available on Mac OS X 10.6 and
162 above. You can disable the indexing step by setting
163 :confval:`applehelp_disable_external_tools` to ``True``, in which case the
164 output will not be valid until :program:`hiutil` has been run on all of the
165 ``.lproj`` folders within the bundle.
166
167 .. autoattribute:: name
168
169 .. autoattribute:: format
170
171 .. autoattribute:: supported_image_types
172
173 .. versionadded:: 1.3
174
175 .. versionchanged:: 2.0
176
177 Moved to sphinxcontrib.applehelp from sphinx.builders package.
178
179 .. module:: sphinxcontrib.devhelp
180 .. class:: DevhelpBuilder
181
182 This builder produces the same output as the standalone HTML builder, but
183 also generates `GNOME Devhelp <https://wiki.gnome.org/Apps/Devhelp>`__
184 support file that allows the GNOME Devhelp reader to view them.
185
186 .. autoattribute:: name
187
188 .. autoattribute:: format
189
190 .. autoattribute:: supported_image_types
191
192 .. versionchanged:: 2.0
193
194 Moved to sphinxcontrib.devhelp from sphinx.builders package.
195
196 .. module:: sphinx.builders.epub3
197 .. class:: Epub3Builder
198
199 This builder produces the same output as the standalone HTML builder, but
200 also generates an *epub* file for ebook readers. See :ref:`epub-faq` for
201 details about it. For definition of the epub format, have a look at
202 `<https://idpf.org/epub>`_ or `<https://en.wikipedia.org/wiki/EPUB>`_.
203 The builder creates *EPUB 3* files.
204
205 .. autoattribute:: name
206
207 .. autoattribute:: format
208
209 .. autoattribute:: supported_image_types
210
211 .. versionadded:: 1.4
212
213 .. versionchanged:: 1.5
214
215 Since Sphinx 1.5, the epub3 builder is used as the default epub builder.
216
217 .. module:: sphinx.builders.latex
218 .. class:: LaTeXBuilder
219
220 This builder produces LaTeX source files in the output directory. The
221 actual PDF builds happen inside this output directory and need to be
222 triggered in a second step. This can be done via
223 :program:`make all-pdf` there.
224 To combine the two steps into only one, use :option:`sphinx-build -M`
225 (i.e. ``-M latexpdf`` not ``-b latexpdf``) or :program:`make latexpdf`
226 at the project root.
227
228 See :confval:`latex_documents` and the chapter :ref:`latex-options` for
229 available options.
230
231 PDF builds need a sufficiently complete LaTeX installation.
232 The testing is currently (since 5.3.0) done on Ubuntu 22.04LTS,
233 whose LaTeX distribution matches upstream TeXLive 2021 as of 2022/02/04,
234 but PDF builds can be successfully done on much older LaTeX installations.
235
236 At any rate, on Ubuntu for example, following packages must all be present:
237
238 * ``texlive-latex-recommended``
239 * ``texlive-fonts-recommended``
240 * ``texlive-fonts-extra`` (needed for ``fontawesome5``, see the 7.4.0
241 change notice below)
242 * ``tex-gyre`` (if :confval:`latex_engine` left to default)
243 * ``texlive-latex-extra``
244 * ``latexmk``
245
246 .. versionchanged:: 4.0.0
247 TeX Gyre fonts now required for ``'pdflatex'`` engine (default).
248
249 .. versionchanged:: 7.4.0
250 LaTeX package ``xcolor`` is now required (it is part of Ubuntu
251 ``texlive-latex-recommended`` anyhow). The LaTeX package
252 ``fontawesome5`` is recommended. See the :ref:`'sphinxsetup'
253 <latexsphinxsetup>` ``iconpackage`` key for more.
254
255 Additional packages are needed in some circumstances:
256
257 * ``texlive-lang-cyrillic`` for Cyrillic (and also then
258 ``cm-super`` if using the default fonts),
259 * ``texlive-lang-greek`` for Greek (and also then
260 ``cm-super`` if using the default fonts),
261 * ``texlive-xetex`` if :confval:`latex_engine` is ``'xelatex'``,
262 * ``texlive-luatex`` if :confval:`latex_engine` is ``'lualatex'``,
263 * ``fonts-freefont-otf`` if :confval:`latex_engine` is either
264 ``'xelatex'`` or ``'lualatex'``.
265
266 .. note::
267
268 Since 1.6, ``make latexpdf`` uses on GNU/Linux and macOS
269 :program:`latexmk`, as it
270 makes sure the needed number of runs is automatically executed.
271 On Windows the PDF builds execute a fix number of LaTeX runs
272 (three, then ``makeindex``, then two more).
273
274 One can pass to ``latexmk`` options via the ``LATEXMKOPTS``
275 Makefile variable. For example:
276
277 .. code-block:: console
278
279 make latexpdf LATEXMKOPTS="-silent"
280
281 reduces console output to a minimum.
282
283 Also, if ``latexmk`` is at version 4.52b or higher (January 2017)
284 ``LATEXMKOPTS="-xelatex"`` speeds up PDF builds via XeLateX in case
285 of numerous graphics inclusions.
286
287 To pass options directly to the ``(pdf|xe|lua)latex`` binary, use
288 variable ``LATEXOPTS``, for example:
289
290 .. code-block:: console
291
292 make latexpdf LATEXOPTS="--halt-on-error"
293
294 .. autoattribute:: name
295
296 .. autoattribute:: format
297
298 .. autoattribute:: supported_image_types
299
300 Note that a direct PDF builder is being provided by `rinohtype`_. The builder's
301 name is ``rinoh``. Refer to the `rinohtype manual`_ for details.
302
303 .. _rinohtype: https://github.com/brechtm/rinohtype
304 .. _rinohtype manual: https://www.mos6581.org/rinohtype/master/quickstart.html#sphinx-builder
305
306 .. module:: sphinx.builders.text
307 .. class:: TextBuilder
308
309 This builder produces a text file for each reStructuredText file.
310 This is almost the same as the reStructuredText source,
311 but with much of the markup stripped for better readability.
312
313 .. autoattribute:: name
314
315 .. autoattribute:: format
316
317 .. autoattribute:: supported_image_types
318
319 .. versionadded:: 0.4
320
321 .. module:: sphinx.builders.manpage
322 .. class:: ManualPageBuilder
323
324 This builder produces manual pages in the groff format. You have to specify
325 which documents are to be included in which manual pages via the
326 :confval:`man_pages` configuration value.
327
328 .. autoattribute:: name
329
330 .. autoattribute:: format
331
332 .. autoattribute:: supported_image_types
333
334 .. versionadded:: 1.0
335
336
337 .. module:: sphinx.builders.texinfo
338 .. class:: TexinfoBuilder
339
340 This builder produces Texinfo files that can be processed into Info files by
341 the :program:`makeinfo` program. You have to specify which documents are to
342 be included in which Texinfo files via the :confval:`texinfo_documents`
343 configuration value.
344
345 The Info format is the basis of the on-line help system used by GNU Emacs and
346 the terminal-based program :program:`info`. See :ref:`texinfo-faq` for more
347 details. The Texinfo format is the official documentation system used by the
348 GNU project. More information on Texinfo can be found at
349 `<https://www.gnu.org/software/texinfo/>`_.
350
351 .. autoattribute:: name
352
353 .. autoattribute:: format
354
355 .. autoattribute:: supported_image_types
356
357 .. versionadded:: 1.1
358
359
360 .. currentmodule:: sphinxcontrib.serializinghtml
361 .. class:: SerializingHTMLBuilder
362
363 This builder uses a module that implements the Python serialization API
364 (``pickle``, ``simplejson``, ``phpserialize``, and others) to dump the
365 generated HTML documentation. The pickle builder is a subclass of it.
366
367 A concrete subclass of this builder serializing to the `PHP serialization`_
368 format could look like this::
369
370 import phpserialize
371
372 class PHPSerializedBuilder(SerializingHTMLBuilder):
373 name = 'phpserialized'
374 implementation = phpserialize
375 out_suffix = '.file.phpdump'
376 globalcontext_filename = 'globalcontext.phpdump'
377 searchindex_filename = 'searchindex.phpdump'
378
379 .. _PHP serialization: https://pypi.org/project/phpserialize/
380
381 .. attribute:: implementation
382
383 A module that implements ``dump()``, ``load()``, ``dumps()`` and ``loads()``
384 functions that conform to the functions with the same names from the
385 pickle module. Known modules implementing this interface are
386 ``simplejson``, ``phpserialize``, ``plistlib``, and others.
387
388 .. attribute:: out_suffix
389
390 The suffix for all regular files.
391
392 .. attribute:: globalcontext_filename
393
394 The filename for the file that contains the "global context". This
395 is a dict with some general configuration values such as the name
396 of the project.
397
398 .. attribute:: searchindex_filename
399
400 The filename for the search index Sphinx generates.
401
402 See :ref:`serialization-details` for details about the output format.
403
404 .. versionadded:: 0.5
405
406 .. class:: PickleHTMLBuilder
407
408 This builder produces a directory with pickle files containing mostly HTML
409 fragments and TOC information, for use of a web application (or custom
410 postprocessing tool) that doesn't use the standard HTML templates.
411
412 See :ref:`serialization-details` for details about the output format.
413
414 .. autoattribute:: name
415
416 The old name ``web`` still works as well.
417
418 .. autoattribute:: format
419
420 .. autoattribute:: supported_image_types
421
422 The file suffix is ``.fpickle``. The global context is called
423 ``globalcontext.pickle``, the search index ``searchindex.pickle``.
424
425 .. class:: JSONHTMLBuilder
426
427 This builder produces a directory with JSON files containing mostly HTML
428 fragments and TOC information, for use of a web application (or custom
429 postprocessing tool) that doesn't use the standard HTML templates.
430
431 See :ref:`serialization-details` for details about the output format.
432
433 .. autoattribute:: name
434
435 .. autoattribute:: format
436
437 .. autoattribute:: supported_image_types
438
439 The file suffix is ``.fjson``. The global context is called
440 ``globalcontext.json``, the search index ``searchindex.json``.
441
442 .. versionadded:: 0.5
443
444 .. module:: sphinx.builders.gettext
445 .. class:: MessageCatalogBuilder
446
447 This builder produces gettext-style message catalogs. Each top-level file or
448 subdirectory grows a single ``.pot`` catalog template.
449
450 See the documentation on :ref:`intl` for further reference.
451
452 .. autoattribute:: name
453
454 .. autoattribute:: format
455
456 .. autoattribute:: supported_image_types
457
458 .. versionadded:: 1.1
459
460 .. module:: sphinx.builders.changes
461 .. class:: ChangesBuilder
462
463 This builder produces an HTML overview of all :rst:dir:`versionadded`,
464 :rst:dir:`versionchanged`, :rst:dir:`deprecated` and :rst:dir:`versionremoved`
465 directives for the current :confval:`version`. This is useful to generate a
466 changelog file, for example.
467
468 .. autoattribute:: name
469
470 .. autoattribute:: format
471
472 .. autoattribute:: supported_image_types
473
474 .. module:: sphinx.builders.dummy
475 .. class:: DummyBuilder
476
477 This builder produces no output. The input is only parsed and checked for
478 consistency. This is useful for linting purposes.
479
480 .. autoattribute:: name
481
482 .. autoattribute:: supported_image_types
483
484 .. versionadded:: 1.4
485
486 .. module:: sphinx.builders.linkcheck
487 .. class:: CheckExternalLinksBuilder
488
489 This builder scans all documents for external links, tries to open them with
490 ``requests``, and writes an overview which ones are broken and redirected to
491 standard output and to :file:`output.txt` in the output directory.
492
493 .. autoattribute:: name
494
495 .. autoattribute:: format
496
497 .. autoattribute:: supported_image_types
498
499 .. versionchanged:: 1.5
500
501 Since Sphinx 1.5, the linkcheck builder uses the requests module.
502
503 .. versionchanged:: 3.4
504
505 The linkcheck builder retries links when servers apply rate limits.
506
507 .. module:: sphinx.builders.xml
508 .. class:: XMLBuilder
509
510 This builder produces Docutils-native XML files. The output can be
511 transformed with standard XML tools such as XSLT processors into arbitrary
512 final forms.
513
514 .. autoattribute:: name
515
516 .. autoattribute:: format
517
518 .. autoattribute:: supported_image_types
519
520 .. versionadded:: 1.2
521
522 .. class:: PseudoXMLBuilder
523
524 This builder is used for debugging the Sphinx/Docutils "Reader to Transform
525 to Writer" pipeline. It produces compact pretty-printed "pseudo-XML", files
526 where nesting is indicated by indentation (no end-tags). External
527 attributes for all elements are output, and internal attributes for any
528 leftover "pending" elements are also given.
529
530 .. autoattribute:: name
531
532 .. autoattribute:: format
533
534 .. autoattribute:: supported_image_types
535
536 .. versionadded:: 1.2
537
538
539 Built-in Sphinx extensions that offer more builders are:
540
541 * :mod:`~sphinx.ext.doctest`
542 * :mod:`~sphinx.ext.coverage`
543
544
545 .. _serialization-details:
546
547 Serialization builder details
548 -----------------------------
549
550 All serialization builders outputs one file per source file and a few special
551 files. They also copy the reStructuredText source files
552 to the ``_sources`` directory under the output directory.
553
554 The :class:`.PickleHTMLBuilder` is a builtin subclass that implements the pickle
555 serialization interface.
556
557 The files per source file have the extensions of
558 :attr:`~.SerializingHTMLBuilder.out_suffix`, and are arranged in directories
559 just as the source files are. They unserialize to a dictionary (or dictionary
560 like structure) with these keys:
561
562 ``body``
563 The HTML "body" (that is, the HTML rendering of the source file), as rendered
564 by the HTML translator.
565
566 ``title``
567 The title of the document, as HTML (may contain markup).
568
569 ``toc``
570 The table of contents for the file, rendered as an HTML ``<ul>``.
571
572 ``display_toc``
573 A boolean that is ``True`` if the ``toc`` contains more than one entry.
574
575 ``current_page_name``
576 The document name of the current file.
577
578 ``parents``, ``prev`` and ``next``
579 Information about related chapters in the TOC tree. Each relation is a
580 dictionary with the keys ``link`` (HREF for the relation) and ``title``
581 (title of the related document, as HTML). ``parents`` is a list of
582 relations, while ``prev`` and ``next`` are a single relation.
583
584 ``sourcename``
585 The name of the source file under ``_sources``.
586
587 The special files are located in the root output directory. They are:
588
589 :attr:`.SerializingHTMLBuilder.globalcontext_filename`
590 A pickled dict with these keys:
591
592 ``project``, ``copyright``, ``release``, ``version``
593 The same values as given in the configuration file.
594
595 ``style``
596 :confval:`html_style`.
597
598 ``last_updated``
599 Date of last build.
600
601 ``builder``
602 Name of the used builder, in the case of pickles this is always
603 ``'pickle'``.
604
605 ``titles``
606 A dictionary of all documents' titles, as HTML strings.
607
608 :attr:`.SerializingHTMLBuilder.searchindex_filename`
609 An index that can be used for searching the documentation. It is a pickled
610 list with these entries:
611
612 * A list of indexed docnames.
613 * A list of document titles, as HTML strings, in the same order as the first
614 list.
615 * A dict mapping word roots (processed by an English-language stemmer) to a
616 list of integers, which are indices into the first list.
617
618 ``environment.pickle``
619 The build environment. This is always a pickle file, independent of the
620 builder and a copy of the environment that was used when the builder was
621 started.
622
623 .. todo:: Document common members.
624
625 Unlike the other pickle files this pickle file requires that the ``sphinx``
626 package is available on unpickling.