"#,
before = before,
classes = classes,
- after = after)
- }).into_owned()
+ after = after
+ )
+ })
+ .into_owned()
}
fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
let regex = Regex::new(r##"((?s)]?class="([^"]+)".*?>(.*?))"##).unwrap();
- regex.replace_all(html, |caps: &Captures| {
- let text = &caps[1];
- let classes = &caps[2];
- let code = &caps[3];
+ regex
+ .replace_all(html, |caps: &Captures| {
+ let text = &caps[1];
+ let classes = &caps[2];
+ let code = &caps[3];
- if (classes.contains("language-rust") && !classes.contains("ignore")) ||
- classes.contains("mdbook-runnable")
- {
- // wrap the contents in an external pre block
- if playpen_config.editable && classes.contains("editable") ||
- text.contains("fn main") || text.contains("quick_main!")
+ if (classes.contains("language-rust") && !classes.contains("ignore"))
+ || classes.contains("mdbook-runnable")
{
- format!("{}", text)
- } else {
- // we need to inject our own main
- let (attrs, code) = partition_source(code);
+ // wrap the contents in an external pre block
+ if playpen_config.editable && classes.contains("editable")
+ || text.contains("fn main") || text.contains("quick_main!")
+ {
+ format!("{}", text)
+ } else {
+ // we need to inject our own main
+ let (attrs, code) = partition_source(code);
- format!("\n# \
- #![allow(unused_variables)]\n\
- {}#fn main() {{\n\
- {}\
- #}}
",
- classes,
- attrs,
- code)
+ format!(
+ "\n# \
+ #![allow(unused_variables)]\n{}#fn main() {{\n{}#}}
",
+ classes, attrs, code
+ )
+ }
+ } else {
+ // not language-rust, so no-op
+ text.to_owned()
}
- } else {
- // not language-rust, so no-op
- text.to_owned()
- }
- }).into_owned()
+ })
+ .into_owned()
}
fn partition_source(s: &str) -> (String, String) {