Skip to content

Commit 947f1b6

Browse files
committed
book: Emit links to play.rust-lang.org to run examples
Had to fix a bug in `--markdown-playground-url` for markdown files in rustdoc as well as adding some necessary JS to the rustbook output as well. Closes #21553
1 parent 0f3183f commit 947f1b6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/librustdoc/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
5959
let input_str = load_or_return!(input, 1, 2);
6060
let playground = matches.opt_str("markdown-playground-url");
6161
if playground.is_some() {
62-
markdown::PLAYGROUND_KRATE.with(|s| { *s.borrow_mut() = None; });
62+
markdown::PLAYGROUND_KRATE.with(|s| { *s.borrow_mut() = Some(None); });
6363
}
6464
let playground = playground.unwrap_or("".to_string());
6565

src/rustbook/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
135135
format!("-o{}", out_path.display()),
136136
format!("--html-before-content={}", prelude.display()),
137137
format!("--html-after-content={}", postlude.display()),
138+
format!("--markdown-playground-url=http://play.rust-lang.org"),
138139
format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()),
139140
"--markdown-no-toc".to_string(),
140141
];
@@ -148,6 +149,14 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
148149

149150
// create index.html from the root README
150151
try!(fs::copy(&tgt.join("README.html"), &tgt.join("index.html")));
152+
153+
// Copy some js for playpen
154+
let mut jquery = try!(File::create(tgt.join("jquery.js")));
155+
let js = include_bytes!("../librustdoc/html/static/jquery-2.1.0.min.js");
156+
try!(jquery.write_all(js));
157+
let mut playpen = try!(File::create(tgt.join("playpen.js")));
158+
let js = include_bytes!("../librustdoc/html/static/playpen.js");
159+
try!(playpen.write_all(js));
151160
Ok(())
152161
}
153162

src/rustbook/javascript.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ document.addEventListener("DOMContentLoaded", function(event) {
7171
7272
});
7373
</script>
74+
<script type="text/javascript" src="jquery.js"></script>
75+
<script type="text/javascript" src="playpen.js"></script>
7476
"#;

0 commit comments

Comments
 (0)