diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-07-11 15:59:58 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-07-11 15:59:58 +0300 |
commit | 70d521ad9c1c066a081f81e9af618dd05d372486 (patch) | |
tree | e2b80a313b2df4e92dea2de6f06c275b9ad3a468 /sphinx/addnodes.py | |
parent | e39cb011b3a25f0677013a5a64d1c88f06a345e5 (diff) | |
parent | 1a31a7ca177b3700464430b93a863130241e984f (diff) |
Merge branch '3.x'
Diffstat (limited to 'sphinx/addnodes.py')
-rw-r--r-- | sphinx/addnodes.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index c98cdcbe1..763b3155a 100644 --- a/sphinx/addnodes.py +++ b/sphinx/addnodes.py @@ -14,10 +14,38 @@ from typing import TYPE_CHECKING from docutils import nodes from docutils.nodes import Element +from sphinx.util import docutils + if TYPE_CHECKING: 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: + 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. |