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)
}