Skip to content

Commit a4d0f82

Browse files
committed
Address review comments
1 parent e9a4b29 commit a4d0f82

3 files changed

Lines changed: 74 additions & 49 deletions

File tree

python_docs_theme/__init__.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pathlib import Path
44

5+
from markupsafe import Markup, escape
56
from sphinx.locale import get_translation
67

78
TYPE_CHECKING = False
@@ -17,6 +18,11 @@
1718
LOCALE_DIR = THEME_PATH / "locale"
1819
MESSAGE_CATALOG_NAME = "python-docs-theme"
1920

21+
def _tobool(val: object) -> bool:
22+
if isinstance(val, str):
23+
return val.lower() in {"true", "1", "yes", "on"}
24+
return bool(val)
25+
2026

2127
def add_translation_to_context(
2228
app: Sphinx,
@@ -37,15 +43,40 @@ def combined(message: str) -> str:
3743
context["_"] = context["gettext"] = context["ngettext"] = combined
3844

3945

46+
def add_html_dir_to_context(
47+
app: Sphinx,
48+
pagename: str,
49+
templatename: str,
50+
context: dict[str, Any],
51+
doctree: None,
52+
) -> None:
53+
language = app.config.language or "en"
54+
55+
is_rtl_option = context.get("theme_is_rtl", "")
56+
if is_rtl_option in (None, ""):
57+
is_rtl = False
58+
else:
59+
is_rtl = _tobool(is_rtl_option)
60+
61+
dir_attr = "rtl" if is_rtl else "ltr"
62+
63+
content_root = context.get("content_root", "")
64+
lang_part = f' lang="{escape(language)}"' if language is not None else ""
65+
context["html_tag"] = Markup(
66+
f'<html{lang_part} dir="{dir_attr}" data-content_root="{escape(content_root)}">'
67+
)
68+
69+
4070
def setup(app: Sphinx) -> ExtensionMetadata:
4171
app.require_sphinx("7.3")
4272

4373
app.add_html_theme("python_docs_theme", str(THEME_PATH))
4474
app.add_message_catalog(MESSAGE_CATALOG_NAME, LOCALE_DIR)
4575
app.connect("html-page-context", add_translation_to_context)
76+
app.connect("html-page-context", add_html_dir_to_context)
4677

4778
return {
4879
"version": __version__,
4980
"parallel_read_safe": True,
5081
"parallel_write_safe": True,
51-
}
82+
}

python_docs_theme/layout.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h3>{{ _('Navigation') }}</h3>
77
<ul>
88
{%- for rellink in rellinks %}
9-
<li class="right" {% if loop.first %}style="margin-right: 10px"{% endif %}>
9+
<li class="right" {% if loop.first %}style="margin-inline-end: 10px"{% endif %}>
1010
<a href="{{ pathto(rellink[0])|e }}" title="{{ rellink[1]|striptags|e }}"
1111
{{ accesskey(rellink[2]) }}>{{ rellink[3] }}
1212
</a>
@@ -80,12 +80,6 @@ <h3>{{ _('Navigation') }}</h3>
8080
<script type="text/javascript" src="{{ pathto('_static/themetoggle.js', 1) }}"></script>
8181
{%- endif -%}
8282
{%- endif -%}
83-
{%- if theme_is_rtl|lower == "true" %}
84-
<script>
85-
document.documentElement.dir = 'rtl';
86-
document.documentElement.lang = '{{ language }}';
87-
</script>
88-
{%- endif %}
8983
{{ super() }}
9084
{%- endblock -%}
9185

@@ -175,4 +169,4 @@ <h3>{{ _('Navigation') }}</h3>
175169

176170
{% trans sphinx_version=sphinx_version|e %}Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> {{ sphinx_version }}.{% endtrans %}
177171
</div>
178-
{% endblock %}
172+
{% endblock %}

python_docs_theme/static/pydoctheme.css

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,15 @@ div.related ul::after {
117117
display: block;
118118
}
119119

120-
html[dir='rtl'] div.related ul {
121-
padding: 0 10px 0 0;
120+
div.related ul {
121+
padding: 0;
122+
padding-inline-start: 10px;
122123
}
123124

124125
html[dir='rtl'] div.related ul li.right {
125126
float: left;
126-
}
127-
128-
html[dir='rtl'] div.related ul li {
129-
float: right;
130-
padding-inline: 0.3em;
127+
margin-right: 0;
128+
margin-left: 5px;
131129
}
132130

133131
.inline-search,
@@ -175,8 +173,8 @@ div.sphinxsidebar h4 {
175173
margin-top: 1.5em;
176174
}
177175

178-
div.bodywrapper {
179-
margin-inline-start: 0;
176+
div.document div.bodywrapper {
177+
margin: 0;
180178
}
181179

182180
div.documentwrapper {
@@ -202,6 +200,11 @@ div.sphinxsidebarwrapper > ul > li > ul > li {
202200
margin-bottom: 0.4em;
203201
}
204202

203+
div.sphinxsidebar ul ul {
204+
margin-left: 0;
205+
margin-inline-start: 20px;
206+
}
207+
205208
div.sphinxsidebar a:hover {
206209
color: #0095c4;
207210
}
@@ -227,19 +230,18 @@ div.sphinxsidebar input[type='text'] {
227230
min-width: 12px;
228231
border-start-end-radius: 5px;
229232
border-end-end-radius: 5px;
230-
border-inline-start: none;
233+
border-left: none;
231234
}
232235

233236
#sidebarbutton:hover {
234237
background-color: #AAAAAA;
235238
}
236239

237240
div.body {
238-
padding: 0 0 0 1.2em;
241+
padding-inline-start: 1.2em;
239242
}
240243

241244
html[dir='rtl'] div.body {
242-
padding: 0 1.2em 0 0;
243245
direction: rtl;
244246
}
245247

@@ -254,6 +256,10 @@ div.body h1, div.body h2, div.body h3, div.body h4, div.body h5, div.body h6 {
254256
}
255257
div.body dl.field-list > dt {
256258
line-height: 1.6;
259+
padding-left: 0;
260+
padding-right: 0;
261+
padding-inline-start: 0.5em;
262+
padding-inline-end: 5px;
257263
}
258264

259265
div.body hr {
@@ -262,8 +268,14 @@ div.body hr {
262268
height: 1px;
263269
}
264270

265-
div.body pre, div.body code, div.highlight {
271+
pre,
272+
code,
273+
div.highlight,
274+
dl > dt span ~ em,
275+
.sig,
276+
.sig-param {
266277
direction: ltr;
278+
unicode-bidi: isolate;
267279
}
268280

269281
div.body pre {
@@ -508,11 +520,6 @@ div.footer a:hover {
508520
}
509521

510522

511-
dl > dt span ~ em,
512-
.sig {
513-
font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;
514-
}
515-
516523
.toctree-wrapper ul {
517524
padding-inline-start: 20px;
518525
}
@@ -635,9 +642,6 @@ div.genindex-jumpbox a {
635642
padding: .25rem;
636643
align-items: stretch;
637644
}
638-
html[dir='rtl'] .nav-items-wrapper {
639-
flex-direction: row-reverse;
640-
}
641645
.nav-logo {
642646
margin-inline-end: 1rem;
643647
flex-shrink: 0;
@@ -661,14 +665,10 @@ div.genindex-jumpbox a {
661665
}
662666
.nav-content .search input[type=search] {
663667
border: 0;
664-
padding-inline-start: 24px; /* was: padding-left */
668+
padding-inline-start: 24px;
665669
width: 100%;
666670
flex: 1;
667671
}
668-
html[dir='rtl'] .nav-content .search input[type=search] {
669-
padding-inline-start: 4px;
670-
padding-inline-end: 24px;
671-
}
672672
.nav-content .search input[type=submit] {
673673
height: 100%;
674674
box-shadow: none;
@@ -680,11 +680,7 @@ div.genindex-jumpbox a {
680680
.nav-content .search svg {
681681
position: absolute;
682682
align-self: center;
683-
padding-inline-start: 4px;
684-
}
685-
html[dir='rtl'] .nav-content .search svg {
686-
padding-inline-start: 0;
687-
padding-inline-end: 4px;
683+
inset-inline-start: 4px;
688684
}
689685
.toggler__input {
690686
display: none;
@@ -698,9 +694,6 @@ div.genindex-jumpbox a {
698694
padding: 8px;
699695
flex-shrink: 0;
700696
}
701-
html[dir='rtl'] .toggler__label {
702-
order: 1;
703-
}
704697
.toggler__label:hover, .toggler__label:focus {
705698
background-color: rgba(127 127 127 / 50%);
706699
}
@@ -740,29 +733,36 @@ div.genindex-jumpbox a {
740733
}
741734
.toggler__input:checked ~ .menu-wrapper {
742735
visibility: visible;
743-
inset-inline-start: 0; /* was: left: 0 */
736+
transform: translateX(0);
744737
}
745738

746739
/* Sliding side menu */
747740
.menu-wrapper {
748741
display: block;
749742
position: fixed;
750743
top: 0;
751-
transition: inset-inline-start 400ms ease;
752-
inset-inline-start: -310px;
744+
inset-inline-start: 0;
745+
transition: transform 400ms ease;
746+
transform: translateX(-100%);
753747
width: 300px;
754748
height: 100%;
755749
background-color: #eee;
756750
color: #444444;
757751
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
758752
overflow-y: auto;
759753
}
754+
html[dir='rtl'] .menu-wrapper {
755+
transform: translateX(100%);
756+
}
760757
.menu-wrapper.open {
761758
visibility: visible;
762-
inset-inline-start: 0;
759+
transform: translateX(0);
763760
}
764761
.menu {
765-
padding: 40px 10px 30px 20px;
762+
padding-block-start: 40px;
763+
padding-inline-end: 10px;
764+
padding-block-end: 30px;
765+
padding-inline-start: 20px;
766766
}
767767
.menu-wrapper h3,
768768
.menu-wrapper h4 {
@@ -891,4 +891,4 @@ div.soft-deprecated .versionmodified {
891891
div.mobile-nav {
892892
display: none;
893893
}
894-
}
894+
}

0 commit comments

Comments
 (0)