11import os
22import inspect
3+ import types
34from docutils import nodes
45from sphinx .roles import XRefRole
56from sphinx .util .fileutil import copy_asset
67
78from . import version
8- from .domains import HoverXRefPythonDomain , HoverXRefStandardDomain
9+ from .domains import HoverXRefPythonDomainMixin , HoverXRefStandardDomainMixin
910from .translators import HoverXRefHTMLTranslator
1011
1112ASSETS_FILES = [
@@ -53,6 +54,13 @@ def copy_asset_files(app, exception):
5354
5455
5556def setup_domains (app , config ):
57+ """
58+ Override domains respecting the one defined (if any).
59+
60+ We create a new class by inheriting the Sphinx Domain already defined
61+ and our own ``HoverXRef...DomainMixin`` that includes the logic for
62+ ``_hoverxref`` attributes.
63+ """
5664 # Add ``hoverxref`` role replicating the behavior of ``ref``
5765 app .add_role_to_domain (
5866 'std' ,
@@ -63,10 +71,27 @@ def setup_domains(app, config):
6371 warn_dangling = True ,
6472 ),
6573 )
66- app .add_domain (HoverXRefStandardDomain , override = True )
6774
68- if 'py' in config .hoverxref_domains :
69- app .add_domain (HoverXRefPythonDomain , override = True )
75+ domain = types .new_class (
76+ 'HoverXRefStandardDomain' ,
77+ (
78+ HoverXRefStandardDomainMixin ,
79+ app .registry .domains .get ('std' ),
80+ ),
81+ {}
82+ )
83+ app .add_domain (domain , override = True )
84+
85+ if 'py' in app .config .hoverxref_domains :
86+ domain = types .new_class (
87+ 'HoverXRefPythonDomain' ,
88+ (
89+ HoverXRefPythonDomainMixin ,
90+ app .registry .domains .get ('py' ),
91+ ),
92+ {}
93+ )
94+ app .add_domain (domain , override = True )
7095
7196
7297def setup_sphinx_tabs (app , config ):
0 commit comments