diff options
Diffstat (limited to 'sphinx/addnodes.py')
-rw-r--r-- | sphinx/addnodes.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index 5e191e989..5f371e46b 100644 --- a/sphinx/addnodes.py +++ b/sphinx/addnodes.py @@ -4,7 +4,7 @@ Additional docutils nodes. - :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. + :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -21,6 +21,33 @@ if False: from sphinx.application import Sphinx +class document(nodes.document): + """The document root element patched by Sphinx. + + This fixes that document.set_id() does not support a node having multiple node Ids. + see https://sourceforge.net/p/docutils/patches/167/ + + .. important:: This is only for Sphinx internal use. Please don't use this + in your extensions. It will be removed without deprecation period. + """ + + def set_id(self, node: Element, msgnode: Element = None, + suggested_prefix: str = '') -> str: + from sphinx.util import docutils + if docutils.__version_info__ >= (0, 16): + ret = super().set_id(node, msgnode, suggested_prefix) # type: ignore + else: + ret = super().set_id(node, msgnode) + + if docutils.__version_info__ < (0, 17): + # register other node IDs forcedly + for node_id in node['ids']: + if node_id not in self.ids: + self.ids[node_id] = node + + return ret + + class translatable(nodes.Node): """Node which supports translation. |