Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-05-05 16:12:52 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-07-09 17:15:56 +0300
commitfb7b0ee5718af07c8eddf49f71742f6b97f7fd65 (patch)
tree8d19c75f49410eaa096fe004b9511832f73daa94 /sphinx/addnodes.py
parent2feb0b43b64012ac982a9d07af85002b43b59226 (diff)
Fix #7619: Duplicated node IDs are generated if node has multiple IDs
Diffstat (limited to 'sphinx/addnodes.py')
-rw-r--r--sphinx/addnodes.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py
index 5e191e989..84b0c1427 100644
--- a/sphinx/addnodes.py
+++ b/sphinx/addnodes.py
@@ -15,12 +15,39 @@ from docutils import nodes
from docutils.nodes import Element, Node
from sphinx.deprecation import RemovedInSphinx40Warning
+from sphinx.util import docutils
if False:
# For type annotation
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.