lib.writers

Docutils writers for Django Docutils, designed for cleaner output.

class django_docutils.lib.writers.ParentNodeClassTuple(parent_node_type: Type[Node | Body], args: List[str], kwargs: Dict[str, str], close_tag: str | None)[source]

Bases: NamedTuple

Typing for parent node accepting custom arguments.

parent_node_type: Type[Union[Node, Body]]

Alias for field number 0

args: List[str]

Alias for field number 1

kwargs: Dict[str, str]

Alias for field number 2

close_tag: Optional[str]

Alias for field number 3

_asdict()[source]

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('parent_node_type', 'args', 'kwargs', 'close_tag')
classmethod _make(iterable)[source]

Make a new ParentNodeClassTuple object from a sequence or iterable

_replace(**kwds)[source]

Return a new ParentNodeClassTuple object replacing specified fields with new values

class django_docutils.lib.writers.DjangoDocutilsHTMLTranslator(document)[source]

Bases: HTMLTranslator

Django Docutils touchups to docutil’s HTML renderer.

visit_table(node)[source]

Open table.

Return type:

None

visit_reference(node)[source]

Open reference.

Changes: :rtype: None

  • Monkeypatch bugfix https://sourceforge.net/p/docutils/bugs/322/

  • Add target _blank to offsite urls

  • Add class offsite for offsite urls

  • Add class insite for insite urls (note, internal is already used for reference links in the same document)

visit_title(node)[source]

Visit docutils title.

Changes: :rtype: None

  • Add backlinks for Contents refid headers

    They’re baked inside the Section (parent) of the anchor since we’re using an ad-hoc contents transformation process that builds toc separately from the main content (see templatetags)

  • s/with-subtitle/subtitle for bulma css

_visit_section_title(node, close_tag)[source]

Our special sauce for section titles.

Extracted from visit_title() to reduce complexity.

Parameters:
  • node (docutils.nodes.title) – Title node being visited

  • close_tag (str) – Close tag (passed in from visit_title)

Returns:

Close tag for section title node.

Return type:

str

visit_docinfo(node)[source]

Skip docinfo.

Return type:

None

visit_icon(node)[source]

Open <em> tag.

Return type:

None

depart_icon(node)[source]

Close <em> tag.

Return type:

None

class django_docutils.lib.writers.DjangoDocutilsWriter[source]

Bases: Writer

DjangoDocutils’s hand-crafted docutils’ writer.

Example:

>>> DJANGO_DOCUTILS_LIB_RST = {
...    'transforms': [  #: docutils.transforms.Transform class (import string)
...        'django_docutils.lib.transforms.xref.XRefTransform'
...    ]
... }
get_transforms()[source]

Return transformed required by DjangoDocutilsWriter.

Adheres to DJANGO_DOCUTILS_LIB_RST settings.

Return type:

List[Type[Transform]]