There are several convenience functions in the docutils.core module.
Each of these functions sets up a docutils.core.Publisher object,
then calls its publish() method which handles everything else.
For details, see the argument reference, the function docstrings
and the source file core.py.
The function reads input from sys.stdin or a file specified on the
command line, writes the output document to a file, and also returns it
as str instance. [2]
Get the input from the source argument
(a str or bytes instance).
Return the output document as a bytes instance unless the
output_encoding runtime setting has the special value "unicode". [3]
Example:
Return a Docutils XML version of the source as str instance:
For programmatic use with string output.
Render from an existing Document Tree data structure
(nodes.document instance).
Return the output document as a bytes or str instance
(cf. publish_string()).
For programmatic use. With string input (default) or file input
(depending on the value of the source_class argument).
Returns a dictionary of document parts.
(the end-tag for <div class="document">), the footer division
if applicable:
<div class="footer">
...
</div>
and
</body>
</html>
"docinfo"
Bibliographic data, i.e. the <docinfo> element's content, [4]
rendered as a table.
"footer"
The document footer content, meant to
appear at the bottom of a web page, or repeated at the bottom of
every printed page.
"fragment"
The document body (not the HTML <body>).
In other words, part['fragment'] contains the entire document,
less the document "title", "subtitle", "docinfo",
"header", and "footer". Equivalent to part "body".
"head"
Contains <meta ... /> tags and the document
<title>...</title>. See also "html_head".
"head_prefix"
The XML declaration, the DOCTYPE declaration,
the <html ...> start tag, and the <head> start tag.
"header"
The document header content, meant to appear at the top
of a web page, or repeated at the top of every printed page.
"html_body"
The HTML <body> content,
less the <body> and </body> tags themselves.
"html_head"
The HTML <head> content, less the "stylesheet"
and the <head> and </head> tags themselves.
The "Content-Type" meta tag's "charset" value is left unresolved,
as %s:
The HTML5 writer provides the same parts as the HTML4 writer.
However, it uses semantic HTML5 elements for the document, "header", and
"footer" and a description list for the "docinfo" part.
The function publish_file() uses the file I/O interface;
publish_parts() can be configured to use file input
by setting the source_class argument to docutils.io.FileInput.
sourcefile-like
A file-like object holding the document source
(must have read() and close() methods).
Default: None (open source_path
or use sys.stdin).
source_pathstr | pathlib.Path
Path to the source file,
opened if source is None.
The document source. bytes are decoded with the encoding
specified in the input_encoding setting.
Required.
source_pathstr
Path to the file or name of the object that produced
source.
Used as "source" attribute in diagnostic output.
Default: None.
source_classdocutils.io.Input
Change the semantics of the "source" and "source_path" arguments.
The value docutils.io.FileInput lets "source" and "source_path"
behave as described in file I/O.
Default: docutils.io.StringInput.
destination_pathstr
Path to the file or name of the object which will receive the output.
Used for determining relative paths (stylesheets, source links, etc.)
Runtime settings object.
If settings is passed, it's assumed to be the end result of
runtime settings processing and no further setting/config/option
processing is done.
Application-specific settings definitions, independent of components.
In other words, the application becomes a component, and its settings
data is processed after the other components.
Used only if settings is None.
Default: None.
settings_overridesdict
Application-specific settings defaults that override the defaults
of other components. Used only if settings is None.
Default: None.
config_sectionstr
Name of the configuration file section for this application.