mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
texinfo: Handle duplicate domain indices.
Reported by Takafumi Arakaki at https://bitbucket.org/jonwaltman/sphinx-info/issue/1/error-this-node-python-module-index-has
This commit is contained in:
parent
e091ae2bf7
commit
8e96fc71d4
@ -233,30 +233,31 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
"""Generates a unique id for each section.
|
"""Generates a unique id for each section.
|
||||||
|
|
||||||
Assigns the attribute ``node_name`` to each section."""
|
Assigns the attribute ``node_name`` to each section."""
|
||||||
|
|
||||||
|
def add_node_name(name):
|
||||||
|
node_id = self.escape_id(name)
|
||||||
|
nth, suffix = 1, ''
|
||||||
|
while node_id + suffix in self.written_ids or \
|
||||||
|
node_id + suffix in self.node_names:
|
||||||
|
nth += 1
|
||||||
|
suffix = '<%s>' % nth
|
||||||
|
node_id += suffix
|
||||||
|
self.written_ids.add(node_id)
|
||||||
|
self.node_names[node_id] = name
|
||||||
|
return node_id
|
||||||
|
|
||||||
# must have a "Top" node
|
# must have a "Top" node
|
||||||
self.document['node_name'] = 'Top'
|
self.document['node_name'] = 'Top'
|
||||||
self.node_names['Top'] = 'Top'
|
add_node_name('Top')
|
||||||
self.written_ids.update(('Top', 'top'))
|
add_node_name('top')
|
||||||
# each index is a node
|
# each index is a node
|
||||||
for name, content in self.indices:
|
self.indices = [(add_node_name(name), content)
|
||||||
self.node_names[name] = name
|
for name, content in self.indices]
|
||||||
self.written_ids.add(name)
|
|
||||||
# each section is also a node
|
# each section is also a node
|
||||||
for section in self.document.traverse(nodes.section):
|
for section in self.document.traverse(nodes.section):
|
||||||
title = section.next_node(nodes.Titular)
|
title = section.next_node(nodes.Titular)
|
||||||
name = (title and title.astext()) or '<untitled>'
|
name = (title and title.astext()) or '<untitled>'
|
||||||
node_id = self.escape_id(name) or '<untitled>'
|
section['node_name'] = add_node_name(name)
|
||||||
assert node_id and name
|
|
||||||
nth, suffix = 1, ''
|
|
||||||
while node_id + suffix in self.written_ids:
|
|
||||||
nth += 1
|
|
||||||
suffix = '<%s>' % nth
|
|
||||||
node_id += suffix
|
|
||||||
assert node_id not in self.node_names
|
|
||||||
assert node_id not in self.written_ids
|
|
||||||
section['node_name'] = node_id
|
|
||||||
self.node_names[node_id] = name
|
|
||||||
self.written_ids.add(node_id)
|
|
||||||
|
|
||||||
def collect_node_menus(self):
|
def collect_node_menus(self):
|
||||||
"""Collect the menu entries for each "node" section."""
|
"""Collect the menu entries for each "node" section."""
|
||||||
@ -371,7 +372,11 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
for entry in entries:
|
for entry in entries:
|
||||||
name = self.node_names[entry]
|
name = self.node_names[entry]
|
||||||
# special formatting for entries that are divided by an em-dash
|
# special formatting for entries that are divided by an em-dash
|
||||||
|
try:
|
||||||
parts = reg.split(name, 1)
|
parts = reg.split(name, 1)
|
||||||
|
except TypeError:
|
||||||
|
# could be a gettext proxy
|
||||||
|
parts = [name]
|
||||||
if len(parts) == 2:
|
if len(parts) == 2:
|
||||||
name, desc = parts
|
name, desc = parts
|
||||||
else:
|
else:
|
||||||
@ -450,8 +455,7 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
|||||||
self.builder.docnames)
|
self.builder.docnames)
|
||||||
if not content:
|
if not content:
|
||||||
continue
|
continue
|
||||||
node_name = self.escape_id(indexcls.localname)
|
self.indices.append((indexcls.localname,
|
||||||
self.indices.append((node_name,
|
|
||||||
generate(content, collapsed)))
|
generate(content, collapsed)))
|
||||||
self.indices.append((_('Index'), '\n@printindex ge\n'))
|
self.indices.append((_('Index'), '\n@printindex ge\n'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user