From 4aa222e7f9dc48dd016098f8c2bf86402faacd65 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 4 Jul 2021 01:28:35 +0900 Subject: [PATCH] Fix #9387: xml: XML Builder ignores custom visitors So far, XML builder only allows to switch its translator to custom one. But it does not support to install custom visitor methods. This allows to use them expectedly. --- CHANGES | 1 + sphinx/writers/xml.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 21ba7a067..0a0125423 100644 --- a/CHANGES +++ b/CHANGES @@ -88,6 +88,7 @@ Bugs fixed * #9306: Linkcheck reports broken link when remote server closes the connection on HEAD request * #9280: py domain: "exceptions" module is not displayed +* #9387: xml: XML Builder ignores custom visitors * #9224: ``:param:`` and ``:type:`` fields does not support a type containing whitespace (ex. ``Dict[str, str]``) * #8945: when transforming typed fields, call the specified role instead of diff --git a/sphinx/writers/xml.py b/sphinx/writers/xml.py index 19fa3c1ef..ef261fde2 100644 --- a/sphinx/writers/xml.py +++ b/sphinx/writers/xml.py @@ -19,7 +19,9 @@ class XMLWriter(BaseXMLWriter): def __init__(self, builder: Builder) -> None: super().__init__() self.builder = builder - self.translator_class = self.builder.get_translator_class() + + # A lambda function to generate translator lazily + self.translator_class = lambda document: self.builder.create_translator(document) def translate(self, *args: Any, **kwargs: Any) -> None: self.document.settings.newlines = \