mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add version information for methods in `utils.docutils` (#12649)
This commit is contained in:
@@ -366,30 +366,47 @@ class SphinxDirective(Directive):
|
|||||||
|
|
||||||
This class provides helper methods for Sphinx directives.
|
This class provides helper methods for Sphinx directives.
|
||||||
|
|
||||||
|
.. versionadded:: 1.8
|
||||||
|
|
||||||
.. note:: The subclasses of this class might not work with docutils.
|
.. note:: The subclasses of this class might not work with docutils.
|
||||||
This class is strongly coupled with Sphinx.
|
This class is strongly coupled with Sphinx.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def env(self) -> BuildEnvironment:
|
def env(self) -> BuildEnvironment:
|
||||||
"""Reference to the :class:`.BuildEnvironment` object."""
|
"""Reference to the :class:`.BuildEnvironment` object.
|
||||||
|
|
||||||
|
.. versionadded:: 1.8
|
||||||
|
"""
|
||||||
return self.state.document.settings.env
|
return self.state.document.settings.env
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self) -> Config:
|
def config(self) -> Config:
|
||||||
"""Reference to the :class:`.Config` object."""
|
"""Reference to the :class:`.Config` object.
|
||||||
|
|
||||||
|
.. versionadded:: 1.8
|
||||||
|
"""
|
||||||
return self.env.config
|
return self.env.config
|
||||||
|
|
||||||
def get_source_info(self) -> tuple[str, int]:
|
def get_source_info(self) -> tuple[str, int]:
|
||||||
"""Get source and line number."""
|
"""Get source and line number.
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
"""
|
||||||
return self.state_machine.get_source_and_line(self.lineno)
|
return self.state_machine.get_source_and_line(self.lineno)
|
||||||
|
|
||||||
def set_source_info(self, node: Node) -> None:
|
def set_source_info(self, node: Node) -> None:
|
||||||
"""Set source and line number to the node."""
|
"""Set source and line number to the node.
|
||||||
|
|
||||||
|
.. versionadded:: 2.1
|
||||||
|
"""
|
||||||
node.source, node.line = self.get_source_info()
|
node.source, node.line = self.get_source_info()
|
||||||
|
|
||||||
def get_location(self) -> str:
|
def get_location(self) -> str:
|
||||||
"""Get current location info for logging."""
|
"""Get current location info for logging.
|
||||||
|
|
||||||
|
.. versionadded:: 4.2
|
||||||
|
"""
|
||||||
source, line = self.get_source_info()
|
source, line = self.get_source_info()
|
||||||
if source and line:
|
if source and line:
|
||||||
return f'{source}:{line}'
|
return f'{source}:{line}'
|
||||||
@@ -473,6 +490,8 @@ class SphinxRole:
|
|||||||
|
|
||||||
This class provides helper methods for Sphinx roles.
|
This class provides helper methods for Sphinx roles.
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
.. note:: The subclasses of this class might not work with docutils.
|
.. note:: The subclasses of this class might not work with docutils.
|
||||||
This class is strongly coupled with Sphinx.
|
This class is strongly coupled with Sphinx.
|
||||||
"""
|
"""
|
||||||
@@ -517,24 +536,35 @@ class SphinxRole:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def env(self) -> BuildEnvironment:
|
def env(self) -> BuildEnvironment:
|
||||||
"""Reference to the :class:`.BuildEnvironment` object."""
|
"""Reference to the :class:`.BuildEnvironment` object.
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
|
"""
|
||||||
return self.inliner.document.settings.env
|
return self.inliner.document.settings.env
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self) -> Config:
|
def config(self) -> Config:
|
||||||
"""Reference to the :class:`.Config` object."""
|
"""Reference to the :class:`.Config` object.
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
|
"""
|
||||||
return self.env.config
|
return self.env.config
|
||||||
|
|
||||||
def get_source_info(self, lineno: int | None = None) -> tuple[str, int]:
|
def get_source_info(self, lineno: int | None = None) -> tuple[str, int]:
|
||||||
|
# .. versionadded:: 3.0
|
||||||
if lineno is None:
|
if lineno is None:
|
||||||
lineno = self.lineno
|
lineno = self.lineno
|
||||||
return self.inliner.reporter.get_source_and_line(lineno) # type: ignore[attr-defined]
|
return self.inliner.reporter.get_source_and_line(lineno) # type: ignore[attr-defined]
|
||||||
|
|
||||||
def set_source_info(self, node: Node, lineno: int | None = None) -> None:
|
def set_source_info(self, node: Node, lineno: int | None = None) -> None:
|
||||||
|
# .. versionadded:: 2.0
|
||||||
node.source, node.line = self.get_source_info(lineno)
|
node.source, node.line = self.get_source_info(lineno)
|
||||||
|
|
||||||
def get_location(self) -> str:
|
def get_location(self) -> str:
|
||||||
"""Get current location info for logging."""
|
"""Get current location info for logging.
|
||||||
|
|
||||||
|
.. versionadded:: 4.2
|
||||||
|
"""
|
||||||
source, line = self.get_source_info()
|
source, line = self.get_source_info()
|
||||||
if source and line:
|
if source and line:
|
||||||
return f'{source}:{line}'
|
return f'{source}:{line}'
|
||||||
@@ -551,6 +581,8 @@ class ReferenceRole(SphinxRole):
|
|||||||
The reference roles can accept ``link title <target>`` style as a text for
|
The reference roles can accept ``link title <target>`` style as a text for
|
||||||
the role. The parsed result; link title and target will be stored to
|
the role. The parsed result; link title and target will be stored to
|
||||||
``self.title`` and ``self.target``.
|
``self.title`` and ``self.target``.
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
has_explicit_title: bool #: A boolean indicates the role has explicit title or not.
|
has_explicit_title: bool #: A boolean indicates the role has explicit title or not.
|
||||||
@@ -591,6 +623,8 @@ class SphinxTranslator(nodes.NodeVisitor):
|
|||||||
|
|
||||||
It also provides helper methods for Sphinx translators.
|
It also provides helper methods for Sphinx translators.
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
.. note:: The subclasses of this class might not work with docutils.
|
.. note:: The subclasses of this class might not work with docutils.
|
||||||
This class is strongly coupled with Sphinx.
|
This class is strongly coupled with Sphinx.
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user