Skip to content

Commit b65a369

Browse files
Improve documentation, add checks for themes option arguments, make sure the themes file names are js compatible
1 parent 29494a8 commit b65a369

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/doc/rustdoc/src/command-line-arguments.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ you'll need to use this flag as follows:
368368
$ rustdoc src/lib.rs --themes /path/to/your/theme/file.css
369369
```
370370

371+
Note that the theme's name will be the file name without its extension. So if you pass
372+
`/path/to/your/theme/file.css` as theme, then the theme's name will be `file`.
373+
371374
### `check-theme`: check if your themes implement all the required rules
372375

373376
This flag allows you to check if your themes implement the necessary CSS rules. To put it more
@@ -377,5 +380,5 @@ CSS theme.
377380
You can use this flag like this:
378381

379382
```bash
380-
$ rustdoc src/lib.rs --check-theme /path/to/your/theme/file.css
383+
$ rustdoc --check-theme /path/to/your/theme/file.css
381384
```

src/librustdoc/config.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::BTreeMap;
2+
use std::ffi::OsStr;
23
use std::fmt;
34
use std::path::PathBuf;
45

@@ -371,9 +372,14 @@ impl Options {
371372
.emit();
372373
return Err(1);
373374
}
375+
if theme_file.extension() != Some(OsStr::new("css")) {
376+
diag.struct_err(&format!("invalid file: \"{}\": expected CSS file", theme_s))
377+
.emit();
378+
return Err(1);
379+
}
374380
let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
375381
if !success {
376-
diag.struct_warn(&format!("error loading theme file: \"{}\"", theme_s)).emit();
382+
diag.struct_err(&format!("error loading theme file: \"{}\"", theme_s)).emit();
377383
return Err(1);
378384
} else if !ret.is_empty() {
379385
diag.struct_warn(&format!("theme file \"{}\" is missing CSS rules from the \

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ themePicker.onblur = handleThemeButtonsBlur;
644644
themes.appendChild(but);
645645
}});"#,
646646
themes.iter()
647-
.map(|s| format!("\"{}\"", s))
647+
.map(|s| format!("\"{}\"", s.replace("\\", "\\\\").replace("\"", "\\\"")))
648648
.collect::<Vec<String>>()
649649
.join(","));
650650
write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)),

0 commit comments

Comments
 (0)