mirror of
https://github.com/rust-lang/book.git
synced 2026-09-14 00:34:47 -04:00
Remove spans around captions as well as around filenames
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user