>, <#text: ']'>]
+ refnode_index = textnode.first_child_matching_class(docutils.nodes.reference)
+ if refnode_index:
+ refnode = textnode.children[refnode_index]
+ self._inject_hoverxref_data(env, refnode, typ)
+
+ return textnode
diff --git a/hoverxref/extension.py b/hoverxref/extension.py
index 20a09bdd..dcca54f3 100644
--- a/hoverxref/extension.py
+++ b/hoverxref/extension.py
@@ -12,6 +12,7 @@
from . import version
from .domains import (
HoverXRefBaseDomain,
+ HoverXRefBibtexDomainMixin,
HoverXRefPythonDomainMixin,
HoverXRefStandardDomainMixin,
)
@@ -119,6 +120,17 @@ def setup_domains(app, config):
)
app.add_domain(domain, override=True)
+ if 'cite' in app.config.hoverxref_domains:
+ domain = types.new_class(
+ 'HoverXRefBibtexDomain',
+ (
+ HoverXRefBibtexDomainMixin,
+ app.registry.domains.get('cite'),
+ ),
+ {}
+ )
+ app.add_domain(domain, override=True)
+
def setup_sphinx_tabs(app, config):
"""
diff --git a/tests/examples/bibtex-domain/conf.py b/tests/examples/bibtex-domain/conf.py
new file mode 100644
index 00000000..04bf3162
--- /dev/null
+++ b/tests/examples/bibtex-domain/conf.py
@@ -0,0 +1,11 @@
+# conf.py to run tests
+
+master_doc = 'index'
+extensions = [
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.autosectionlabel',
+ 'hoverxref.extension',
+ 'sphinxcontrib.bibtex',
+]
+
+bibtex_bibfiles = ['refs.bib']
diff --git a/tests/examples/bibtex-domain/index.rst b/tests/examples/bibtex-domain/index.rst
new file mode 100644
index 00000000..f70372a7
--- /dev/null
+++ b/tests/examples/bibtex-domain/index.rst
@@ -0,0 +1,10 @@
+sphinxcontrib-bibtex Domain
+===========================
+
+This is an example page with a sphinxcontrib-bibtex Domain role usage.
+
+See :cite:t:`1987:nelson` for an introduction to non-standard analysis.
+Non-standard analysis is fun :cite:p:`1987:nelson`.
+
+
+.. bibliography::
diff --git a/tests/examples/bibtex-domain/refs.bib b/tests/examples/bibtex-domain/refs.bib
new file mode 100644
index 00000000..8be9d662
--- /dev/null
+++ b/tests/examples/bibtex-domain/refs.bib
@@ -0,0 +1,6 @@
+@Book{1987:nelson,
+ author = {Edward Nelson},
+ title = {Radically Elementary Probability Theory},
+ publisher = {Princeton University Press},
+ year = {1987}
+}
diff --git a/tests/examples/default/glossary.rst b/tests/examples/default/glossary.rst
new file mode 100644
index 00000000..4ea70a16
--- /dev/null
+++ b/tests/examples/default/glossary.rst
@@ -0,0 +1,25 @@
+Glossary
+========
+
+Example page showing the usage of ``.. glossary`` and ``term``.
+
+See definition :term:`builder` for more information.
+
+.. copied from https://www.sphinx-doc.org/en/master/glossary.html
+
+.. glossary::
+
+ builder
+ A class (inheriting from :class:`~sphinx.builders.Builder`) that takes
+ parsed documents and performs an action on them. Normally, builders
+ translate the documents to an output format, but it is also possible to
+ use builders that e.g. check for broken links in the documentation, or
+ build coverage information.
+
+ See :doc:`/usage/builders/index` for an overview over Sphinx's built-in
+ builders.
+
+ configuration directory
+ The directory containing :file:`conf.py`. By default, this is the same as
+ the :term:`source directory`, but can be set differently with the **-c**
+ command-line option.
diff --git a/tests/test_htmltag.py b/tests/test_htmltag.py
index b127b557..64a580c2 100644
--- a/tests/test_htmltag.py
+++ b/tests/test_htmltag.py
@@ -3,7 +3,7 @@
import sphinx
import textwrap
-from .utils import srcdir, prefixdocumentsrcdir, customobjectsrcdir, pythondomainsrcdir, intersphinxsrc
+from .utils import srcdir, prefixdocumentsrcdir, customobjectsrcdir, pythondomainsrcdir, intersphinxsrc, bibtexdomainsrcdir
@pytest.mark.sphinx(
@@ -121,6 +121,50 @@ def test_python_domain(app, status, warning):
assert chunk in content
+@pytest.mark.skipif(
+ sphinx.version_info < (2, 1, 0),
+ reason='sphinxcontrib-bibtex requires Sphinx>=2.1 to work',
+)
+@pytest.mark.sphinx(
+ srcdir=bibtexdomainsrcdir,
+ confoverrides={
+ 'hoverxref_domains': ['cite'],
+ },
+)
+def test_bibtex_domain(app, status, warning):
+ app.build()
+ path = app.outdir / 'index.html'
+ assert path.exists() is True
+ content = open(path).read()
+
+ chunks = [
+ 'See Nelson [Nel87] for an introduction to non-standard analysis.\nNon-standard analysis is fun [Nel87].
',
+ ]
+
+ for chunk in chunks:
+ assert chunk in content
+
+
+@pytest.mark.sphinx(
+ srcdir=srcdir,
+ confoverrides={
+ 'hoverxref_roles': ['term'],
+ },
+)
+def test_glossary_term_domain(app, status, warning):
+ app.build()
+ path = app.outdir / 'glossary.html'
+ assert path.exists() is True
+ content = open(path).read()
+
+ chunks = [
+ 'See definition builder for more information.
',
+ ]
+
+ for chunk in chunks:
+ assert chunk in content
+
+
@pytest.mark.sphinx(
srcdir=srcdir,
confoverrides={
diff --git a/tests/utils.py b/tests/utils.py
index 5f62b2ec..8072c7da 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -28,6 +28,13 @@
'python-domain',
)
+# srcdir with ``:cite:`` call
+bibtexdomainsrcdir = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ 'examples',
+ 'bibtex-domain',
+)
+
# srcdir with intersphinx configured
intersphinxsrc = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
diff --git a/tox.ini b/tox.ini
index c31030dc..998c31d3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -7,6 +7,7 @@ envlist =
deps =
pytest
pdbpp
+ sphinxcontrib-bibtex
.
sphinx18: sphinx~=1.8.0
sphinx20: sphinx~=2.0.0