diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-10-09 15:18:17 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-09 15:18:17 +0900 |
commit | 23bb8bee85b1871de5964e65fda7b3aac34fb7e4 (patch) | |
tree | d0e9178151ba75e6e62dfc928eeaacd84d8a61ac /sphinx/directives/patches.py | |
parent | 9c53175528ceb0268a18867522dc2425bf99912a (diff) | |
parent | 81a4fd973d4cfcb25d01a7b0be62cdb28f82406d (diff) | |
download | sphinx-git-23bb8bee85b1871de5964e65fda7b3aac34fb7e4.tar.gz |
Merge branch '4.x' into class-option-for-code-directive
Diffstat (limited to 'sphinx/directives/patches.py')
-rw-r--r-- | sphinx/directives/patches.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py index 428ae0ba4..0a076ad4f 100644 --- a/sphinx/directives/patches.py +++ b/sphinx/directives/patches.py @@ -14,7 +14,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Tuple, cast from docutils import nodes from docutils.nodes import Node, make_id, system_message from docutils.parsers.rst import directives -from docutils.parsers.rst.directives import html, images, tables +from docutils.parsers.rst.directives import images, tables from sphinx import addnodes from sphinx.deprecation import RemovedInSphinx60Warning @@ -27,6 +27,15 @@ from sphinx.util.nodes import set_source_info from sphinx.util.osutil import SEP, os_path, relpath from sphinx.util.typing import OptionSpec +try: + from docutils.nodes import meta as meta_node # type: ignore + from docutils.parsers.rst.directives.misc import Meta as MetaBase # type: ignore +except ImportError: + # docutils-0.17 or older + from docutils.parsers.rst.directives.html import Meta as MetaBase + from docutils.parsers.rst.directives.html import MetaBody + meta_node = MetaBody.meta + if TYPE_CHECKING: from sphinx.application import Sphinx @@ -60,19 +69,19 @@ class Figure(images.Figure): return [figure_node] -class Meta(html.Meta, SphinxDirective): +class Meta(MetaBase, SphinxDirective): def run(self) -> List[Node]: result = super().run() for node in result: if (isinstance(node, nodes.pending) and - isinstance(node.details['nodes'][0], html.MetaBody.meta)): + isinstance(node.details['nodes'][0], meta_node)): meta = node.details['nodes'][0] meta.source = self.env.doc2path(self.env.docname) meta.line = self.lineno - meta.rawcontent = meta['content'] # type: ignore + meta.rawcontent = meta['content'] # docutils' meta nodes aren't picklable because the class is nested - meta.__class__ = addnodes.meta # type: ignore + meta.__class__ = addnodes.meta return result |