Skip to content

Commit ae974c2

Browse files
committed
Merge branch 'master' of github.com:humitos/sphinx-hoverxref into humitos/ignore-refs
2 parents bc6c720 + 9fb3c66 commit ae974c2

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class HoverXRefBaseDomain:
88

9-
def _inject_hoverxref_data(self, env, refnode, docname, labelid):
9+
def _inject_hoverxref_data(self, env, refnode, docname, docpath, labelid):
1010
refnode.replace_attr('classes', ['hoverxref'])
1111

1212
project = env.config.hoverxref_project
@@ -15,9 +15,15 @@ def _inject_hoverxref_data(self, env, refnode, docname, labelid):
1515
'data-project': project,
1616
'data-version': version,
1717
'data-doc': docname,
18+
'data-docpath': docpath,
1819
'data-section': labelid,
1920
}
2021

22+
def _get_docpath(self, builder, docname):
23+
docpath = builder.get_outfilename(docname)
24+
docpath = docpath.replace(builder.outdir, '')
25+
return docpath
26+
2127
def _is_ignored_ref(self, env, target):
2228
if target in env.config.hoverxref_ignore_refs:
2329
logger.info(
@@ -49,7 +55,8 @@ def resolve_xref(self, env, fromdocname, builder, type, target, node, contnode):
4955
name, obj = matches[0]
5056

5157
docname, labelid = obj[0], name
52-
self._inject_hoverxref_data(env, refnode, docname, labelid)
58+
docpath = self._get_docpath(builder, docname)
59+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
5360
logger.info(
5461
':ref: _hoverxref injected: fromdocname=%s %s',
5562
fromdocname,
@@ -90,8 +97,10 @@ def _resolve_ref_xref(self, env, fromdocname, builder, typ, target, node, contno
9097
]):
9198
return refnode
9299

100+
93101
docname, labelid, _ = get_ref_xref_data(self, node, target)
94-
self._inject_hoverxref_data(env, refnode, docname, labelid)
102+
docpath = self._get_docpath(builder, docname)
103+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
95104
logger.info(
96105
':ref: _hoverxref injected: fromdocname=%s %s',
97106
fromdocname,
@@ -112,7 +121,8 @@ def _resolve_obj_xref(self, env, fromdocname, builder, typ, target, node, contno
112121
return refnode
113122

114123
docname, labelid = get_ref_obj_data(self, node, typ, target)
115-
self._inject_hoverxref_data(env, refnode, docname, labelid)
124+
docpath = self._get_docpath(builder, docname)
125+
self._inject_hoverxref_data(env, refnode, docname, docpath, labelid)
116126
logger.info(
117127
':%s: _hoverxref injected: fromdocname=%s %s',
118128
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)