Debian Codegraph @

doc/usage/builders/index.rst

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