doxtr-html-theme-core 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- doxtr_html_theme_core-0.1.0/LICENSE +21 -0
- doxtr_html_theme_core-0.1.0/PKG-INFO +28 -0
- doxtr_html_theme_core-0.1.0/README.md +3 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/__init__.py +424 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/images.py +814 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/layout.html +75 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/page.html +4 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/drawer.html +40 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/footer.html +18 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/head.html +33 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/header.html +104 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/pygments_sync.html +17 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/sidebar_left.html +29 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/sidebar_right.html +26 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/partials/theme_images_sync.html +24 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/static/doxtr-core.css +828 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/static/doxtr-core.js +469 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/static/doxtr-tokens.css +48 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core/theme.conf +23 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core.egg-info/PKG-INFO +28 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core.egg-info/SOURCES.txt +26 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core.egg-info/dependency_links.txt +1 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core.egg-info/entry_points.txt +2 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core.egg-info/requires.txt +3 -0
- doxtr_html_theme_core-0.1.0/doxtr_html_theme_core.egg-info/top_level.txt +1 -0
- doxtr_html_theme_core-0.1.0/pyproject.toml +52 -0
- doxtr_html_theme_core-0.1.0/setup.cfg +4 -0
- doxtr_html_theme_core-0.1.0/tests/test_html_theme_core.py +771 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Doxtr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: doxtr-html-theme-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Core accessible Sphinx HTML theme powered by doxtr-theme-core and modern web standards.
|
|
5
|
+
Author: Jens Frey
|
|
6
|
+
Project-URL: Homepage, https://github.com/doxtr/doxtr-html-theme-core
|
|
7
|
+
Project-URL: Repository, https://github.com/doxtr/doxtr-html-theme-core
|
|
8
|
+
Project-URL: Issues, https://github.com/doxtr/doxtr-html-theme-core/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Framework :: Sphinx :: Extension
|
|
14
|
+
Classifier: Framework :: Sphinx :: Theme
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Documentation :: Sphinx
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: doxtr-theme-core>=0.1.0
|
|
22
|
+
Requires-Dist: Sphinx>=7.0
|
|
23
|
+
Requires-Dist: Pillow>=10.0
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# doxtr-html-theme-core
|
|
27
|
+
|
|
28
|
+
Base Sphinx HTML theme (`doxtr_core`) built on `doxtr-theme-core` with semantic design tokens (`--dd-*`), `light-dark()` + persistent color-scheme toggle, WCAG AA contrast guardrails, native `<dialog>` mobile drawer, CSS Anchor/Scrollspy TOC, copy-code commands, and cross-builder `.. stylebox::` styling.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# doxtr-html-theme-core
|
|
2
|
+
|
|
3
|
+
Base Sphinx HTML theme (`doxtr_core`) built on `doxtr-theme-core` with semantic design tokens (`--dd-*`), `light-dark()` + persistent color-scheme toggle, WCAG AA contrast guardrails, native `<dialog>` mobile drawer, CSS Anchor/Scrollspy TOC, copy-code commands, and cross-builder `.. stylebox::` styling.
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
"""Core accessible Sphinx HTML theme powered by ``doxtr-theme-core``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import shutil
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from sphinx.util import logging
|
|
10
|
+
|
|
11
|
+
from doxtr_theme_core import (
|
|
12
|
+
DEFAULT_CORE_THEME_SPEC,
|
|
13
|
+
DOXTR_SEMANTIC_PALETTE,
|
|
14
|
+
DOXTR_SEMANTIC_PALETTE_DARK_DEFAULTS,
|
|
15
|
+
add_config_value_if_missing,
|
|
16
|
+
compute_dark_palette,
|
|
17
|
+
deep_update,
|
|
18
|
+
enforce_pygments_css_wcag,
|
|
19
|
+
generate_css_font_faces,
|
|
20
|
+
generate_css_tokens,
|
|
21
|
+
get_active_theme,
|
|
22
|
+
get_ai_style_guidance,
|
|
23
|
+
get_default_icon_path,
|
|
24
|
+
get_registered_fonts,
|
|
25
|
+
register_renderer,
|
|
26
|
+
)
|
|
27
|
+
from doxtr_theme_core.fonts import collect_font_files
|
|
28
|
+
|
|
29
|
+
from .images import collect_html_image_opt_outs, process_html_theme_images
|
|
30
|
+
|
|
31
|
+
__version__ = "0.1.0"
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
THEME_DIR = Path(__file__).resolve().parent
|
|
36
|
+
HTML_BUILDERS = frozenset({"html", "dirhtml", "singlehtml", "readthedocs"})
|
|
37
|
+
|
|
38
|
+
# Register immediately so setup_brand_theme("core") finds the HTML renderer.
|
|
39
|
+
register_renderer("html", "core", "doxtr_html_theme_core", html_theme_name="doxtr_core")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _is_html_builder(app: Any) -> bool:
|
|
43
|
+
builder = getattr(app, "builder", None)
|
|
44
|
+
if builder is None:
|
|
45
|
+
return False
|
|
46
|
+
return (
|
|
47
|
+
getattr(builder, "format", None) == "html"
|
|
48
|
+
or getattr(builder, "name", "") in HTML_BUILDERS
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _resolve_html_palettes(
|
|
53
|
+
config: Any,
|
|
54
|
+
) -> tuple[Any, dict[str, str], dict[str, str], float, bool]:
|
|
55
|
+
"""Resolve light/dark semantic palettes and WCAG thresholds from Sphinx config."""
|
|
56
|
+
spec = get_active_theme(config) or DEFAULT_CORE_THEME_SPEC
|
|
57
|
+
raw_palette = dict(getattr(config, "doxtr_semantic_palette", {}) or {})
|
|
58
|
+
raw_dark = raw_palette.pop("dark", {}) if isinstance(raw_palette.get("dark"), dict) else {}
|
|
59
|
+
|
|
60
|
+
light_base = spec.light.to_semantic_dict() if spec.light else dict(DOXTR_SEMANTIC_PALETTE)
|
|
61
|
+
light_palette = deep_update(light_base, raw_palette)
|
|
62
|
+
|
|
63
|
+
dark_base = (
|
|
64
|
+
spec.dark.to_semantic_dict()
|
|
65
|
+
if spec.dark is not None
|
|
66
|
+
else dict(DOXTR_SEMANTIC_PALETTE_DARK_DEFAULTS)
|
|
67
|
+
)
|
|
68
|
+
extra_dark = dict(getattr(config, "doxtr_dark_semantic_palette", {}) or {})
|
|
69
|
+
strategy = getattr(config, "doxtr_dark_mode_strategy", spec.dark_strategy) or "auto"
|
|
70
|
+
dark_palette = compute_dark_palette(
|
|
71
|
+
light_palette,
|
|
72
|
+
deep_update(dark_base, deep_update(raw_dark, extra_dark)),
|
|
73
|
+
strategy=strategy,
|
|
74
|
+
)
|
|
75
|
+
wcag_level = float(getattr(config, "doxtr_wcag_level", None) or 4.5)
|
|
76
|
+
wcag_debug = bool(getattr(config, "doxtr_wcag_color_debug", False))
|
|
77
|
+
return spec, light_palette, dark_palette, wcag_level, wcag_debug
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def build_runtime_tokens_css(config: Any) -> str:
|
|
81
|
+
"""Compile CSS tokens + ``@font-face`` rules for the active brand & config."""
|
|
82
|
+
spec, light_palette, dark_palette, wcag_level, wcag_debug = _resolve_html_palettes(config)
|
|
83
|
+
|
|
84
|
+
registered = get_registered_fonts()
|
|
85
|
+
font_faces = generate_css_font_faces(registered, url_prefix="fonts/") if registered else ""
|
|
86
|
+
|
|
87
|
+
fonts = spec.fonts
|
|
88
|
+
return generate_css_tokens(
|
|
89
|
+
light_palette,
|
|
90
|
+
dark_palette,
|
|
91
|
+
css_body_stack=fonts.css_body_stack,
|
|
92
|
+
css_heading_stack=fonts.css_heading_stack,
|
|
93
|
+
css_mono_stack=fonts.css_mono_stack,
|
|
94
|
+
font_faces_css=font_faces,
|
|
95
|
+
wcag_level=wcag_level,
|
|
96
|
+
wcag_color_debug=wcag_debug,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _write_tokens_and_fonts(app: Any) -> None:
|
|
101
|
+
if not _is_html_builder(app):
|
|
102
|
+
return
|
|
103
|
+
outdir = Path(app.outdir)
|
|
104
|
+
static_dir = outdir / "_static"
|
|
105
|
+
static_dir.mkdir(parents=True, exist_ok=True)
|
|
106
|
+
|
|
107
|
+
css_text = build_runtime_tokens_css(app.config)
|
|
108
|
+
(static_dir / "doxtr-tokens.css").write_text(css_text, encoding="utf-8")
|
|
109
|
+
|
|
110
|
+
_, light_palette, dark_palette, wcag_level, wcag_debug = _resolve_html_palettes(app.config)
|
|
111
|
+
pyg_wcag = float(getattr(app.config, "doxtr_pygments_wcag_level", None) or wcag_level)
|
|
112
|
+
light_code_bg = str(
|
|
113
|
+
light_palette.get("code_bg") or light_palette.get("surface") or "#F8FAFC"
|
|
114
|
+
)
|
|
115
|
+
dark_code_bg = str(
|
|
116
|
+
dark_palette.get("code_bg") or dark_palette.get("surface") or "#2D2D2D"
|
|
117
|
+
)
|
|
118
|
+
for fname, bg in (("pygments.css", light_code_bg), ("pygments_dark.css", dark_code_bg)):
|
|
119
|
+
pyg_path = static_dir / fname
|
|
120
|
+
if pyg_path.is_file():
|
|
121
|
+
orig = pyg_path.read_text(encoding="utf-8", errors="ignore")
|
|
122
|
+
rewritten = enforce_pygments_css_wcag(
|
|
123
|
+
orig, bg, wcag_level=pyg_wcag, color_debug=wcag_debug
|
|
124
|
+
)
|
|
125
|
+
pyg_path.write_text(rewritten, encoding="utf-8")
|
|
126
|
+
|
|
127
|
+
font_files = collect_font_files(get_registered_fonts())
|
|
128
|
+
if font_files:
|
|
129
|
+
fonts_out = static_dir / "fonts"
|
|
130
|
+
fonts_out.mkdir(parents=True, exist_ok=True)
|
|
131
|
+
for src_str in font_files:
|
|
132
|
+
src_path = Path(src_str)
|
|
133
|
+
if src_path.is_file():
|
|
134
|
+
shutil.copy2(src_path, fonts_out / src_path.name)
|
|
135
|
+
|
|
136
|
+
logo_files: dict[str, Path] = getattr(app, "_doxtr_static_logo_files", None) or {}
|
|
137
|
+
for dest_name, src_path in logo_files.items():
|
|
138
|
+
if src_path and src_path.is_file():
|
|
139
|
+
dst = static_dir / dest_name
|
|
140
|
+
if not dst.is_file() or src_path.resolve() != dst.resolve():
|
|
141
|
+
shutil.copy2(src_path, dst)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _is_external_asset(raw: str) -> bool:
|
|
145
|
+
low = raw.strip().lower()
|
|
146
|
+
return low.startswith(("http://", "https://", "//", "data:"))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _is_disabled_logo(raw: Any) -> bool:
|
|
150
|
+
return isinstance(raw, str) and raw.strip().lower() in {"none", "off", "false"}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _resolve_local_asset(app: Any, raw_value: Any) -> tuple[str | None, Path | None]:
|
|
154
|
+
"""Resolve an external URL or local image path against confdir/srcdir/html_static_path."""
|
|
155
|
+
if not raw_value:
|
|
156
|
+
return None, None
|
|
157
|
+
raw = str(raw_value).strip()
|
|
158
|
+
if not raw or _is_disabled_logo(raw):
|
|
159
|
+
return None, None
|
|
160
|
+
if _is_external_asset(raw):
|
|
161
|
+
return raw, None
|
|
162
|
+
|
|
163
|
+
p = Path(raw)
|
|
164
|
+
if p.is_absolute() and p.is_file():
|
|
165
|
+
return None, p
|
|
166
|
+
|
|
167
|
+
confdir = Path(str(getattr(app, "confdir", "") or "."))
|
|
168
|
+
srcdir = Path(str(getattr(app, "srcdir", "") or confdir))
|
|
169
|
+
candidates: list[Path] = [confdir / raw, srcdir / raw]
|
|
170
|
+
for sp in getattr(app.config, "html_static_path", None) or []:
|
|
171
|
+
sp_path = Path(str(sp))
|
|
172
|
+
base = sp_path if sp_path.is_absolute() else confdir / sp_path
|
|
173
|
+
candidates.append(base / raw)
|
|
174
|
+
for cand in candidates:
|
|
175
|
+
if cand.is_file():
|
|
176
|
+
return None, cand
|
|
177
|
+
logger.warning("[Doxtr HTML Core] Configured logo/favicon asset not found: %r", raw)
|
|
178
|
+
return None, None
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _resolve_header_titles(
|
|
182
|
+
app: Any,
|
|
183
|
+
context: dict[str, Any],
|
|
184
|
+
spec: Any,
|
|
185
|
+
) -> tuple[str, str]:
|
|
186
|
+
"""Return ``(header_title, full_title)`` favoring project title & user short_name."""
|
|
187
|
+
config = app.config
|
|
188
|
+
raw_cfg = getattr(config, "_raw_config", None) or {}
|
|
189
|
+
doxtr_branding = dict(getattr(config, "doxtr_branding", None) or {})
|
|
190
|
+
|
|
191
|
+
root_doc = str(getattr(config, "root_doc", None) or getattr(config, "master_doc", None) or "index")
|
|
192
|
+
env = getattr(app, "env", None)
|
|
193
|
+
root_title_node = getattr(env, "titles", {}).get(root_doc) if env is not None else None
|
|
194
|
+
root_doc_title = root_title_node.astext().strip() if root_title_node is not None else ""
|
|
195
|
+
|
|
196
|
+
project_raw = str(getattr(config, "project", "") or "").strip()
|
|
197
|
+
html_title_raw = str(getattr(config, "html_title", "") or "").strip()
|
|
198
|
+
html_short_raw = str(getattr(config, "html_short_title", "") or "").strip()
|
|
199
|
+
brand_display = (
|
|
200
|
+
str(getattr(spec.branding, "display_name", "") or "").strip()
|
|
201
|
+
if spec.name not in {"core", "aubergine"}
|
|
202
|
+
else ""
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if "html_title" in raw_cfg and html_title_raw:
|
|
206
|
+
full_title = html_title_raw
|
|
207
|
+
elif "project" in raw_cfg and project_raw:
|
|
208
|
+
full_title = project_raw
|
|
209
|
+
elif brand_display:
|
|
210
|
+
full_title = brand_display
|
|
211
|
+
else:
|
|
212
|
+
full_title = (
|
|
213
|
+
root_doc_title
|
|
214
|
+
or project_raw
|
|
215
|
+
or str(context.get("docstitle", "") or "").strip()
|
|
216
|
+
or str(getattr(spec.branding, "display_name", "") or "").strip()
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
explicit_short_html_title = (
|
|
220
|
+
html_short_raw
|
|
221
|
+
if ("html_short_title" in raw_cfg or (html_short_raw and html_short_raw != html_title_raw))
|
|
222
|
+
else ""
|
|
223
|
+
)
|
|
224
|
+
brand_short = (
|
|
225
|
+
str(getattr(spec.branding, "short_name", "") or "").strip()
|
|
226
|
+
if spec.name not in {"core", "aubergine"}
|
|
227
|
+
else ""
|
|
228
|
+
)
|
|
229
|
+
candidates = [
|
|
230
|
+
str(context.get("theme_short_name", "") or "").strip(),
|
|
231
|
+
str(doxtr_branding.get("short_name", "") or "").strip(),
|
|
232
|
+
explicit_short_html_title,
|
|
233
|
+
str(context.get("theme_brand_name", "") or "").strip(),
|
|
234
|
+
str(doxtr_branding.get("display_name", "") or "").strip(),
|
|
235
|
+
brand_short,
|
|
236
|
+
full_title,
|
|
237
|
+
]
|
|
238
|
+
header_title = next((c for c in candidates if c), "")
|
|
239
|
+
return header_title, (full_title or header_title)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _to_static_url(
|
|
243
|
+
app: Any,
|
|
244
|
+
context: dict[str, Any],
|
|
245
|
+
ext_url: str | None,
|
|
246
|
+
src_path: Path | None,
|
|
247
|
+
*,
|
|
248
|
+
auto_adapt: bool = False,
|
|
249
|
+
) -> str:
|
|
250
|
+
if ext_url:
|
|
251
|
+
return ext_url
|
|
252
|
+
if src_path is None:
|
|
253
|
+
return ""
|
|
254
|
+
dest_name = src_path.name
|
|
255
|
+
files_map = getattr(app, "_doxtr_static_logo_files", None)
|
|
256
|
+
if files_map is None:
|
|
257
|
+
files_map = {}
|
|
258
|
+
app._doxtr_static_logo_files = files_map
|
|
259
|
+
files_map[dest_name] = src_path
|
|
260
|
+
if auto_adapt:
|
|
261
|
+
adapt_map = getattr(app, "_doxtr_static_logo_auto_adapt", None)
|
|
262
|
+
if adapt_map is None:
|
|
263
|
+
adapt_map = {}
|
|
264
|
+
app._doxtr_static_logo_auto_adapt = adapt_map
|
|
265
|
+
adapt_map[dest_name] = src_path
|
|
266
|
+
|
|
267
|
+
pathto = context.get("pathto")
|
|
268
|
+
if callable(pathto):
|
|
269
|
+
return str(pathto(f"_static/{dest_name}", 1))
|
|
270
|
+
return f"_static/{dest_name}"
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def _resolve_logo_and_favicon(
|
|
274
|
+
app: Any,
|
|
275
|
+
context: dict[str, Any],
|
|
276
|
+
spec: Any,
|
|
277
|
+
header_title: str,
|
|
278
|
+
) -> None:
|
|
279
|
+
"""Resolve header logo (light/dark) and default favicon with theme-core icon fallback."""
|
|
280
|
+
config = app.config
|
|
281
|
+
doxtr_branding = dict(getattr(config, "doxtr_branding", None) or {})
|
|
282
|
+
theme_logo_light = context.get("theme_logo_light")
|
|
283
|
+
theme_logo_dark = context.get("theme_logo_dark")
|
|
284
|
+
theme_logo = context.get("theme_logo")
|
|
285
|
+
brand_logo_light = doxtr_branding.get("logo_light")
|
|
286
|
+
brand_logo_dark = doxtr_branding.get("logo_dark")
|
|
287
|
+
brand_logo = doxtr_branding.get("logo")
|
|
288
|
+
sphinx_logo = getattr(config, "html_logo", None)
|
|
289
|
+
spec_logo_light = getattr(spec.branding, "logo_light", "")
|
|
290
|
+
spec_logo_dark = getattr(spec.branding, "logo_dark", "")
|
|
291
|
+
|
|
292
|
+
raw_light: Any = ""
|
|
293
|
+
raw_dark: Any = ""
|
|
294
|
+
disabled = False
|
|
295
|
+
|
|
296
|
+
if _is_disabled_logo(theme_logo) or (not theme_logo and not theme_logo_light and _is_disabled_logo(brand_logo)):
|
|
297
|
+
disabled = True
|
|
298
|
+
elif theme_logo_light or theme_logo_dark or theme_logo:
|
|
299
|
+
raw_light = theme_logo_light or theme_logo
|
|
300
|
+
raw_dark = theme_logo_dark or ""
|
|
301
|
+
elif brand_logo_light or brand_logo_dark or brand_logo:
|
|
302
|
+
raw_light = brand_logo_light or brand_logo
|
|
303
|
+
raw_dark = brand_logo_dark or ""
|
|
304
|
+
elif sphinx_logo:
|
|
305
|
+
raw_light = sphinx_logo
|
|
306
|
+
elif spec_logo_light or spec_logo_dark:
|
|
307
|
+
raw_light = spec_logo_light
|
|
308
|
+
raw_dark = spec_logo_dark
|
|
309
|
+
else:
|
|
310
|
+
try:
|
|
311
|
+
raw_light = str(get_default_icon_path(small=True))
|
|
312
|
+
except FileNotFoundError:
|
|
313
|
+
raw_light = ""
|
|
314
|
+
|
|
315
|
+
if disabled:
|
|
316
|
+
light_url = ""
|
|
317
|
+
dark_url = ""
|
|
318
|
+
else:
|
|
319
|
+
light_ext, light_path = _resolve_local_asset(app, raw_light)
|
|
320
|
+
dark_ext, dark_path = _resolve_local_asset(app, raw_dark)
|
|
321
|
+
has_explicit_dark = bool(dark_ext or dark_path)
|
|
322
|
+
light_url = _to_static_url(
|
|
323
|
+
app, context, light_ext, light_path, auto_adapt=(not has_explicit_dark)
|
|
324
|
+
)
|
|
325
|
+
dark_url = _to_static_url(app, context, dark_ext, dark_path, auto_adapt=False)
|
|
326
|
+
|
|
327
|
+
context["doxtr_logo_light_url"] = light_url
|
|
328
|
+
context["doxtr_logo_dark_url"] = dark_url
|
|
329
|
+
alt_override = str(context.get("theme_logo_alt", "") or "").strip()
|
|
330
|
+
if alt_override:
|
|
331
|
+
context["doxtr_logo_alt"] = alt_override
|
|
332
|
+
elif header_title:
|
|
333
|
+
context["doxtr_logo_alt"] = f"{header_title} logo"
|
|
334
|
+
else:
|
|
335
|
+
context["doxtr_logo_alt"] = str(context.get("logo_alt", "Documentation logo") or "Documentation logo")
|
|
336
|
+
|
|
337
|
+
if not context.get("favicon_url") and not getattr(config, "html_favicon", None):
|
|
338
|
+
fav_raw: Any = doxtr_branding.get("favicon") or getattr(spec.branding, "favicon", "")
|
|
339
|
+
if not fav_raw:
|
|
340
|
+
try:
|
|
341
|
+
fav_raw = str(get_default_icon_path(small=True))
|
|
342
|
+
except FileNotFoundError:
|
|
343
|
+
fav_raw = ""
|
|
344
|
+
fav_ext, fav_path = _resolve_local_asset(app, fav_raw)
|
|
345
|
+
fav_url = _to_static_url(app, context, fav_ext, fav_path, auto_adapt=False)
|
|
346
|
+
if fav_url:
|
|
347
|
+
context["favicon_url"] = fav_url
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _on_doctree_resolved(app: Any, doctree: Any, docname: str) -> None:
|
|
351
|
+
if _is_html_builder(app):
|
|
352
|
+
collect_html_image_opt_outs(app, doctree)
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _on_builder_inited(app: Any) -> None:
|
|
356
|
+
if not _is_html_builder(app):
|
|
357
|
+
return
|
|
358
|
+
app.add_css_file("doxtr-tokens.css", priority=150)
|
|
359
|
+
app.add_css_file("doxtr-core.css", priority=175)
|
|
360
|
+
app.add_js_file("doxtr-core.js", priority=600)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def _on_build_finished(app: Any, exception: Exception | None) -> None:
|
|
364
|
+
if exception is not None:
|
|
365
|
+
return
|
|
366
|
+
try:
|
|
367
|
+
_write_tokens_and_fonts(app)
|
|
368
|
+
except Exception as exc: # pragma: no cover - defensive build guard
|
|
369
|
+
logger.warning("[Doxtr HTML Core] Failed writing runtime tokens: %s", exc)
|
|
370
|
+
if _is_html_builder(app):
|
|
371
|
+
try:
|
|
372
|
+
_, _, dark_palette, _, _ = _resolve_html_palettes(app.config)
|
|
373
|
+
process_html_theme_images(app, dark_palette)
|
|
374
|
+
except Exception as exc: # pragma: no cover - defensive build guard
|
|
375
|
+
logger.warning("[Doxtr HTML Core] Failed processing theme images: %s", exc)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def _inject_page_context(
|
|
379
|
+
app: Any,
|
|
380
|
+
pagename: str,
|
|
381
|
+
templatename: str,
|
|
382
|
+
context: dict[str, Any],
|
|
383
|
+
doctree: Any,
|
|
384
|
+
) -> None:
|
|
385
|
+
spec = get_active_theme(app.config) or DEFAULT_CORE_THEME_SPEC
|
|
386
|
+
scheme = str(getattr(app.config, "doxtr_color_scheme", "auto") or "auto").lower()
|
|
387
|
+
if scheme not in {"auto", "light", "dark"}:
|
|
388
|
+
scheme = "auto"
|
|
389
|
+
|
|
390
|
+
context["doxtr_color_scheme"] = scheme
|
|
391
|
+
context["doxtr_active_brand"] = spec.name
|
|
392
|
+
context["doxtr_brand"] = spec.branding
|
|
393
|
+
context["doxtr_guidance"] = get_ai_style_guidance(spec.name)
|
|
394
|
+
|
|
395
|
+
header_title, full_title = _resolve_header_titles(app, context, spec)
|
|
396
|
+
context["doxtr_header_title"] = header_title
|
|
397
|
+
context["doxtr_full_title"] = full_title
|
|
398
|
+
context["theme_brand_name"] = header_title
|
|
399
|
+
|
|
400
|
+
_resolve_logo_and_favicon(app, context, spec, header_title)
|
|
401
|
+
|
|
402
|
+
if not context.get("theme_tagline") and spec.branding.tagline:
|
|
403
|
+
context["theme_tagline"] = spec.branding.tagline
|
|
404
|
+
if not context.get("theme_repo_url") and spec.branding.repository_url:
|
|
405
|
+
context["theme_repo_url"] = spec.branding.repository_url
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def setup(app: Any) -> dict[str, Any]:
|
|
409
|
+
"""Sphinx extension entry point for ``doxtr_html_theme_core``."""
|
|
410
|
+
app.setup_extension("doxtr_theme_core")
|
|
411
|
+
add_config_value_if_missing(app, "doxtr_html_dark_images", True, "env")
|
|
412
|
+
add_config_value_if_missing(app, "doxtr_dark_image_brightness_threshold", 0.65, "env")
|
|
413
|
+
app.add_html_theme("doxtr_core", str(THEME_DIR))
|
|
414
|
+
|
|
415
|
+
app.connect("builder-inited", _on_builder_inited)
|
|
416
|
+
app.connect("doctree-resolved", _on_doctree_resolved)
|
|
417
|
+
app.connect("html-page-context", _inject_page_context, priority=600)
|
|
418
|
+
app.connect("build-finished", _on_build_finished)
|
|
419
|
+
|
|
420
|
+
return {
|
|
421
|
+
"version": __version__,
|
|
422
|
+
"parallel_read_safe": True,
|
|
423
|
+
"parallel_write_safe": True,
|
|
424
|
+
}
|