Skip to content

Commit 215af5d

Browse files
committed
use CSS to hide elements on certain themes
1 parent a3b508f commit 215af5d

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

src/book/init.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ impl BookBuilder {
143143
let mut variables_css = File::create(cssdir.join("variables.css"))?;
144144
variables_css.write_all(theme::VARIABLES_CSS)?;
145145

146+
let mut excludes_css = File::create(cssdir.join("exclude.css"))?;
147+
excludes_css.write_all(theme::EXCLUDES_CSS)?;
148+
146149
let mut favicon = File::create(themedir.join("favicon.png"))?;
147150
favicon.write_all(theme::FAVICON_PNG)?;
148151

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ impl HtmlHandlebars {
229229
write_file(destination, "css/print.css", &theme.print_css)?;
230230
}
231231
write_file(destination, "css/variables.css", &theme.variables_css)?;
232+
write_file(destination, "css/exclude.css", &theme.excludes_css)?;
232233
if let Some(contents) = &theme.favicon_png {
233234
write_file(destination, "favicon.png", contents)?;
234235
}

src/theme/css/exclude.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.light .no-light {
2+
visibility: hidden;
3+
}
4+
5+
.rust .no-rust {
6+
visibility: hidden;
7+
}
8+
9+
.navy .no-navy {
10+
visibility: hidden;
11+
}
12+
13+
.ayu .no-ayu {
14+
visibility: hidden;
15+
}
16+
17+
.coal .no-coal {
18+
visibility: hidden;
19+
}
20+
21+
.navy, .ayu, .coal .no-dark {
22+
visibility: hidden;
23+
}

src/theme/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub static CHROME_CSS: &[u8] = include_bytes!("css/chrome.css");
2121
pub static GENERAL_CSS: &[u8] = include_bytes!("css/general.css");
2222
pub static PRINT_CSS: &[u8] = include_bytes!("css/print.css");
2323
pub static VARIABLES_CSS: &[u8] = include_bytes!("css/variables.css");
24+
pub static EXCLUDES_CSS: &[u8] = include_bytes!("css/exclude.css");
2425
pub static FAVICON_PNG: &[u8] = include_bytes!("favicon.png");
2526
pub static FAVICON_SVG: &[u8] = include_bytes!("favicon.svg");
2627
pub static JS: &[u8] = include_bytes!("book.js");
@@ -54,6 +55,7 @@ pub struct Theme {
5455
pub general_css: Vec<u8>,
5556
pub print_css: Vec<u8>,
5657
pub variables_css: Vec<u8>,
58+
pub excludes_css: Vec<u8>,
5759
pub favicon_png: Option<Vec<u8>>,
5860
pub favicon_svg: Option<Vec<u8>>,
5961
pub js: Vec<u8>,
@@ -91,6 +93,7 @@ impl Theme {
9193
theme_dir.join("css/variables.css"),
9294
&mut theme.variables_css,
9395
),
96+
(theme_dir.join("css/exclude.css"), &mut theme.excludes_css),
9497
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
9598
(theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
9699
(theme_dir.join("highlight.css"), &mut theme.highlight_css),
@@ -153,6 +156,7 @@ impl Default for Theme {
153156
general_css: GENERAL_CSS.to_owned(),
154157
print_css: PRINT_CSS.to_owned(),
155158
variables_css: VARIABLES_CSS.to_owned(),
159+
excludes_css: EXCLUDES_CSS.to_owned(),
156160
favicon_png: Some(FAVICON_PNG.to_owned()),
157161
favicon_svg: Some(FAVICON_SVG.to_owned()),
158162
js: JS.to_owned(),
@@ -213,6 +217,7 @@ mod tests {
213217
"css/general.css",
214218
"css/print.css",
215219
"css/variables.css",
220+
"css/exclude.css",
216221
"book.js",
217222
"highlight.js",
218223
"tomorrow-night.css",
@@ -240,6 +245,7 @@ mod tests {
240245
general_css: Vec::new(),
241246
print_css: Vec::new(),
242247
variables_css: Vec::new(),
248+
excludes_css: Vec::new(),
243249
favicon_png: Some(Vec::new()),
244250
favicon_svg: Some(Vec::new()),
245251
js: Vec::new(),

tests/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn copy_theme() {
119119
"css/general.css",
120120
"css/print.css",
121121
"css/variables.css",
122+
"css/exclude.css",
122123
"favicon.png",
123124
"favicon.svg",
124125
"highlight.css",

0 commit comments

Comments
 (0)