File tree 5 files changed +52
-2
lines changed
5 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -207,13 +207,15 @@ editable = false # allows editing the source code
207
207
copyable = true # include the copy button for copying code snippets
208
208
copy-js = true # includes the JavaScript for the code editor
209
209
line-numbers = false # displays line numbers for editable code
210
+ runnable = true # displays a run button for rust code
210
211
```
211
212
212
213
- ** editable:** Allow editing the source code. Defaults to ` false ` .
213
214
- ** copyable:** Display the copy button on code snippets. Defaults to ` true ` .
214
215
- ** copy-js:** Copy JavaScript files for the editor to the output directory.
215
216
Defaults to ` true ` .
216
217
- ** line-numbers** Display line numbers on editable sections of code. Requires both ` editable ` and ` copy-js ` to be ` true ` . Defaults to ` false ` .
218
+ - ** runnable** Displays a run button for rust code snippets. Changing this to ` false ` will disable the run in playground feature globally. Defaults to ` true ` .
217
219
218
220
[ Ace ] : https://ace.c9.io/
219
221
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ println!("Hello, World!");
41
41
42
42
If there is no ` main ` function, then the code is automatically wrapped inside one.
43
43
44
- If you wish to disable the play button, you can include the ` noplayground ` option on the code block like this:
44
+ If you wish to disable the play button for a code block , you can include the ` noplayground ` option on the code block like this:
45
45
46
46
~~~ markdown
47
47
```rust,noplayground
@@ -51,6 +51,13 @@ println!("Hello {}!", name);
51
51
```
52
52
~~~
53
53
54
+ Or, if you wish to disable the play button for all code blocks in your book, you can write the config to the ` book.toml ` like this.
55
+
56
+ ``` toml
57
+ [output .html .playground ]
58
+ runnable = false
59
+ ```
60
+
54
61
## Rust code block attributes
55
62
56
63
Additional attributes can be included in Rust code blocks with comma, space, or tab-separated terms just after the language term. For example:
Original file line number Diff line number Diff line change @@ -630,6 +630,8 @@ pub struct Playground {
630
630
pub copy_js : bool ,
631
631
/// Display line numbers on playground snippets. Default: `false`.
632
632
pub line_numbers : bool ,
633
+ /// Display the run button. Default: `true`
634
+ pub runnable : bool ,
633
635
}
634
636
635
637
impl Default for Playground {
@@ -639,6 +641,7 @@ impl Default for Playground {
639
641
copyable : true ,
640
642
copy_js : true ,
641
643
line_numbers : false ,
644
+ runnable : true ,
642
645
}
643
646
}
644
647
}
@@ -781,6 +784,7 @@ mod tests {
781
784
copyable : true ,
782
785
copy_js : true ,
783
786
line_numbers : false ,
787
+ runnable : true ,
784
788
} ;
785
789
let html_should_be = HtmlConfig {
786
790
curly_quotes : true ,
@@ -811,6 +815,22 @@ mod tests {
811
815
assert_eq ! ( got. html_config( ) . unwrap( ) , html_should_be) ;
812
816
}
813
817
818
+ #[ test]
819
+ fn disable_runnable ( ) {
820
+ let src = r#"
821
+ [book]
822
+ title = "Some Book"
823
+ description = "book book book"
824
+ authors = ["Shogo Takata"]
825
+
826
+ [output.html.playground]
827
+ runnable = false
828
+ "# ;
829
+
830
+ let got = Config :: from_str ( src) . unwrap ( ) ;
831
+ assert_eq ! ( got. html_config( ) . unwrap( ) . playground. runnable, false ) ;
832
+ }
833
+
814
834
#[ test]
815
835
fn edition_2015 ( ) {
816
836
let src = r#"
Original file line number Diff line number Diff line change @@ -828,7 +828,8 @@ fn add_playground_pre(
828
828
if classes. contains ( "language-rust" ) {
829
829
if ( !classes. contains ( "ignore" )
830
830
&& !classes. contains ( "noplayground" )
831
- && !classes. contains ( "noplaypen" ) )
831
+ && !classes. contains ( "noplaypen" )
832
+ && playground_config. runnable )
832
833
|| classes. contains ( "mdbook-runnable" )
833
834
{
834
835
let contains_e2015 = classes. contains ( "edition2015" ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ use std::ffi::OsStr;
17
17
use std:: fs;
18
18
use std:: io:: Write ;
19
19
use std:: path:: { Component , Path , PathBuf } ;
20
+ use std:: str:: FromStr ;
20
21
use tempfile:: Builder as TempFileBuilder ;
21
22
use walkdir:: { DirEntry , WalkDir } ;
22
23
@@ -150,6 +151,25 @@ fn rendered_code_has_playground_stuff() {
150
151
assert_contains_strings ( book_js, & [ ".playground" ] ) ;
151
152
}
152
153
154
+ #[ test]
155
+ fn rendered_code_does_not_have_playground_stuff_in_html_when_disabled_in_config ( ) {
156
+ let temp = DummyBook :: new ( ) . build ( ) . unwrap ( ) ;
157
+ let config = Config :: from_str (
158
+ "
159
+ [output.html.playground]
160
+ runnable = false
161
+ " ,
162
+ )
163
+ . unwrap ( ) ;
164
+ let md = MDBook :: load_with_config ( temp. path ( ) , config) . unwrap ( ) ;
165
+ md. build ( ) . unwrap ( ) ;
166
+
167
+ let nested = temp. path ( ) . join ( "book/first/nested.html" ) ;
168
+ let playground_class = vec ! [ r#"class="playground""# ] ;
169
+
170
+ assert_doesnt_contain_strings ( nested, & playground_class) ;
171
+ }
172
+
153
173
#[ test]
154
174
fn anchors_include_text_between_but_not_anchor_comments ( ) {
155
175
let temp = DummyBook :: new ( ) . build ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments