Jon Waltman avatar Jon Waltman committed 51850bb

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

Comments (0)

Files changed (1)

sphinx/writers/texinfo.py

         """Generates a unique id for 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
         self.document['node_name'] = 'Top'
-        self.node_names['Top'] = 'Top'
-        self.written_ids.update(('Top', 'top'))
+        add_node_name('Top')
+        add_node_name('top')
         # each index is a node
-        for name, content in self.indices:
-            self.node_names[name] = name
-            self.written_ids.add(name)
+        self.indices = [(add_node_name(name), content)
+                        for name, content in self.indices]
         # each section is also a node
         for section in self.document.traverse(nodes.section):
             title = section.next_node(nodes.Titular)
             name = (title and title.astext()) or '<untitled>'
-            node_id = self.escape_id(name) or '<untitled>'
-            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)
+            section['node_name'] = add_node_name(name)
 
     def collect_node_menus(self):
         """Collect the menu entries for each "node" section."""
         for entry in entries:
             name = self.node_names[entry]
             # special formatting for entries that are divided by an em-dash
-            parts = reg.split(name, 1)
+            try:
+                parts = reg.split(name, 1)
+            except TypeError:
+                # could be a gettext proxy
+                parts = [name]
             if len(parts) == 2:
                 name, desc = parts
             else:
                         self.builder.docnames)
                     if not content:
                         continue
-                    node_name = self.escape_id(indexcls.localname)
-                    self.indices.append((node_name,
+                    self.indices.append((indexcls.localname,
                                          generate(content, collapsed)))
         self.indices.append((_('Index'), '\n@printindex ge\n'))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.