2007-07-23 04:02:25 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
sphinx.addnodes
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
2008-01-16 14:27:25 -06:00
|
|
|
Additional docutils nodes.
|
|
|
|
|
2016-01-14 15:54:04 -06:00
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
2008-12-27 05:19:17 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
2007-07-23 04:02:25 -05:00
|
|
|
"""
|
|
|
|
|
2016-02-13 21:02:57 -06:00
|
|
|
import warnings
|
|
|
|
|
2007-07-23 04:02:25 -05:00
|
|
|
from docutils import nodes
|
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
|
2016-09-10 01:36:57 -05:00
|
|
|
class translatable(object):
|
2016-08-21 08:15:50 -05:00
|
|
|
"""Node which supports translation.
|
|
|
|
|
|
|
|
The translation goes forward with following steps:
|
|
|
|
|
|
|
|
1. Preserve original translatable messages
|
|
|
|
2. Apply translated messages from message catalog
|
|
|
|
3. Extract preserved messages (for gettext builder)
|
|
|
|
|
|
|
|
The translatable nodes MUST preserve original messages.
|
|
|
|
And these messages should not be overridden at applying step.
|
|
|
|
Because they are used at final step; extraction.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def preserve_original_messages(self):
|
|
|
|
"""Preserve original translatable messages."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def apply_translated_message(self, original_message, translated_message):
|
|
|
|
"""Apply translated message."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def extract_original_messages(self):
|
|
|
|
"""Extract translation messages.
|
|
|
|
|
|
|
|
:returns: list of extracted messages or messages generator
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
|
|
|
class toctree(nodes.General, nodes.Element, translatable):
|
2010-08-22 04:09:35 -05:00
|
|
|
"""Node for inserting a "TOC tree"."""
|
|
|
|
|
2016-08-21 08:15:50 -05:00
|
|
|
def preserve_original_messages(self):
|
|
|
|
if 'caption' in self:
|
|
|
|
self['rawcaption'] = self['caption']
|
|
|
|
|
|
|
|
def apply_translated_message(self, original_message, translated_message):
|
|
|
|
if self.get('rawcaption') == original_message:
|
|
|
|
self['caption'] = translated_message
|
|
|
|
|
|
|
|
def extract_original_messages(self):
|
|
|
|
if 'rawcaption' in self:
|
|
|
|
return [self['rawcaption']]
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2009-10-27 13:58:40 -05:00
|
|
|
# domain-specific object descriptions (class, function etc.)
|
2008-06-18 13:16:25 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class desc(nodes.Admonition, nodes.Element):
|
|
|
|
"""Node for object descriptions.
|
|
|
|
|
|
|
|
This node is similar to a "definition list" with one definition. It
|
|
|
|
contains one or more ``desc_signature`` and a ``desc_content``.
|
|
|
|
"""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class desc_signature(nodes.Part, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for object signatures.
|
2008-06-18 13:16:25 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
The "term" part of the custom Sphinx definition list.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
# nodes to use within a desc_signature
|
|
|
|
|
|
|
|
class desc_addname(nodes.Part, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for additional name parts (module name, class name)."""
|
2008-06-18 13:16:25 -05:00
|
|
|
# compatibility alias
|
|
|
|
desc_classname = desc_addname
|
2010-08-22 04:09:35 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class desc_type(nodes.Part, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for return types or object type names."""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2008-12-25 15:06:10 -06:00
|
|
|
class desc_returns(desc_type):
|
2010-08-22 04:09:35 -05:00
|
|
|
"""Node for a "returns" annotation (a la -> in Python)."""
|
2008-12-25 15:06:10 -06:00
|
|
|
def astext(self):
|
|
|
|
return ' -> ' + nodes.TextElement.astext(self)
|
2010-08-22 04:09:35 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class desc_name(nodes.Part, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for the main object name."""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2007-12-05 20:00:01 -06:00
|
|
|
class desc_parameterlist(nodes.Part, nodes.Inline, nodes.TextElement):
|
2010-08-22 04:09:35 -05:00
|
|
|
"""Node for a general parameter list."""
|
2007-12-05 20:00:01 -06:00
|
|
|
child_text_separator = ', '
|
2010-08-22 04:09:35 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class desc_parameter(nodes.Part, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for a single parameter."""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2007-12-05 20:00:01 -06:00
|
|
|
class desc_optional(nodes.Part, nodes.Inline, nodes.TextElement):
|
2010-08-22 04:09:35 -05:00
|
|
|
"""Node for marking optional parts of the parameter list."""
|
2007-12-05 20:00:01 -06:00
|
|
|
child_text_separator = ', '
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2007-12-05 20:00:01 -06:00
|
|
|
def astext(self):
|
|
|
|
return '[' + nodes.TextElement.astext(self) + ']'
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class desc_annotation(nodes.Part, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for signature annotations (not Python 3-style annotations)."""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class desc_content(nodes.General, nodes.Element):
|
|
|
|
"""Node for object description content.
|
|
|
|
|
|
|
|
This is the "definition" part of the custom Sphinx definition list.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
# new admonition-like constructs
|
|
|
|
|
|
|
|
class versionmodified(nodes.Admonition, nodes.TextElement):
|
|
|
|
"""Node for version change entries.
|
|
|
|
|
|
|
|
Currently used for "versionadded", "versionchanged" and "deprecated"
|
|
|
|
directives.
|
|
|
|
"""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class seealso(nodes.Admonition, nodes.Element):
|
|
|
|
"""Custom "see also" admonition."""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class productionlist(nodes.Admonition, nodes.Element):
|
|
|
|
"""Node for grammar production lists.
|
|
|
|
|
|
|
|
Contains ``production`` nodes.
|
|
|
|
"""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class production(nodes.Part, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for a single grammar production rule."""
|
|
|
|
|
|
|
|
|
|
|
|
# other directive-level nodes
|
|
|
|
|
|
|
|
class index(nodes.Invisible, nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for index entries.
|
|
|
|
|
|
|
|
This node is created by the ``index`` directive and has one attribute,
|
2016-05-23 21:42:19 -05:00
|
|
|
``entries``. Its value is a list of 5-tuples of ``(entrytype, entryname,
|
|
|
|
target, ignored, key)``.
|
2010-08-22 04:09:35 -05:00
|
|
|
|
|
|
|
*entrytype* is one of "single", "pair", "double", "triple".
|
2016-05-25 08:59:03 -05:00
|
|
|
|
|
|
|
*key* is categolziation characters (usually it is single character) for
|
|
|
|
general index page. For the detail of this, please see also:
|
2016-05-27 09:08:02 -05:00
|
|
|
:rst:dir:`glossary` and issue #2320.
|
2010-08-22 04:09:35 -05:00
|
|
|
"""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2014-09-17 06:37:05 -05:00
|
|
|
class centered(nodes.Part, nodes.TextElement):
|
2010-08-22 04:09:35 -05:00
|
|
|
"""Deprecated."""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class acks(nodes.Element):
|
|
|
|
"""Special node for "acks" lists."""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class hlist(nodes.Element):
|
|
|
|
"""Node for "horizontal lists", i.e. lists that should be compressed to
|
|
|
|
take up less vertical space.
|
|
|
|
"""
|
2008-06-18 13:16:25 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class hlistcol(nodes.Element):
|
|
|
|
"""Node for one column in a horizontal list."""
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class compact_paragraph(nodes.paragraph):
|
|
|
|
"""Node for a compact paragraph (which never makes a <p> node)."""
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class glossary(nodes.Element):
|
|
|
|
"""Node to insert a glossary."""
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class only(nodes.Element):
|
|
|
|
"""Node for "only" directives (conditional inclusion based on tags)."""
|
2007-07-23 04:02:25 -05:00
|
|
|
|
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
# meta-information nodes
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class start_of_file(nodes.Element):
|
|
|
|
"""Node to mark start of a new file, used in the LaTeX builder only."""
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class highlightlang(nodes.Element):
|
|
|
|
"""Inserted to set the highlight language and line number options for
|
|
|
|
subsequent code blocks.
|
|
|
|
"""
|
2008-12-28 14:30:25 -06:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class tabular_col_spec(nodes.Element):
|
|
|
|
"""Node for specifying tabular columns, used for LaTeX output."""
|
2007-12-07 14:27:52 -06:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class meta(nodes.Special, nodes.PreBibliographic, nodes.Element):
|
|
|
|
"""Node for meta directive -- same as docutils' standard meta node,
|
|
|
|
but pickleable.
|
|
|
|
"""
|
2009-01-04 15:00:40 -06:00
|
|
|
|
2007-07-23 04:02:25 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
# inline nodes
|
2007-08-04 18:07:57 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class pending_xref(nodes.Inline, nodes.Element):
|
|
|
|
"""Node for cross-references that cannot be resolved without complete
|
|
|
|
information about all documents.
|
2009-03-05 02:48:55 -06:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
These nodes are resolved before writing output, in
|
|
|
|
BuildEnvironment.resolve_references.
|
|
|
|
"""
|
2007-08-17 01:27:35 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2014-09-30 21:38:41 -05:00
|
|
|
class number_reference(nodes.reference):
|
|
|
|
"""Node for number references, similar to pending_xref."""
|
|
|
|
|
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class download_reference(nodes.reference):
|
|
|
|
"""Node for download references, similar to pending_xref."""
|
2008-05-03 13:14:13 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class literal_emphasis(nodes.emphasis):
|
|
|
|
"""Node that behaves like `emphasis`, but further text processors are not
|
|
|
|
applied (e.g. smartypants for HTML output).
|
|
|
|
"""
|
2008-05-03 13:14:13 -05:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2014-01-12 10:01:22 -06:00
|
|
|
class literal_strong(nodes.strong):
|
|
|
|
"""Node that behaves like `strong`, but further text processors are not
|
|
|
|
applied (e.g. smartypants for HTML output).
|
|
|
|
"""
|
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
class abbreviation(nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for abbreviations with explanations."""
|
2009-02-19 14:56:34 -06:00
|
|
|
|
2014-09-21 13:21:43 -05:00
|
|
|
|
2016-02-13 21:02:57 -06:00
|
|
|
class termsep(nodes.Structural, nodes.Element):
|
|
|
|
"""Separates two terms within a <term> node.
|
|
|
|
|
|
|
|
.. versionchanged:: 1.4
|
|
|
|
sphinx.addnodes.termsep is deprecated. It will be removed at Sphinx-1.5.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kw):
|
|
|
|
warnings.warn('sphinx.addnodes.termsep will be removed at Sphinx-1.5',
|
|
|
|
DeprecationWarning, stacklevel=2)
|
|
|
|
super(termsep, self).__init__(*args, **kw)
|
2011-01-06 13:34:41 -06:00
|
|
|
|
2008-10-18 04:29:49 -05:00
|
|
|
|
2016-01-08 07:17:45 -06:00
|
|
|
class manpage(nodes.Inline, nodes.TextElement):
|
|
|
|
"""Node for references to manpages."""
|
|
|
|
|
|
|
|
|
2010-08-22 04:09:35 -05:00
|
|
|
# make the new nodes known to docutils; needed because the HTML writer will
|
|
|
|
# choke at some point if these are not added
|
|
|
|
nodes._add_node_class_names(k for k in globals().keys()
|
|
|
|
if k != 'nodes' and k[0] != '_')
|