Skip to content

Commit dcb4429

Browse files
committed
Restore Sphinx 5 nodes.Element copying behaviour
1 parent 2a7c40d commit dcb4429

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sphinx/util/nodes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,18 @@ def process_only_nodes(document: Node, tags: Tags) -> None:
608608
# the only node, so we make sure docutils can transfer the id to
609609
# something, even if it's just a comment and will lose the id anyway...
610610
node.replace_self(nodes.comment())
611+
612+
613+
def _copy_except__document(self: Element) -> Element:
614+
"""Monkey-patch ```nodes.Element.copy``` to not copy the ``_document``
615+
attribute.
616+
617+
xref: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086
618+
"""
619+
newnode = self.__class__(rawsource=self.rawsource, **self.attributes)
620+
newnode.source = self.source
621+
newnode.line = self.line
622+
return newnode
623+
624+
625+
nodes.Element.copy = _copy_except__document # type: ignore

0 commit comments

Comments
 (0)