1 ========================
3 ========================
6 :Contact: docutils-develop@lists.sourceforge.net
9 :Copyright: This document has been placed in the public domain.
14 The ``docutils.core.Publisher`` class is the core of Docutils,
15 managing all the processing and relationships between components. See
16 `PEP 258`_ for an overview of Docutils components.
18 The ``docutils.core.publish_*`` convenience functions are the normal
19 entry points for using Docutils as a library.
21 See `Inside A Docutils Command-Line Front-End Tool`_ for an overview
22 of a typical Docutils front-end tool, including how the Publisher
25 .. _PEP 258: ../peps/pep-0258.html
26 .. _Inside A Docutils Command-Line Front-End Tool: ./cmdline-tool.html
29 Publisher Convenience Functions
30 ===============================
32 Each of these functions set up a ``docutils.core.Publisher`` object,
33 then call its ``publish`` method. ``docutils.core.Publisher.publish``
34 handles everything else. There are several convenience functions in
35 the ``docutils.core`` module:
37 :_`publish_cmdline`: for command-line front-end tools, like
38 ``rst2html.py``. There are several examples in the ``tools/``
39 directory. A detailed analysis of one such tool is in `Inside A
40 Docutils Command-Line Front-End Tool`_
42 :_`publish_file`: for programmatic use with file-like I/O. In
43 addition to writing the encoded output to a file, also returns the
44 encoded output as a string.
46 :_`publish_string`: for programmatic use with string I/O. Returns
47 the encoded output as a string.
49 :_`publish_parts`: for programmatic use with string input; returns a
50 dictionary of document parts. Dictionary keys are the names of
51 parts, and values are Unicode strings; encoding is up to the client.
52 Useful when only portions of the processed document are desired.
53 See `publish_parts Details`_ below.
55 There are usage examples in the `docutils/examples.py`_ module.
57 :_`publish_doctree`: for programmatic use with string input; returns a
58 Docutils document tree data structure (doctree). The doctree can be
59 modified, pickled & unpickled, etc., and then reprocessed with
60 `publish_from_doctree`_.
62 :_`publish_from_doctree`: for programmatic use to render from an
63 existing document tree data structure (doctree); returns the encoded
66 :_`publish_programmatically`: for custom programmatic use. This
67 function implements common code and is used by ``publish_file``,
68 ``publish_string``, and ``publish_parts``. It returns a 2-tuple:
69 the encoded string output and the Publisher object.
71 .. _Inside A Docutils Command-Line Front-End Tool: ./cmdline-tool.html
72 .. _docutils/examples.py: ../../docutils/examples.py
78 To pass application-specific setting defaults to the Publisher
79 convenience functions, use the ``settings_overrides`` parameter. Pass
80 a dictionary of setting names & values, like this::
82 overrides = {'input_encoding': 'ascii',
83 'output_encoding': 'latin-1'}
84 output = publish_string(..., settings_overrides=overrides)
86 Settings from command-line options override configuration file
87 settings, and they override application defaults. For details, see
88 `Docutils Runtime Settings`_. See `Docutils Configuration Files`_ for
89 details about individual settings.
91 .. _Docutils Runtime Settings: ./runtime-settings.html
92 .. _Docutils Configuration Files: ../user/tools.html
98 The default output encoding of Docutils is UTF-8. If you have any
99 non-ASCII in your input text, you may have to do a bit more setup.
100 Docutils may introduce some non-ASCII text if you use
101 `auto-symbol footnotes`_ or the `"contents" directive`_.
103 .. _auto-symbol footnotes:
104 ../ref/rst/restructuredtext.html#auto-symbol-footnotes
105 .. _"contents" directive:
106 ../ref/rst/directives.html#table-of-contents
109 ``publish_parts`` Details
110 =========================
112 The ``docutils.core.publish_parts`` convenience function returns a
113 dictionary of document parts. Dictionary keys are the names of parts,
114 and values are Unicode strings.
116 Each Writer component may publish a different set of document parts,
117 described below. Not all writers implement all parts.
120 Parts Provided By All Writers
121 -----------------------------
124 The output encoding setting.
127 The version of Docutils used.
130 ``parts['whole']`` contains the entire formatted document.
135 Parts Provided By the HTML Writer
136 ---------------------------------
139 ``parts['body']`` is equivalent to parts['fragment_']. It is
140 *not* equivalent to parts['html_body_'].
143 ``parts['body_prefix']`` contains::
147 <div class="document" ...>
156 ``parts['body_pre_docinfo]`` contains (as applicable)::
158 <h1 class="title">...</h1>
159 <h2 class="subtitle" id="...">...</h2>
162 ``parts['body_suffix']`` contains::
166 (the end-tag for ``<div class="document">``), the footer division
179 ``parts['docinfo']`` contains the document bibliographic data, the
180 docinfo field list rendered as a table.
183 ``parts['footer']`` contains the document footer content, meant to
184 appear at the bottom of a web page, or repeated at the bottom of
188 ``parts['fragment']`` contains the document body (*not* the HTML
189 ``<body>``). In other words, it contains the entire document,
190 less the document title, subtitle, docinfo, header, and footer.
193 ``parts['head']`` contains ``<meta ... />`` tags and the document
194 ``<title>...</title>``.
197 ``parts['head_prefix']`` contains the XML declaration, the DOCTYPE
198 declaration, the ``<html ...>`` start tag and the ``<head>`` start
202 ``parts['header']`` contains the document header content, meant to
203 appear at the top of a web page, or repeated at the top of every
207 ``parts['html_body']`` contains the HTML ``<body>`` content, less
208 the ``<body>`` and ``</body>`` tags themselves.
211 ``parts['html_head']`` contains the HTML ``<head>`` content, less
212 the stylesheet link and the ``<head>`` and ``</head>`` tags
213 themselves. Since ``publish_parts`` returns Unicode strings and
214 does not know about the output encoding, the "Content-Type" meta
215 tag's "charset" value is left unresolved, as "%s"::
217 <meta http-equiv="Content-Type" content="text/html; charset=%s" />
219 The interpolation should be done by client code.
222 ``parts['html_prolog]`` contains the XML declaration and the
223 doctype declaration. The XML declaration's "encoding" attribute's
224 value is left unresolved, as "%s"::
226 <?xml version="1.0" encoding="%s" ?>
228 The interpolation should be done by client code.
231 ``parts['html_subtitle']`` contains the document subtitle,
232 including the enclosing ``<h2 class="subtitle">`` & ``</h2>``
236 ``parts['html_title']`` contains the document title, including the
237 enclosing ``<h1 class="title">`` & ``</h1>`` tags.
240 ``parts['meta']`` contains all ``<meta ... />`` tags.
243 ``parts['stylesheet']`` contains the embedded stylesheet or
247 ``parts['subtitle']`` contains the document subtitle text and any
248 inline markup. It does not include the enclosing ``<h2>`` &
252 ``parts['title']`` contains the document title text and any inline
253 markup. It does not include the enclosing ``<h1>`` & ``</h1>``
257 Parts Provided by the PEP/HTML Writer
258 `````````````````````````````````````
260 The PEP/HTML writer provides the same parts as the `HTML writer`_,
264 ``parts['pepnum']`` contains
267 Parts Provided by the S5/HTML Writer
268 ````````````````````````````````````
270 The S5/HTML writer provides the same parts as the `HTML writer`_.
273 Parts Provided by the LaTeX2e Writer
274 ------------------------------------
276 See the template files for examples how these parts can be combined
277 into a valid LaTeX document.
280 ``parts['abstract']`` contains the formatted content of the
281 'abstract' docinfo field.
284 ``parts['body']`` contains the document's content. In other words, it
285 contains the entire document, except the document title, subtitle, and
288 This part can be included into another LaTeX document body using the
289 ``\input{}`` command.
292 ``parts['body_pre_docinfo]`` contains the ``\maketitle`` command.
295 ``parts['dedication']`` contains the formatted content of the
296 'dedication' docinfo field.
299 ``parts['docinfo']`` contains the document bibliographic data, the
300 docinfo field list rendered as a table.
302 With ``--use-latex-docinfo`` 'author', 'organization', 'contact',
303 'address' and 'date' info is moved to titledata.
305 'dedication' and 'abstract' are always moved to separate parts.
308 ``parts['fallbacks']`` contains fallback definitions for
309 Docutils-specific commands and environments.
312 ``parts['head_prefix']`` contains the declaration of
313 documentclass and document options.
316 ``parts['latex_preamble']`` contains the argument of the
317 ``--latex-preamble`` option.
320 ``parts['pdfsetup']`` contains the PDF properties
321 ("hyperref" package setup).
324 ``parts['requirements']`` contains required packages and setup
325 before the stylesheet inclusion.
328 ``parts['stylesheet']`` contains the embedded stylesheet(s) or
329 stylesheet loading command(s).
332 ``parts['subtitle']`` contains the document subtitle text and any
336 ``parts['title']`` contains the document title text and any inline
340 ``parts['titledata]`` contains the combined title data in
341 ``\title``, ``\author``, and ``\data`` macros.
343 With ``--use-latex-docinfo``, this includes the 'author',
344 'organization', 'contact', 'address' and 'date' docinfo items.