Switch to getting the contents with a function to handle the escaped lines.

This commit is contained in:
Tom Alexander
2023-10-04 12:59:57 -04:00
parent b56d847cfa
commit afb43ff34f
3 changed files with 35 additions and 2 deletions

View File

@@ -237,3 +237,25 @@ impl<'s> Comment<'s> {
ret
}
}
impl<'s> ExampleBlock<'s> {
/// Get the inner contents of the ExampleBlock with the escaping commas removed.
pub fn get_contents(&self) -> String {
let mut ret = String::with_capacity(self.contents.len());
for line in self.contents.lines() {
let first_comma = line.find(",#+").or_else(|| line.find(",*"));
if let Some(first_comma) = first_comma {
let before_first_comma = &line[..first_comma];
let is_escaping_comma = before_first_comma.chars().all(char::is_whitespace);
if is_escaping_comma {
ret.push_str(&line[(first_comma + 1)..]);
} else {
ret.push_str(line);
}
} else {
ret.push_str(line);
}
}
ret
}
}