summaryrefslogtreecommitdiff
path: root/sphinx/directives/patches.py
diff options
context:
space:
mode:
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>2022-04-17 04:36:20 +0100
committerAdam Turner <9087854+AA-Turner@users.noreply.github.com>2022-09-27 18:31:47 +0100
commit080517ce55119a6358337b5f939b3942e4de63b4 (patch)
tree4514c65dfca9aef4da848f42c41944da1118fd6c /sphinx/directives/patches.py
parent4660b62de0e83f42b6e2ede7a1a19e861e4d34e4 (diff)
downloadsphinx-git-080517ce55119a6358337b5f939b3942e4de63b4.tar.gz
Increase minimum Docutils to 0.17
Diffstat (limited to 'sphinx/directives/patches.py')
-rw-r--r--sphinx/directives/patches.py41
1 files changed, 20 insertions, 21 deletions
diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py
index 876683ad0..a0bf26262 100644
--- a/sphinx/directives/patches.py
+++ b/sphinx/directives/patches.py
@@ -19,11 +19,29 @@ from sphinx.util.osutil import SEP, os_path, relpath
from sphinx.util.typing import OptionSpec
try:
- from docutils.parsers.rst.directives.misc import Meta as MetaBase # type: ignore
+ from docutils.parsers.rst.directives.misc import Meta as Meta # type: ignore
except ImportError:
- # docutils-0.17 or older
+ # docutils-0.17
from docutils.parsers.rst.directives.html import Meta as MetaBase
+ class Meta(MetaBase, SphinxDirective): # type: ignore
+ def run(self) -> Sequence[Node]: # type: ignore
+ result = super().run()
+ for node in result:
+ # for docutils-0.17. Since docutils-0.18, patching is no longer needed
+ # because it uses picklable node; ``docutils.nodes.meta``.
+ if (isinstance(node, nodes.pending) and
+ isinstance(node.details['nodes'][0], addnodes.docutils_meta)):
+ meta = node.details['nodes'][0]
+ meta.source = self.env.doc2path(self.env.docname)
+ meta.line = self.lineno
+ meta.rawcontent = meta['content']
+
+ # docutils' meta nodes aren't picklable because the class is nested
+ meta.__class__ = addnodes.meta
+
+ return result
+
if TYPE_CHECKING:
from sphinx.application import Sphinx
@@ -57,25 +75,6 @@ class Figure(images.Figure):
return [figure_node]
-class Meta(MetaBase, SphinxDirective):
- def run(self) -> Sequence[Node]:
- result = super().run()
- for node in result:
- # for docutils-0.17 or older. Since docutils-0.18, patching is no longer needed
- # because it uses picklable node; ``docutils.nodes.meta``.
- if (isinstance(node, nodes.pending) and
- isinstance(node.details['nodes'][0], addnodes.docutils_meta)):
- meta = node.details['nodes'][0]
- meta.source = self.env.doc2path(self.env.docname)
- meta.line = self.lineno
- meta.rawcontent = meta['content']
-
- # docutils' meta nodes aren't picklable because the class is nested
- meta.__class__ = addnodes.meta
-
- return result
-
-
class CSVTable(tables.CSVTable):
"""The csv-table directive which searches a CSV file from Sphinx project's source
directory when an absolute path is given via :file: option.