Skip to content

Commit 01d061f

Browse files
authored
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.
2 parents 509d14f + dc3859d commit 01d061f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/librustdoc/html/render.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,8 @@ pub fn run(mut krate: clean::Crate,
467467
clean::NameValue(ref x, ref s)
468468
if "html_playground_url" == *x => {
469469
markdown::PLAYGROUND.with(|slot| {
470-
if slot.borrow().is_none() {
471-
let name = krate.name.clone();
472-
*slot.borrow_mut() = Some((Some(name), s.clone()));
473-
}
470+
let name = krate.name.clone();
471+
*slot.borrow_mut() = Some((Some(name), s.clone()));
474472
});
475473
}
476474
clean::NameValue(ref x, ref s)

src/librustdoc/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ pub fn opts() -> Vec<RustcOptGroup> {
162162
unstable(optmulti("Z", "",
163163
"internal and debugging options (only on nightly build)", "FLAG")),
164164
stable(optopt("", "sysroot", "Override the system root", "PATH")),
165+
stable(optopt("", "playground-url",
166+
"URL to send code snippets to, may be reset by --markdown-playground-url \
167+
or `#![doc(html_playground_url=...)]`",
168+
"URL")),
165169
]
166170
}
167171

@@ -230,6 +234,10 @@ pub fn main_args(args: &[String]) -> isize {
230234
}
231235
};
232236

237+
if let Some(playground) = matches.opt_str("playground-url") {
238+
html::markdown::PLAYGROUND.with(|s| { *s.borrow_mut() = Some((None, playground)); });
239+
}
240+
233241
let test_args = matches.opt_strs("test-args");
234242
let test_args: Vec<String> = test_args.iter()
235243
.flat_map(|s| s.split_whitespace())

0 commit comments

Comments
 (0)