Skip to content

Commit 3384578

Browse files
committed
Add support for right-to-left languages
This updates our `mdbook` version to the latest version in Git. I copied the `index.hbs` file from that version and back-ported our changes into it. I checked English and Danish locally and they both look fine. The new version has support for right-to-left languages: rust-lang/mdBook#1641. We have an in-progress Persian translation. Download the `fa.zip` artifact after building the PR to check how it looks. I checked Persian locally and it looks mirrored like I expect (but we will need someone who can read Persian to actually verify this). Fixes #1164.
1 parent 5e72cf5 commit 3384578

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

.github/workflows/install-mdbook/action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ runs:
88
# The --locked flag is important for reproducible builds. It also
99
# avoids breakage due to skews between mdbook and mdbook-svgbob.
1010
- name: Install mdbook
11-
run: cargo install mdbook --locked --version 0.4.34
11+
# See https://github.com/google/comprehensive-rust/issues/1164.
12+
# We will revert to a released version of mdbook as soon as the
13+
# commit referenced here is released.
14+
run: cargo install --git https://github.com/rust-lang/mdbook/ --rev 09f222b
1215
shell: bash
1316

1417
- name: Install mdbook-svgbob

language-picker.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
right: 10px;
44
}
55

6+
[dir=rtl] #language-list {
7+
left: 10px;
8+
right: auto;
9+
}
10+
611
#language-list a {
712
color: inherit;
813
}

theme/index.hbs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE HTML>
2-
<html lang="{{ language }}" class="sidebar-visible no-js {{ default_theme }}">
2+
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
33
<head>
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">
@@ -63,7 +63,7 @@
6363
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
6464
{{/if}}
6565
</head>
66-
<body>
66+
<body class="sidebar-visible no-js">
6767
<div id="body-container">
6868
<!-- Provide site root to javascript -->
6969
<script>
@@ -93,24 +93,29 @@
9393
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
9494
if (theme === null || theme === undefined) { theme = default_theme; }
9595
var html = document.querySelector('html');
96-
html.classList.remove('no-js')
9796
html.classList.remove('{{ default_theme }}')
9897
html.classList.add(theme);
99-
html.classList.add('js');
98+
var body = document.querySelector('body');
99+
body.classList.remove('no-js')
100+
body.classList.add('js');
100101
</script>
101102

103+
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
104+
102105
<!-- Hide / unhide sidebar before it is displayed -->
103106
<script>
104-
var html = document.querySelector('html');
107+
var body = document.querySelector('body');
105108
var sidebar = null;
109+
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
106110
if (document.body.clientWidth >= 1080) {
107111
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
108112
sidebar = sidebar || 'visible';
109113
} else {
110114
sidebar = 'hidden';
111115
}
112-
html.classList.remove('sidebar-visible');
113-
html.classList.add("sidebar-" + sidebar);
116+
sidebar_toggle.checked = sidebar === 'visible';
117+
body.classList.remove('sidebar-visible');
118+
body.classList.add("sidebar-" + sidebar);
114119
</script>
115120

116121
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
@@ -176,9 +181,9 @@
176181
<div id="menu-bar-hover-placeholder"></div>
177182
<div id="menu-bar" class="menu-bar sticky">
178183
<div class="left-buttons">
179-
<button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
184+
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
180185
<i class="fa fa-bars"></i>
181-
</button>
186+
</label>
182187
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
183188
<i class="fa fa-paint-brush"></i>
184189
</button>

0 commit comments

Comments
 (0)