about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2019-08-21 15:48:26 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2019-11-18 16:43:48 +0100
commitbbfd63c89afe091fa9ec75bba0a5721d153d78f3 (patch)
tree8775b29dcebfd9fb546b99178e5fb794f5893690 /src
parent6f2d1f51eb43bcf555a1b3b71998eb7f18bd87de (diff)
downloadrust-bbfd63c89afe091fa9ec75bba0a5721d153d78f3.tar.gz
rust-bbfd63c89afe091fa9ec75bba0a5721d153d78f3.zip
Improve documentation, add checks for themes option arguments, make sure the themes file names are js compatible
Diffstat (limited to 'src')
-rw-r--r--src/doc/rustdoc/src/command-line-arguments.md5
-rw-r--r--src/librustdoc/config.rs8
-rw-r--r--src/librustdoc/html/render.rs2
3 files changed, 12 insertions, 3 deletions
diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md
index 5a0a8f76744..1f4584ec564 100644
--- a/src/doc/rustdoc/src/command-line-arguments.md
+++ b/src/doc/rustdoc/src/command-line-arguments.md
@@ -368,6 +368,9 @@ you'll need to use this flag as follows:
 $ rustdoc src/lib.rs --themes /path/to/your/theme/file.css
 ```
 
+Note that the theme's name will be the file name without its extension. So if you pass
+`/path/to/your/theme/file.css` as theme, then the theme's name will be `file`.
+
 ### `check-theme`: check if your themes implement all the required rules
 
 This flag allows you to check if your themes implement the necessary CSS rules. To put it more
@@ -377,5 +380,5 @@ CSS theme.
 You can use this flag like this:
 
 ```bash
-$ rustdoc src/lib.rs --check-theme /path/to/your/theme/file.css
+$ rustdoc --check-theme /path/to/your/theme/file.css
 ```
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs
index 1f7f8735465..38e0e34be61 100644
--- a/src/librustdoc/config.rs
+++ b/src/librustdoc/config.rs
@@ -1,4 +1,5 @@
 use std::collections::BTreeMap;
+use std::ffi::OsStr;
 use std::fmt;
 use std::path::PathBuf;
 
@@ -369,9 +370,14 @@ impl Options {
                         .emit();
                     return Err(1);
                 }
+                if theme_file.extension() != Some(OsStr::new("css")) {
+                    diag.struct_err(&format!("invalid file: \"{}\": expected CSS file", theme_s))
+                        .emit();
+                    return Err(1);
+                }
                 let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
                 if !success {
-                    diag.struct_warn(&format!("error loading theme file: \"{}\"", theme_s)).emit();
+                    diag.struct_err(&format!("error loading theme file: \"{}\"", theme_s)).emit();
                     return Err(1);
                 } else if !ret.is_empty() {
                     diag.struct_warn(&format!("theme file \"{}\" is missing CSS rules from the \
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 7eb49ead527..60bb159c45f 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -645,7 +645,7 @@ themePicker.onblur = handleThemeButtonsBlur;
     themes.appendChild(but);
 }});"#,
                  themes.iter()
-                       .map(|s| format!("\"{}\"", s))
+                       .map(|s| format!("\"{}\"", s.replace("\\", "\\\\").replace("\"", "\\\"")))
                        .collect::<Vec<String>>()
                        .join(","));
     write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)),