Skip to content

Commit

Permalink
Restore Sphinx 5 nodes.Element copying behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 10, 2023
1 parent 2a7c40d commit dcb4429
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sphinx/util/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dcb4429

Please sign in to comment.