about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-11-18 01:47:01 -0800
committerGitHub <noreply@github.com>2016-11-18 01:47:01 -0800
commit01d061fdc04ed78ff65138e96c212ecc678a9f8f (patch)
tree2b5e0151b2d33853dce12c334098ec397b84268d /src
parent509d14fc70d673bd01c7721481f63cb1bc503103 (diff)
parentdc3859d73e77a34b1a61fd4f23d18651bf515b80 (diff)
downloadrust-01d061fdc04ed78ff65138e96c212ecc678a9f8f.tar.gz
rust-01d061fdc04ed78ff65138e96c212ecc678a9f8f.zip
Auto merge of #37763 - liigo:rustdoc-playground, r=alexcrichton
rustdoc: add cli argument `--playground-url`

Add a new cli argument `--playground-url` for rustdoc:

`rustdoc lib.rs --playground-url="https://play.rust-lang.org/"`

`rustdoc book.md --playground-url="https://play.rust-lang.org/"`

This makes it possible for tools like https://docs.rs to generate crate docs that can submit samples code to run at https://play.rust-lang.org, even if the crate's author *forgot* putting `#![doc(html_playground_url = "https://play.rust-lang.org/")]` to crate root. By the way, I'd like to say, many crate authors are not aware of existing of `#![doc(html_playground_url = "https://play.rust-lang.org/")]`.

`--playground-url` may be reset by `--markdown-playground-url` or `#![doc(html_playground_url=...)]`, so it's backward compatible.

@alexcrichton since you implemented playground-url related features.
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/render.rs6
-rw-r--r--src/librustdoc/lib.rs8
2 files changed, 10 insertions, 4 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 7395cc42ac5..44dadc4367b 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -467,10 +467,8 @@ pub fn run(mut krate: clean::Crate,
                 clean::NameValue(ref x, ref s)
                         if "html_playground_url" == *x => {
                     markdown::PLAYGROUND.with(|slot| {
-                        if slot.borrow().is_none() {
-                            let name = krate.name.clone();
-                            *slot.borrow_mut() = Some((Some(name), s.clone()));
-                        }
+                        let name = krate.name.clone();
+                        *slot.borrow_mut() = Some((Some(name), s.clone()));
                     });
                 }
                 clean::NameValue(ref x, ref s)
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index ee395e0616b..3af7c20c133 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -162,6 +162,10 @@ pub fn opts() -> Vec<RustcOptGroup> {
         unstable(optmulti("Z", "",
                           "internal and debugging options (only on nightly build)", "FLAG")),
         stable(optopt("", "sysroot", "Override the system root", "PATH")),
+        stable(optopt("", "playground-url",
+                      "URL to send code snippets to, may be reset by --markdown-playground-url \
+                       or `#![doc(html_playground_url=...)]`",
+                      "URL")),
     ]
 }
 
@@ -230,6 +234,10 @@ pub fn main_args(args: &[String]) -> isize {
         }
     };
 
+    if let Some(playground) = matches.opt_str("playground-url") {
+        html::markdown::PLAYGROUND.with(|s| { *s.borrow_mut() = Some((None, playground)); });
+    }
+
     let test_args = matches.opt_strs("test-args");
     let test_args: Vec<String> = test_args.iter()
                                           .flat_map(|s| s.split_whitespace())