lib.publisher¶
Docutils Publisher fors for Django Docutils.
-
django_docutils.lib.publisher.publish_parts_from_doctree(document, destination_path=None, writer=None, writer_name='pseudoxml', settings=None, settings_spec=None, settings_overrides=None, config_section=None, enable_exit_status=False)¶django_docutils.lib.publisher.publish_parts_from_doctree(document, destination_path=None, writer=None, writer_name='pseudoxml', settings=None, settings_spec=None, settings_overrides=None, config_section=None, enable_exit_status=False)¶
Render docutils doctree into docutils parts.
- Parameters:
document (
docutils.nodes.document) – Doctree to sanitize and render.destination_path (
str,optional) – Destination path handed to the docutils publisher.writer (
docutils.writers.Writer,optional) – Writer instance;writer_nameselects one when omitted.writer_name (
str) – Writer name used whenwriteris not given.settings (
optional) – Pre-built docutils settings object. The resolved security settings are written onto it, but configuration files it already read cannot be retroactively undone — preferNone.settings_spec (
optional) – docutils settings spec passed through to the publisher.settings_overrides (
mapping,optional) – Per-call Docutils settings resolved viaget_docutils_settings().config_section (
str,optional) – docutils configuration section passed through to the publisher.enable_exit_status (
bool) – Forwarded toPublisher.publish.
- Returns:
docutils parts (e.g.
html_body) keyed by part name.- Return type:
Examples
>>> doctree = publish_doctree("Hello **world**") >>> parts = publish_parts_from_doctree(doctree, writer=DjangoDocutilsWriter()) >>> "world" in parts["html_body"] True
-
django_docutils.lib.publisher.publish_toc_from_doctree(doctree, writer=None)¶django_docutils.lib.publisher.publish_toc_from_doctree(doctree, writer=None)¶
Publish table of contents from docutils doctree.
-
django_docutils.lib.publisher.publish_doctree(source, settings_overrides=None)¶django_docutils.lib.publisher.publish_doctree(source, settings_overrides=None)¶
Split off ability to get doctree (a.k.a. document).
It’s valuable to be able to run transforms to alter and most importantly, extract data like post abstracts.
- Parameters:
source (
str or bytes) – RST contentsettings_overrides (
dict) – Settings overrides for docutils
- Returns:
document/doctree for reStructuredText content
- Return type:
docutils.nodes.document
Examples
>>> doctree = publish_doctree("Hello **world**") >>> doctree.astext().startswith("Hello") True
-
class django_docutils.lib.publisher.PublishHtmlDocTreeKwargs¶class django_docutils.lib.publisher.PublishHtmlDocTreeKwargs¶
Bases:
TypedDictKeyword arguments accepted by publish_html_from_source.
-
django_docutils.lib.publisher.publish_html_from_source(source, **kwargs)¶django_docutils.lib.publisher.publish_html_from_source(source, **kwargs)¶
Return HTML from reStructuredText source string.
- Parameters:
source (
str) – reStructuredText content.**kwargs (
PublishHtmlDocTreeKwargs) – Rendering flags forwarded topublish_html_from_doctree().
- Returns:
Rendered HTML, or
Nonewhen only an empty TOC was requested.- Return type:
str or None
Examples
>>> html = publish_html_from_source("Hello **world**") >>> html is not None and "world" in html True
-
django_docutils.lib.publisher.publish_html_from_doctree(doctree, show_title=True, toc_only=False)¶django_docutils.lib.publisher.publish_html_from_doctree(doctree, show_title=True, toc_only=False)¶
Return HTML from reStructuredText document (doctree).
Examples
>>> doctree = publish_doctree("Hello **world**") >>> html = publish_html_from_doctree(doctree) >>> html is not None and "<strong>world</strong>" in html True