Remove spans around captions as well as around filenames

This commit is contained in:
Carol (Nichols || Goulding)
2017-03-29 15:16:06 -04:00
parent 22dcb1da61
commit 3a2b0ea7bd

View File

@@ -31,6 +31,10 @@ fn write_md(output: String) {
fn remove_markup(input: String) -> String {
let filename_regex = Regex::new(r#"\A<span class="filename">(.*)</span>\z"#).unwrap();
// Captions sometimes take up multiple lines
let caption_start_regex = Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
let caption_end_regex = Regex::new(r#"(.*)</span>\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)
}