1. Georg Brandl
  2. sphinx

Commits

Georg Brandl  committed b2a0904

Closes #1285: Avoid name clashes between C domain objects and section titles.

  • Participants
  • Parent commits 53b8338
  • Branches stable

Comments (0)

Files changed (3)

File CHANGES

View file
  • Ignore whitespace
   Also make the redirect code apparent and tweak the output a bit to be
   more obvious.
 
+* #1285: Avoid name clashes between C domain objects and section titles.
+
 Documentation
 -------------
 

File sphinx/domains/c.py

View file
  • Ignore whitespace
             return ''
 
     def add_target_and_index(self, name, sig, signode):
-        # note target
-        if name not in self.state.document.ids:
-            signode['names'].append(name)
-            signode['ids'].append(name)
+        # for C API items we add a prefix since names are usually not qualified
+        # by a module name and so easily clash with e.g. section titles
+        targetname = 'c.' + name
+        if targetname not in self.state.document.ids:
+            signode['names'].append(targetname)
+            signode['ids'].append(targetname)
             signode['first'] = (not self.names)
             self.state.document.note_explicit_target(signode)
             inv = self.env.domaindata['c']['objects']
 
         indextext = self.get_index_text(name)
         if indextext:
-            self.indexnode['entries'].append(('single', indextext, name, ''))
+            self.indexnode['entries'].append(('single', indextext,
+                                              targetname, ''))
 
     def before_content(self):
         self.typename_set = False
         if target not in self.data['objects']:
             return None
         obj = self.data['objects'][target]
-        return make_refnode(builder, fromdocname, obj[0], target,
+        return make_refnode(builder, fromdocname, obj[0], 'c.' + target,
                             contnode, target)
 
     def get_objects(self):
         for refname, (docname, type) in self.data['objects'].iteritems():
-            yield (refname, refname, type, docname, refname, 1)
+            yield (refname, refname, type, docname, 'c.' + refname, 1)

File tests/test_build_html.py

View file
  • Ignore whitespace
         (".//a[@href='#userdesc-myobj'][@class='reference internal']", ''),
         # C references
         (".//span[@class='pre']", 'CFunction()'),
-        (".//a[@href='#Sphinx_DoSomething']", ''),
-        (".//a[@href='#SphinxStruct.member']", ''),
-        (".//a[@href='#SPHINX_USE_PYTHON']", ''),
-        (".//a[@href='#SphinxType']", ''),
-        (".//a[@href='#sphinx_global']", ''),
+        (".//a[@href='#c.Sphinx_DoSomething']", ''),
+        (".//a[@href='#c.SphinxStruct.member']", ''),
+        (".//a[@href='#c.SPHINX_USE_PYTHON']", ''),
+        (".//a[@href='#c.SphinxType']", ''),
+        (".//a[@href='#c.sphinx_global']", ''),
         # reference from old C markup extension
-        (".//a[@href='#Sphinx_Func']", ''),
+        (".//a[@href='#c.Sphinx_Func']", ''),
         # test global TOC created by toctree()
         (".//ul[@class='current']/li[@class='toctree-l1 current']/a[@href='']",
             'Testing object descriptions'),