",
- "
",
- "",
- "",
- "<",
- ">",
- "&",
- "'",
- """];
+ let repl_sub = vec![
+ "",
+ "",
+ "",
+ "
",
+ "",
+ "",
+ "<",
+ ">",
+ "&",
+ "'",
+ """,
+ ];
for sub in repl_sub {
id = id.replace(sub, "");
}
let id = id.chars()
- .filter_map(|c| if c.is_alphanumeric() || c == '-' || c == '_' {
+ .filter(|c| if c.is_alphanumeric() || c == '-' || c == '_')
+ .map(|c| {
if c.is_ascii() {
Some(c.to_ascii_lowercase())
} else {
@@ -383,11 +442,13 @@ fn build_header_links(html: String, filename: &str) -> String {
id
};
- format!("]+)class="([^"]+)"([^>]*)>"##).unwrap();
- regex.replace_all(&html, |caps: &Captures| {
+ regex
+ .replace_all(&html, |caps: &Captures| {
let before = &caps[1];
let classes = &caps[2].replace(",", " ");
let after = &caps[3];
@@ -434,7 +499,8 @@ fn fix_code_blocks(html: String) -> String {
fn add_playpen_pre(html: String) -> String {
let regex = Regex::new(r##"((?s)]?class="([^"]+)".*?>(.*?)
)"##).unwrap();
- regex.replace_all(&html, |caps: &Captures| {
+ regex
+ .replace_all(&html, |caps: &Captures| {
let text = &caps[1];
let classes = &caps[2];
let code = &caps[3];
@@ -447,14 +513,16 @@ fn add_playpen_pre(html: String) -> String {
} else {
// we need to inject our own main
let (attrs, code) = partition_source(code);
- format!("# #![allow(unused_variables)]
+ format!(
+ "# #![allow(unused_variables)]
{}#fn main() {{
\
{}
#}}
",
- classes,
- attrs,
- code)
+ classes,
+ attrs,
+ code
+ )
}
} else {
// not language-rust, so no-op
@@ -484,3 +552,12 @@ fn partition_source(s: &str) -> (String, String) {
(before, after)
}
+
+
+struct RenderItemContext<'a> {
+ handlebars: &'a Handlebars,
+ book: &'a MDBook,
+ destination: PathBuf,
+ data: serde_json::Map,
+ is_index: bool,
+}