Skip to content

Commit bbfd63c

Browse files
Improve documentation, add checks for themes option arguments, make sure the themes file names are js compatible
1 parent 6f2d1f5 commit bbfd63c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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

@@ -369,9 +370,14 @@ impl Options {
369370
.emit();
370371
return Err(1);
371372
}
373+
if theme_file.extension() != Some(OsStr::new("css")) {
374+
diag.struct_err(&format!("invalid file: \"{}\": expected CSS file", theme_s))
375+
.emit();
376+
return Err(1);
377+
}
372378
let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
373379
if !success {
374-
diag.struct_warn(&format!("error loading theme file: \"{}\"", theme_s)).emit();
380+
diag.struct_err(&format!("error loading theme file: \"{}\"", theme_s)).emit();
375381
return Err(1);
376382
} else if !ret.is_empty() {
377383
diag.struct_warn(&format!("theme file \"{}\" is missing CSS rules from the \

src/librustdoc/html/render.rs

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

0 commit comments

Comments
 (0)