19
19
20
20
logger = logging .getLogger (__name__ )
21
21
22
+ CSS_CLASS_PREFIX = 'hxr-'
23
+ CSS_DEFAULT_CLASS = f'{ CSS_CLASS_PREFIX } hoverxref'
24
+ CSS_CLASSES = {
25
+ 'tooltip' : f'{ CSS_CLASS_PREFIX } tooltip' ,
26
+ 'modal' : f'{ CSS_CLASS_PREFIX } modal' ,
27
+ }
22
28
23
29
HOVERXREF_ASSETS_FILES = [
24
30
'js/hoverxref.js_t' , # ``_t`` tells Sphinx this is a template
27
33
TOOLTIP_ASSETS_FILES = [
28
34
# Tooltipster's Styles
29
35
'js/tooltipster.bundle.min.js' ,
30
- 'css/tooltipster.custom.css ' ,
36
+ 'css/tooltipster.custom.css_t ' ,
31
37
'css/tooltipster.bundle.min.css' ,
32
38
33
39
# Tooltipster's Themes
@@ -65,6 +71,7 @@ def copy_asset_files(app, exception):
65
71
# Then, add the values that the user overrides
66
72
context [attr ] = getattr (app .config , attr )
67
73
74
+ context ['hoverxref_css_class_prefix' ] = CSS_CLASS_PREFIX
68
75
context ['http_hoverxref_version' ] = __version__
69
76
70
77
# Finally, add some non-hoverxref extra configs
@@ -73,10 +80,13 @@ def copy_asset_files(app, exception):
73
80
context [attr ] = getattr (app .config , attr )
74
81
75
82
for f in ASSETS_FILES :
83
+ # Example: "./_static/js/hoverxref.js_t"
76
84
path = os .path .join (os .path .dirname (__file__ ), '_static' , f )
85
+ # Example: "<app.outdir>/_static/css" or "<app.outdir>/_static/js"
86
+ output = os .path .join (app .outdir , '_static' , f .split ('/' )[0 ])
77
87
copy_asset (
78
88
path ,
79
- os . path . join ( app . outdir , '_static' , f . split ( '.' )[ - 1 ]. replace ( 'js_t' , 'js' )) ,
89
+ output ,
80
90
context = context ,
81
91
)
82
92
@@ -264,7 +274,7 @@ def missing_reference(app, env, node, contnode):
264
274
hoverxref_type = hoverxref_type or app .config .hoverxref_default_type
265
275
266
276
classes = newnode .get ('classes' )
267
- classes .extend (['hoverxref' , hoverxref_type ])
277
+ classes .extend ([CSS_DEFAULT_CLASS , CSS_CLASSES [ hoverxref_type ] ])
268
278
newnode .replace_attr ('classes' , classes )
269
279
270
280
return newnode
@@ -374,11 +384,13 @@ def setup(app):
374
384
375
385
app .connect ('missing-reference' , missing_reference )
376
386
387
+ # Include all assets previously copied/rendered by ``copy_asset_files`` as
388
+ # Javascript and CSS files into the Sphinx application
377
389
for f in ASSETS_FILES :
378
390
if f .endswith ('.js' ) or f .endswith ('.js_t' ):
379
391
app .add_js_file (f .replace ('.js_t' , '.js' ))
380
- if f .endswith ('.css' ):
381
- app .add_css_file (f )
392
+ if f .endswith ('.css' ) or f . endswith ( '.css_t' ) :
393
+ app .add_css_file (f . replace ( '.css_t' , '.css' ) )
382
394
383
395
return {
384
396
'version' : __version__ ,
0 commit comments