Skip to content

Commit e5bbbca

Browse files
committed
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
1 parent cc63d4c commit e5bbbca

File tree

29 files changed

+186
-43
lines changed

29 files changed

+186
-43
lines changed

mk/docs.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ L10N_LANGS := ja
4343

4444
# The options are passed to the documentation generators.
4545
RUSTDOC_HTML_OPTS_NO_CSS = --markdown-before-content=doc/version_info.html \
46-
--markdown-in-header=doc/favicon.inc --markdown-after-content=doc/footer.inc
46+
--markdown-in-header=doc/favicon.inc \
47+
--markdown-after-content=doc/footer.inc \
48+
--markdown-playground-url='http://play.rust-lang.org/'
4749

4850
RUSTDOC_HTML_OPTS = $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css rust.css
4951

src/doc/footer.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ or the <a href="http://opensource.org/licenses/MIT">MIT license</a>, at your opt
55
</p><p>
66
This file may not be copied, modified, or distributed except according to those terms.
77
</p></footer>
8+
<script type="text/javascript" src="jquery.js"></script>
9+
<script type="text/javascript" src="playpen.js"></script>

src/doc/rust.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ table th {
313313
padding: 5px;
314314
}
315315

316+
/* Code snippets */
317+
318+
.rusttest { display: none; }
319+
pre.rust { position: relative; }
320+
pre.rust a { transform: scaleX(-1); }
321+
.test-arrow {
322+
display: inline-block;
323+
position: absolute;
324+
top: 0;
325+
right: 10px;
326+
font-size: 150%;
327+
}
328+
316329
@media (min-width: 1170px) {
317330
pre {
318331
font-size: 15px;

src/libcollections/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#![license = "MIT/ASL2"]
1818
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
1919
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
20-
html_root_url = "http://doc.rust-lang.org/")]
20+
html_root_url = "http://doc.rust-lang.org/",
21+
html_playground_url = "http://play.rust-lang.org/")]
2122

2223
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
2324
#![no_std]

src/libcore/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
#![crate_type = "rlib"]
5151
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
5252
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
53-
html_root_url = "http://doc.rust-lang.org/")]
53+
html_root_url = "http://doc.rust-lang.org/",
54+
html_playground_url = "http://play.rust-lang.org/")]
5455

5556
#![no_std]
5657
#![feature(globs, macro_rules, managed_boxes, phase, simd)]

src/libgetopts/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
#![license = "MIT/ASL2"]
8585
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
8686
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
87-
html_root_url = "http://doc.rust-lang.org/")]
87+
html_root_url = "http://doc.rust-lang.org/",
88+
html_playground_url = "http://play.rust-lang.org/")]
8889
#![feature(globs, phase)]
8990
#![deny(missing_doc)]
9091
#![deny(deprecated_owned_vector)]

src/libglob/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#![license = "MIT/ASL2"]
3030
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
3131
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
32-
html_root_url = "http://doc.rust-lang.org/")]
33-
32+
html_root_url = "http://doc.rust-lang.org/",
33+
html_playground_url = "http://play.rust-lang.org/")]
3434
#![deny(deprecated_owned_vector)]
3535

3636
use std::cell::Cell;

src/libgreen/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@
203203
#![crate_type = "dylib"]
204204
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
205205
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
206-
html_root_url = "http://doc.rust-lang.org/")]
206+
html_root_url = "http://doc.rust-lang.org/",
207+
html_playground_url = "http://play.rust-lang.org/")]
207208

208209
// NB this does *not* include globs, please keep it that way.
209210
#![feature(macro_rules, phase)]

src/liblog/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ if logging is disabled, none of the components of the log will be executed.
111111
#![crate_type = "dylib"]
112112
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
113113
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
114-
html_root_url = "http://doc.rust-lang.org/")]
114+
html_root_url = "http://doc.rust-lang.org/",
115+
html_playground_url = "http://play.rust-lang.org/")]
115116

116117
#![feature(macro_rules)]
117118
#![deny(missing_doc, deprecated_owned_vector)]

src/libnum/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
#![license = "MIT/ASL2"]
5151
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
5252
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
53-
html_root_url = "http://doc.rust-lang.org/")]
53+
html_root_url = "http://doc.rust-lang.org/",
54+
html_playground_url = "http://play.rust-lang.org/")]
5455

5556
#![deny(deprecated_owned_vector)]
5657

0 commit comments

Comments
 (0)