Skip to content

Commit

Permalink
Auto merge of #37763 - liigo:rustdoc-playground, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors authored Nov 18, 2016
2 parents 509d14f + dc3859d commit 01d061f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
]
}

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 01d061f

Please sign in to comment.