Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: add cli argument --playground-url #37763

Merged
merged 1 commit into from
Nov 18, 2016

Conversation

liigo
Copy link
Contributor

@liigo liigo commented Nov 14, 2016

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.

@rust-highfive
Copy link
Collaborator

r? @steveklabnik

(rust_highfive has picked a reviewer for you, use r? to override)

@brson brson added the T-tools label Nov 15, 2016
@brson
Copy link
Contributor

brson commented Nov 15, 2016

Seems like a reasonable feature to me.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Nov 16, 2016

📌 Commit dc3859d has been approved by alexcrichton

Copy link
Member

@ollie27 ollie27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need two command line options which do the same thing for Markdown rendering?

I can envision having a --html-playground-url as an alternative to #![doc(html_playground_url)] but it's not clear to me what should happen if both are set. What's proposed here is one option but for the use case of websites like docs.rs surely you would want to override whatever was set by #![doc(html_playground_url)].

Shouldn't we be a bit more careful before adding new stable command line options to rustdoc?

Either way this could do with tests.

@@ -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)); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When doing HTML rendering the crate name needs to be set so the correct extern crate can be added to the code. The first item in the tuple is the crate name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do that in follow up PR, thanks @ollie27 !

@liigo
Copy link
Contributor Author

liigo commented Nov 17, 2016

Do we really need two command line options which do the same thing for Markdown rendering?

existing --markdown-playground-url may be deprecated in the future. --playground-url is reasonable for both Html and Markdown rendering.

surely you would want to override whatever was set by #![doc(html_playground_url)]

That'd be a breaking change?

@bors
Copy link
Contributor

bors commented Nov 18, 2016

⌛ Testing commit dc3859d with merge 01d061f...

bors added a commit that referenced this pull request Nov 18, 2016
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.
@bors bors merged commit dc3859d into rust-lang:master Nov 18, 2016
@liigo liigo deleted the rustdoc-playground branch November 21, 2016 08:21
liigo added a commit to liigo/rust that referenced this pull request Nov 30, 2016
bors added a commit that referenced this pull request Dec 1, 2016
rustdoc: get back missing crate-name when --playground-url is used

follow up PR #37763
r? @alexcrichton (since you r+ed to #37763 )

----

Edit: When `#![doc(html_playground_url="")]` is used, the current crate name is saved to `PLAYGROUND`, so rustdoc may generate `extern crate NAME;` into code snips automatically. But when `--playground-url` was introduced in PR #37763, I forgot saving crate name to `PLAYGROUND`. This PR fix that.

----

Update:
- add test
- unstable `--playground-url`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants