File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments