pub fn append_after_marker(text: String, marker: &str, new_line: String) -> String {
let mut text = text;
let mut mods = text
.lines()
.filter(|line| line.starts_with(marker))
.map(|line| (text.find(line).unwrap_or(0), line))
.filter(|(_, line)| line.starts_with(marker))
.collect::<Vec<(usize, &str)>>();
mods.push((0, &new_line));
mods.sort_by(|a, b| a.1.cmp(&b.1));
let pos = mods.iter().position(|m| m.1 == &new_line).unwrap();
let pos = match mods.get(pos.saturating_add(1)) {
Some(pos) => pos.0,
None => {
let pos = pos.saturating_sub(1);
let mod_line = mods.get(pos).unwrap();
mod_line.0 + mod_line.1.len() + 1
},
};
if pos > text.len() {
text.push_str(format!("\n{}", new_line).as_str());
} else {
text.insert_str(pos, format!("{}\n", new_line).as_str());
}
text
}