Georg Brandl avatar Georg Brandl committed 3dd6812

#302: Fix links generated by the ``:doc:`` role for LaTeX output.

For that, record the source docname in an xfileref node in node['refdoc'].
The LaTeX builder creates one big toctree out of all documents, therefore
"fromdocname" in resolve_references refers to the wrong file.

Comments (0)

Files changed (3)

 Release 0.6.4 (in development)
 ==============================
 
+* #302: Fix links generated by the ``:doc:`` role for LaTeX output.
+
 * #286: collect todo nodes after the whole document has been read;
   this allows placing substitution references in todo items.
 

sphinx/environment.py

 
 # This is increased every time an environment attribute is added
 # or changed to properly invalidate pickle files.
-ENV_VERSION = 30
+ENV_VERSION = 31
 
 
 default_substitutions = set([
                         docname, labelid = self.anonlabels.get(target, ('',''))
                         sectname = node.astext()
                         if not docname:
-                            self.warn(fromdocname, 'undefined label: %s' %
+                            self.warn(node['refdoc'], 'undefined label: %s' %
                                       target, node.line)
                     else:
                         # reference to the named label; the final node will
                                                                      ('','',''))
                         if not docname:
                             self.warn(
-                                fromdocname,
+                                node['refdoc'],
                                 'undefined label: %s' % target + ' -- if you '
                                 'don\'t give a link caption the label must '
                                 'precede a section header.', node.line)
                 elif typ == 'doc':
                     # directly reference to document by source name;
                     # can be absolute or relative
-                    docname = docname_join(fromdocname, target)
+                    docname = docname_join(node['refdoc'], target)
                     if docname not in self.all_docs:
-                        self.warn(fromdocname, 'unknown document: %s' % docname,
-                                  node.line)
+                        self.warn(node['refdoc'],
+                                  'unknown document: %s' % docname, node.line)
                         newnode = contnode
                     else:
                         if node['refcaption']:
                     # keywords are referenced by named labels
                     docname, labelid, _ = self.labels.get(target, ('','',''))
                     if not docname:
-                        #self.warn(fromdocname, 'unknown keyword: %s' % target)
+                        #self.warn(node['refdoc'], 'unknown keyword: %s' % target)
                         newnode = contnode
                     else:
                         newnode = nodes.reference('', '')
                                                            ('', ''))
                     if not docname:
                         if typ == 'term':
-                            self.warn(fromdocname,
+                            self.warn(node['refdoc'],
                                       'term not in glossary: %s' % target,
                                       node.line)
                         elif typ == 'citation':
-                            self.warn(fromdocname,
+                            self.warn(node['refdoc'],
                                       'citation not found: %s' % target,
                                       node.line)
                         newnode = contnode
     else:
         # remove all whitespace to avoid referencing problems
         target = ws_re.sub('', target)
+    pnode['refdoc'] = env.docname
     pnode['reftarget'] = target
     pnode += innernodetypes.get(typ, nodes.literal)(rawtext, title,
                                                     classes=['xref'])
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.