Skip to content

Commit 9fb3c66

Browse files
authored
Merge pull request readthedocs#35 from readthedocs/humitos/send-docpath
Send `docpath` with the full filename path (/section/filename.html)
2 parents fc34b38 + 88b4f3b commit 9fb3c66

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
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
@@ -11,7 +11,7 @@ def _is_hoverxref_configured(self, env):
1111
version = env.config.hoverxref_version
1212
return project and version
1313

14-
def _inject_hoverxref_data(self, env, refnode, docname, labelid):
14+
def _inject_hoverxref_data(self, env, refnode, docname, docpath, labelid):
1515
refnode.replace_attr('classes', ['hoverxref'])
1616

1717
project = env.config.hoverxref_project
@@ -20,9 +20,15 @@ def _inject_hoverxref_data(self, env, refnode, docname, labelid):
2020
'data-project': project,
2121
'data-version': version,
2222
'data-doc': docname,
23+
'data-docpath': docpath,
2324
'data-section': labelid,
2425
}
2526

27+
def _get_docpath(self, builder, docname):
28+
docpath = builder.get_outfilename(docname)
29+
docpath = docpath.replace(builder.outdir, '')
30+
return docpath
31+
2632

2733
class HoverXRefPythonDomainMixin(HoverXRefBaseDomain):
2834

@@ -40,7 +46,9 @@ def resolve_xref(self, env, fromdocname, builder, type, target, node, contnode):
4046

4147
if self._is_hoverxref_configured(env):
4248
docname, labelid = obj[0], name
43-
self._inject_hoverxref_data(env, refnode, docname, labelid)
49+
docpath = self._get_docpath(builder, docname)
50+
51+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
4452
logger.info(
4553
':ref: _hoverxref injected: fromdocname=%s %s',
4654
fromdocname,
@@ -81,7 +89,9 @@ def _resolve_ref_xref(self, env, fromdocname, builder, typ, target, node, contno
8189

8290
if self._is_hoverxref_configured(env) and (env.config.hoverxref_auto_ref or typ == 'hoverxref'):
8391
docname, labelid, _ = get_ref_xref_data(self, node, target)
84-
self._inject_hoverxref_data(env, refnode, docname, labelid)
92+
docpath = self._get_docpath(builder, docname)
93+
94+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
8595
logger.info(
8696
':ref: _hoverxref injected: fromdocname=%s %s',
8797
fromdocname,
@@ -97,7 +107,9 @@ def _resolve_obj_xref(self, env, fromdocname, builder, typ, target, node, contno
97107
if typ in env.config.hoverxref_roles:
98108
docname, labelid = get_ref_obj_data(self, node, typ, target)
99109
if self._is_hoverxref_configured(env):
100-
self._inject_hoverxref_data(env, refnode, docname, labelid)
110+
docpath = self._get_docpath(builder, docname)
111+
112+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
101113
logger.info(
102114
':%s: _hoverxref injected: fromdocname=%s %s',
103115
typ,

tests/test_htmltag.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_project_version_settings(app, status, warning):
7474

7575
chunks = [
7676
'<a class="reference internal" href="chapter-i.html#chapter-i"><span class="std std-ref">This a :ref: to Chapter I</span></a>',
77-
'<a class="hoverxref reference internal" data-doc="chapter-i" data-project="myproject" data-section="section-i" data-version="myversion" href="chapter-i.html#section-i"><span class="std std-ref">This a :hoverxref: to Chapter I, Section I</span></a>',
77+
'<a class="hoverxref reference internal" data-doc="chapter-i" data-docpath="/chapter-i.html" data-project="myproject" data-section="section-i" data-version="myversion" href="chapter-i.html#section-i"><span class="std std-ref">This a :hoverxref: to Chapter I, Section I</span></a>',
7878
]
7979

8080
for chunk in chunks:
@@ -101,7 +101,7 @@ def test_js_render(app, status, warning):
101101
"animation: 'fade'",
102102
"animationDuration: 0",
103103
"content: 'Loading...'",
104-
"var url = 'https://readthedocs.org' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&section=' + section;",
104+
"var url = 'https://readthedocs.org' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&path=' + docpath + '&section=' + section;",
105105
]
106106

107107
for chunk in chunks:
@@ -123,7 +123,7 @@ def test_autosectionlabel_project_version_settings(app, status, warning):
123123

124124
chunks = [
125125
'<a class="reference internal" href="chapter-i.html#chapter-i"><span class="std std-ref">This a :ref: to Chapter I</span></a>.',
126-
'<a class="hoverxref reference internal" data-doc="chapter-i" data-project="myproject" data-section="chapter-i" data-version="myversion" href="chapter-i.html#chapter-i"><span class="std std-ref">This a :hoverxref: to Chapter I</span></a>',
126+
'<a class="hoverxref reference internal" data-doc="chapter-i" data-docpath="/chapter-i.html" data-project="myproject" data-section="chapter-i" data-version="myversion" href="chapter-i.html#chapter-i"><span class="std std-ref">This a :hoverxref: to Chapter I</span></a>',
127127
]
128128

129129
for chunk in chunks:
@@ -141,8 +141,8 @@ def test_custom_object(app, status, warning):
141141
content = open(path).read()
142142

143143
chunks = [
144-
'<a class="hoverxref reference internal" data-doc="configuration" data-project="myproject" data-section="confval-conf-title" data-version="myversion" href="configuration.html#confval-conf-title"><code class="xref std std-confval docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:confval:</span> <span class="pre">to</span> <span class="pre">conf-title</span></code></a>',
145-
'<a class="hoverxref reference internal" data-doc="configuration" data-project="myproject" data-section="configuration" data-version="myversion" href="configuration.html#configuration"><span class="std std-ref">This is a :hoverxref: to Configuration document</span></a>',
144+
'<a class="hoverxref reference internal" data-doc="configuration" data-docpath="/configuration.html" data-project="myproject" data-section="confval-conf-title" data-version="myversion" href="configuration.html#confval-conf-title"><code class="xref std std-confval docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:confval:</span> <span class="pre">to</span> <span class="pre">conf-title</span></code></a>',
145+
'<a class="hoverxref reference internal" data-doc="configuration" data-docpath="/configuration.html" data-project="myproject" data-section="configuration" data-version="myversion" href="configuration.html#configuration"><span class="std std-ref">This is a :hoverxref: to Configuration document</span></a>',
146146
]
147147

148148
for chunk in chunks:
@@ -162,9 +162,9 @@ def test_python_domain(app, status, warning):
162162
content = open(path).read()
163163

164164
chunks = [
165-
'<a class="hoverxref reference internal" data-doc="api" data-project="myproject" data-section="hoverxref.extension.HoverXRefStandardDomainMixin" data-version="myversion" href="api.html#hoverxref.extension.HoverXRefStandardDomainMixin" title="hoverxref.extension.HoverXRefStandardDomainMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:py:class:</span> <span class="pre">role</span> <span class="pre">to</span> <span class="pre">a</span> <span class="pre">Python</span> <span class="pre">object</span></code></a>',
166-
'<a class="hoverxref reference internal" data-doc="api" data-project="myproject" data-section="hoverxref.extension" data-version="myversion" href="api.html#module-hoverxref.extension" title="hoverxref.extension"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hoverxref.extension</span></code></a>',
167-
'<a class="hoverxref reference internal" data-doc="api" data-project="myproject" data-section="hoverxref.utils.get_ref_xref_data" data-version="myversion" href="api.html#hoverxref.utils.get_ref_xref_data" title="hoverxref.utils.get_ref_xref_data"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.utils.get_ref_xref_data()</span></code></a>',
165+
'<a class="hoverxref reference internal" data-doc="api" data-docpath="/api.html" data-project="myproject" data-section="hoverxref.extension.HoverXRefStandardDomainMixin" data-version="myversion" href="api.html#hoverxref.extension.HoverXRefStandardDomainMixin" title="hoverxref.extension.HoverXRefStandardDomainMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:py:class:</span> <span class="pre">role</span> <span class="pre">to</span> <span class="pre">a</span> <span class="pre">Python</span> <span class="pre">object</span></code></a>',
166+
'<a class="hoverxref reference internal" data-doc="api" data-docpath="/api.html" data-project="myproject" data-section="hoverxref.extension" data-version="myversion" href="api.html#module-hoverxref.extension" title="hoverxref.extension"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hoverxref.extension</span></code></a>',
167+
'<a class="hoverxref reference internal" data-doc="api" data-docpath="/api.html" data-project="myproject" data-section="hoverxref.utils.get_ref_xref_data" data-version="myversion" href="api.html#hoverxref.utils.get_ref_xref_data" title="hoverxref.utils.get_ref_xref_data"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.utils.get_ref_xref_data()</span></code></a>',
168168
]
169169

170170
for chunk in chunks:

0 commit comments

Comments
 (0)