Skip to content

Commit 62ac83a

Browse files
committed
Send docpath with the full filename path (/section/filename.html)
1 parent 425ef4f commit 62ac83a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

hoverxref/_static/js/hoverxref.js_t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ $(document).ready(function() {
3939
var project = $origin.data('project');
4040
var version = $origin.data('version');
4141
var doc = $origin.data('doc');
42+
var docpath = $origin.data('docpath');
4243
var section = $origin.data('section');
4344

44-
console.debug('Data: project=' + project + ' version=' + version + ' doc=' + doc + ' section=' + section);
45+
console.debug('Data: project=' + project + ' version=' + version + ' doc=' + doc + 'path=' + docpath + ' section=' + section);
4546

4647
// we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens
4748
if ($origin.data('loaded') !== true) {
4849
// TODO: improve URL handling here
49-
var url = '{{ hoverxref_tooltip_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&section=' + section;
50+
var url = '{{ hoverxref_tooltip_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&path=' + docpath + '&section=' + section;
5051
$.get(url, function(data) {
5152

5253
// call the 'content' method to update the content of our tooltip with the returned data.

hoverxref/domains.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def _is_hoverxref_configured(self, env):
1313
version = env.config.hoverxref_version
1414
return project and version
1515

16-
def _inject_hoverxref_data(self, env, refnode, docname, labelid):
16+
def _inject_hoverxref_data(self, env, refnode, docname, docpath, labelid):
1717
refnode.replace_attr('classes', ['hoverxref'])
1818

1919
project = env.config.hoverxref_project
@@ -22,9 +22,15 @@ def _inject_hoverxref_data(self, env, refnode, docname, labelid):
2222
'data-project': project,
2323
'data-version': version,
2424
'data-doc': docname,
25+
'data-docpath': docpath,
2526
'data-section': labelid,
2627
}
2728

29+
def _get_docpath(self, builder, docname):
30+
docpath = builder.get_outfilename(docname)
31+
docpath = docpath.replace(builder.outdir, '')
32+
return docpath
33+
2834

2935
class HoverXRefPythonDomain(HoverXRefBaseDomain, PythonDomain):
3036

@@ -42,7 +48,9 @@ def resolve_xref(self, env, fromdocname, builder, type, target, node, contnode):
4248

4349
if self._is_hoverxref_configured(env):
4450
docname, labelid = obj[0], name
45-
self._inject_hoverxref_data(env, refnode, docname, labelid)
51+
docpath = self._get_docpath(builder, docname)
52+
53+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
4654
logger.info(
4755
':ref: _hoverxref injected: fromdocname=%s %s',
4856
fromdocname,
@@ -83,7 +91,9 @@ def _resolve_ref_xref(self, env, fromdocname, builder, typ, target, node, contno
8391

8492
if self._is_hoverxref_configured(env) and (env.config.hoverxref_auto_ref or typ == 'hoverxref'):
8593
docname, labelid, _ = get_ref_xref_data(self, node, target)
86-
self._inject_hoverxref_data(env, refnode, docname, labelid)
94+
docpath = self._get_docpath(builder, docname)
95+
96+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
8797
logger.info(
8898
':ref: _hoverxref injected: fromdocname=%s %s',
8999
fromdocname,
@@ -99,7 +109,9 @@ def _resolve_obj_xref(self, env, fromdocname, builder, typ, target, node, contno
99109
if typ in env.config.hoverxref_roles:
100110
docname, labelid = get_ref_obj_data(self, node, typ, target)
101111
if self._is_hoverxref_configured(env):
102-
self._inject_hoverxref_data(env, refnode, docname, labelid)
112+
docpath = self._get_docpath(builder, docname)
113+
114+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
103115
logger.info(
104116
':%s: _hoverxref injected: fromdocname=%s %s',
105117
typ,

0 commit comments

Comments
 (0)