From 3a2b0ea7bd8ea8ea8d8bbe54a2b493b98bd658fa Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 29 Mar 2017 15:16:06 -0400 Subject: [PATCH] Remove spans around captions as well as around filenames --- second-edition/tools/src/bin/remove_markup.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/second-edition/tools/src/bin/remove_markup.rs b/second-edition/tools/src/bin/remove_markup.rs index 8bc66f8d0..c8cbc1c18 100644 --- a/second-edition/tools/src/bin/remove_markup.rs +++ b/second-edition/tools/src/bin/remove_markup.rs @@ -31,6 +31,10 @@ fn write_md(output: String) { fn remove_markup(input: String) -> String { let filename_regex = Regex::new(r#"\A(.*)\z"#).unwrap(); + // Captions sometimes take up multiple lines + let caption_start_regex = Regex::new(r#"\A(.*)\z"#).unwrap(); + let caption_end_regex = Regex::new(r#"(.*)\z"#).unwrap(); + let regexen = vec![filename_regex, caption_start_regex, caption_end_regex]; let lines: Vec<_> = input.lines().flat_map(|line| { // Remove our figure and caption markup @@ -43,10 +47,12 @@ fn remove_markup(input: String) -> String { // Remove our syntax highlighting and rustdoc markers } else if line.starts_with("```") { Some(String::from("```")) - // Remove the span around filenames + // Remove the span around filenames and captions } else { - let result = filename_regex.replace_all(line, |caps: &Captures| { - caps.at(1).unwrap().to_owned() + let result = regexen.iter().fold(line.to_string(), |result, regex| { + regex.replace_all(&result, |caps: &Captures| { + caps.at(1).unwrap().to_owned() + }) }); Some(result) }