Skip to content

Commit e2cc426

Browse files
committed
Force RTL but keep codeboxes LTR
1 parent 091917c commit e2cc426

2 files changed

Lines changed: 42 additions & 40 deletions

File tree

python_docs_theme/layout.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ <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 %}
8389
{{ super() }}
8490
{%- endblock -%}
8591

python_docs_theme/static/pydoctheme.css

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ div.related a:hover {
108108
}
109109

110110
.switchers > div {
111-
margin-right: 5px;
111+
margin-inline-end: 5px;
112112
}
113113

114114
div.related ul::after {
@@ -159,7 +159,7 @@ div.sphinxsidebar h4 {
159159
}
160160

161161
div.bodywrapper {
162-
margin-left: min(25vw, 350px);
162+
margin-inline-start: min(25vw, 350px);
163163
}
164164

165165
div.sphinxsidebarwrapper {
@@ -202,8 +202,9 @@ div.sphinxsidebar input[type='text'] {
202202
align-items: center;
203203
width: 12px;
204204
min-width: 12px;
205-
border-radius: 0 5px 5px 0;
206-
border-left: none;
205+
border-start-end-radius: 5px;
206+
border-end-end-radius: 5px;
207+
border-inline-start: none;
207208
}
208209

209210
#sidebarbutton:hover {
@@ -215,7 +216,7 @@ div.body {
215216
}
216217

217218
div.body p, div.body dd, div.body li, div.body blockquote {
218-
text-align: left;
219+
text-align: start;
219220
line-height: 1.6;
220221
}
221222
div.body h1, div.body h2, div.body h3, div.body h4, div.body h5, div.body h6 {
@@ -233,6 +234,10 @@ div.body hr {
233234
height: 1px;
234235
}
235236

237+
div.body pre, div.body code, div.highlight {
238+
direction: ltr;
239+
}
240+
236241
div.body pre {
237242
border-radius: 3px;
238243
border: 1px solid #ac9;
@@ -251,19 +256,10 @@ div.body {
251256
}
252257

253258
div.code-block-caption {
254-
background-color: #eee;
255-
border: 1px solid #ac9;
256-
border-bottom: none;
257-
border-radius: 3px 3px 0 0;
258-
padding: 0.3em 0.6em;
259-
font-size: 90%;
260-
color: #333;
261-
262259
& + div pre {
263260
border-top-left-radius: 0 !important;
264261
border-top-right-radius: 0 !important;
265262
}
266-
267263
& + div .copybutton {
268264
border-top-right-radius: 0 !important;
269265
}
@@ -402,7 +398,7 @@ table.docutils th {
402398

403399
table p,
404400
table li {
405-
text-align: left !important;
401+
text-align: start !important;
406402
}
407403

408404
table.docutils th {
@@ -416,9 +412,9 @@ table.footnote td {
416412

417413
div.footer {
418414
line-height: 150%;
419-
text-align: right;
415+
text-align: end; /* was: text-align: right */
420416
width: auto;
421-
margin-right: 10px;
417+
margin-inline-end: 10px; /* was: margin-right */
422418
}
423419

424420
div.footer a {
@@ -506,17 +502,17 @@ div.genindex-jumpbox a {
506502
cursor: pointer;
507503
position: absolute;
508504
top: 0;
509-
right: 0;
505+
right: 0; /* physical right; always, even in RTL, since code is LTR */
510506
font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;
511507
font-size: 80%;
512508
padding-left: .5em;
513509
padding-right: .5em;
514510
height: 100%;
515511
max-height: min(100%, 2.4em);
516-
border-radius: 0 3px 0 0;
512+
border-radius: 0 3px 0 0; /* physical — top-right corner, always */
517513
color: #000;
518514
background-color: #fff;
519-
border: 1px solid #ac9; /* follows div.body pre */
515+
border: 1px solid #ac9;
520516
display: none;
521517
}
522518

@@ -583,7 +579,7 @@ div.genindex-jumpbox a {
583579
width: 100%;
584580
position: fixed;
585581
top: 0;
586-
left: 0;
582+
inset-inline-start: 0;
587583
box-shadow: rgba(0, 0, 0, 0.25) 0 0 2px 0;
588584
z-index: 1;
589585
}
@@ -605,7 +601,7 @@ div.genindex-jumpbox a {
605601
align-items: stretch;
606602
}
607603
.nav-logo {
608-
margin-right: 1rem;
604+
margin-inline-end: 1rem;
609605
flex-shrink: 0;
610606
align-self: center;
611607
}
@@ -614,7 +610,7 @@ div.genindex-jumpbox a {
614610
width: 20px;
615611
}
616612
.version_switcher_placeholder {
617-
margin-right: 1rem;
613+
margin-inline-end: 1rem;
618614
}
619615
.version_switcher_placeholder > select {
620616
height: 100%;
@@ -627,22 +623,22 @@ div.genindex-jumpbox a {
627623
}
628624
.nav-content .search input[type=search] {
629625
border: 0;
630-
padding-left: 24px;
626+
padding-inline-start: 24px; /* was: padding-left */
631627
width: 100%;
632628
flex: 1;
633629
}
634630
.nav-content .search input[type=submit] {
635631
height: 100%;
636632
box-shadow: none;
637633
border: 0;
638-
border-left: 1px solid #a9a9a9;
634+
border-inline-start: 1px solid #a9a9a9;
639635
cursor: pointer;
640-
margin-right: 0;
636+
margin-inline-end: 0;
641637
}
642638
.nav-content .search svg {
643639
position: absolute;
644640
align-self: center;
645-
padding-left: 4px;
641+
padding-inline-start: 4px;
646642
}
647643
.toggler__input {
648644
display: none;
@@ -674,7 +670,7 @@ div.genindex-jumpbox a {
674670
width: 100%;
675671
background: inherit;
676672
position: absolute;
677-
left: 0;
673+
inset-inline-start: 0;
678674
top: -8px;
679675
}
680676
.toggler__label > span::after {
@@ -695,16 +691,16 @@ div.genindex-jumpbox a {
695691
}
696692
.toggler__input:checked ~ .menu-wrapper {
697693
visibility: visible;
698-
left: 0;
694+
inset-inline-start: 0; /* was: left: 0 */
699695
}
700696

701697
/* Sliding side menu */
702698
.menu-wrapper {
703699
display: block;
704700
position: fixed;
705701
top: 0;
706-
transition: left 400ms ease;
707-
left: -310px;
702+
transition: inset-inline-start 400ms ease;
703+
inset-inline-start: -310px;
708704
width: 300px;
709705
height: 100%;
710706
background-color: #eee;
@@ -714,7 +710,7 @@ div.genindex-jumpbox a {
714710
}
715711
.menu-wrapper.open {
716712
visibility: visible;
717-
left: 0;
713+
inset-inline-start: 0;
718714
}
719715
.menu {
720716
padding: 40px 10px 30px 20px;
@@ -742,10 +738,10 @@ div.genindex-jumpbox a {
742738
list-style: none;
743739
line-height: 1.4;
744740
overflow-wrap: break-word;
745-
padding-left: 0;
741+
padding-inline-start: 0;
746742
}
747743
.menu ul ul {
748-
margin-left: 20px;
744+
margin-inline-start: 20px;
749745
list-style: square;
750746
}
751747
.menu ul li {
@@ -801,26 +797,26 @@ div.versionadded,
801797
div.versionchanged,
802798
div.deprecated,
803799
div.deprecated-removed {
804-
border-left: 3px solid;
800+
border-inline-start: 3px solid;
805801
padding: 0 1rem;
806802
}
807803

808804
div.versionadded {
809-
border-left-color: var(--versionadded-border);
805+
border-inline-start-color: var(--versionadded-border);
810806
}
811807

812808
div.versionchanged {
813-
border-left-color: var(--versionchanged-border);
809+
border-inline-start-color: var(--versionchanged-border);
814810
}
815811

816812
div.deprecated,
817813
div.deprecated-removed,
818814
div.versionremoved {
819-
border-left-color: var(--deprecated-border);
815+
border-inline-start-color: var(--deprecated-border);
820816
}
821817

822818
div.soft-deprecated {
823-
border-left-color: var(--soft-deprecated-border);
819+
border-inline-start-color: var(--soft-deprecated-border);
824820
}
825821

826822
div.versionadded .versionmodified {
@@ -846,4 +842,4 @@ div.soft-deprecated .versionmodified {
846842
div.mobile-nav {
847843
display: none;
848844
}
849-
}
845+
}

0 commit comments

Comments
 (0)