diff options
author | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-01-10 14:48:03 +0000 |
---|---|---|
committer | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-01-10 14:53:17 +0000 |
commit | dcb4429abacda015f98875fe9489ced696155bd7 (patch) | |
tree | dcfad393b292e36e217e3cfe06eaf0e2cf8f1e18 /sphinx/util/nodes.py | |
parent | 2a7c40d07f4b0e0fd2a4bc942e74634c2df24dee (diff) | |
download | sphinx-git-dcb4429abacda015f98875fe9489ced696155bd7.tar.gz |
Restore Sphinx 5 ``nodes.Element`` copying behaviour
Diffstat (limited to 'sphinx/util/nodes.py')
-rw-r--r-- | sphinx/util/nodes.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 18dd94f46..794eea255 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -608,3 +608,18 @@ def process_only_nodes(document: Node, tags: Tags) -> None: # the only node, so we make sure docutils can transfer the id to # something, even if it's just a comment and will lose the id anyway... node.replace_self(nodes.comment()) + + +def _copy_except__document(self: Element) -> Element: + """Monkey-patch ```nodes.Element.copy``` to not copy the ``_document`` + attribute. + + xref: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086 + """ + newnode = self.__class__(rawsource=self.rawsource, **self.attributes) + newnode.source = self.source + newnode.line = self.line + return newnode + + +nodes.Element.copy = _copy_except__document # type: ignore |