lib.utils

Docutils util functions and regexes.

Some stuff is ported from sphinx:

  • explicit_title_re, ws_re, set_role_source_info, split_explicit_title

django_docutils.lib.utils.split_explicit_title(text)[source]

Split role content into title and target, if given (from sphinx).

Return type:

Tuple[bool, str, str]

django_docutils.lib.utils.chop_after_docinfo(source)[source]

Return the source of a document after DocInfo metadata.

Parameters:

source (str) – Source of RST document

Returns:

All source content after docinfo

Return type:

str

django_docutils.lib.utils.chop_after_title(source)[source]

Return the source of a document after document title.

Parameters:

source (str) – Source of RST document

Returns:

All source content after title

Return type:

str

django_docutils.lib.utils.chop_after_heading_smartly(source)[source]

Return the content after subtitle, or, if exists, docinfo.

This is a universal chop that can be used whether a document has docinfo, a title, subtitle, or not. Traditionally, directory-style RST fixtures keep metadata inside a JSON file instead of docinfo, so chop_after_docinfo() wouldn’t work.

Parameters:

source (str) – Source of RST document

Returns:

All source content after docinfo or title

Return type:

str

django_docutils.lib.utils.find_root_sections(document)[source]

Yield top level section nodes.

Parameters:

document (docutils.nodes.document) – Docutils document

Yields:

docutils.nodes.Node – Upper level titles of document

Return type:

Generator[Node, None, None]

django_docutils.lib.utils.append_html_to_node(node, ad_code)[source]

Inject HTML in this node.

Parameters:
  • node (docutils.nodes.node) – node of the section to find last paragraph of

  • ad_code (str) – html to inject inside ad

Return type:

None