rustdoc: Submit examples to play.rust-lang.org
This grows a new option inside of rustdoc to add the ability to submit examples to an external website. If the `--markdown-playground-url` command line option or crate doc attribute `html_playground_url` is present, then examples will have a button on hover to submit the code to the playground specified. This commit enables submission of example code to play.rust-lang.org. The code submitted is that which is tested by rustdoc, not necessarily the exact code shown in the example. Closes #14654
This commit is contained in:
parent
cc63d4c61b
commit
e5bbbca33e
29 changed files with 186 additions and 43 deletions
|
@ -230,6 +230,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
|||
logo: "".to_string(),
|
||||
favicon: "".to_string(),
|
||||
krate: krate.name.clone(),
|
||||
playground_url: "".to_string(),
|
||||
},
|
||||
include_sources: true,
|
||||
render_redirect_pages: false,
|
||||
|
@ -250,6 +251,14 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
|||
if "html_logo_url" == x.as_slice() => {
|
||||
cx.layout.logo = s.to_string();
|
||||
}
|
||||
clean::NameValue(ref x, ref s)
|
||||
if "html_playground_url" == x.as_slice() => {
|
||||
cx.layout.playground_url = s.to_string();
|
||||
let name = krate.name.clone();
|
||||
if markdown::playground_krate.get().is_none() {
|
||||
markdown::playground_krate.replace(Some(Some(name)));
|
||||
}
|
||||
}
|
||||
clean::Word(ref x)
|
||||
if "html_no_source" == x.as_slice() => {
|
||||
cx.include_sources = false;
|
||||
|
@ -450,6 +459,7 @@ fn write_shared(cx: &Context,
|
|||
try!(write(cx.dst.join("jquery.js"),
|
||||
include_bin!("static/jquery-2.1.0.min.js")));
|
||||
try!(write(cx.dst.join("main.js"), include_bin!("static/main.js")));
|
||||
try!(write(cx.dst.join("playpen.js"), include_bin!("static/playpen.js")));
|
||||
try!(write(cx.dst.join("main.css"), include_bin!("static/main.css")));
|
||||
try!(write(cx.dst.join("normalize.css"),
|
||||
include_bin!("static/normalize.css")));
|
||||
|
@ -2055,14 +2065,15 @@ impl<'a> fmt::Show for Source<'a> {
|
|||
try!(write!(fmt, "<span id='{0:u}'>{0:1$u}</span>\n", i, cols));
|
||||
}
|
||||
try!(write!(fmt, "</pre>"));
|
||||
try!(write!(fmt, "{}", highlight::highlight(s.as_slice(), None)));
|
||||
try!(write!(fmt, "{}", highlight::highlight(s.as_slice(), None, None)));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn item_macro(w: &mut fmt::Formatter, it: &clean::Item,
|
||||
t: &clean::Macro) -> fmt::Result {
|
||||
try!(w.write(highlight::highlight(t.source.as_slice(), Some("macro")).as_bytes()));
|
||||
try!(w.write(highlight::highlight(t.source.as_slice(), Some("macro"),
|
||||
None).as_bytes()));
|
||||
document(w, it)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue