ferencd@0: use crate::interpret_line; ferencd@0: ferencd@0: // returns true if the previous line is handled as a header, ie. this line contains only ferencd@0: // ---------- or ===========, in this case it will change the vector of lines and return true ferencd@0: pub fn handle_as_header(ip:&String, html_lines: &mut Vec, ht:usize, bold_it: &mut bool, bold:&mut bool, italic:&mut bool) -> bool { ferencd@0: let ch = ['-', '=']; ferencd@0: if only(&ip, ch[ht - 1]) { ferencd@0: let last_line:String = html_lines.last().unwrap().to_owned(); ferencd@0: let header = format_header(last_line, ht, ht, bold_it, bold, italic); ferencd@0: html_lines.pop(); ferencd@0: html_lines.push(header); ferencd@0: return true; ferencd@0: } ferencd@0: return false; ferencd@0: } ferencd@0: ferencd@0: // formats the header ferencd@0: pub fn format_header(s:String, c:usize, d:usize, bold_it:&mut bool, bold:&mut bool, italic:&mut bool) -> String { ferencd@0: let m: String = s[(c-d)..].to_string().trim().to_string(); ferencd@0: let m = interpret_line(&m, bold_it, bold, italic); ferencd@0: let nr = String::from(c.to_string()); ferencd@0: let cp = ">\n"; ferencd@0: let h:String = "\n bool ferencd@0: { ferencd@0: if s.is_empty() { ferencd@0: return false; ferencd@0: } ferencd@0: for sc in s.chars() { ferencd@0: if sc != c { ferencd@0: return false; ferencd@0: } ferencd@0: } ferencd@0: return true; ferencd@0: } ferencd@0: ferencd@0: // returns true if the line is a header line, ie. starts with a set of #'s ferencd@0: pub fn header(s:&str, c:usize) -> bool { ferencd@0: if s.starts_with( &'#'.to_string().repeat(c)) { ferencd@0: return true ferencd@0: } ferencd@0: return false ferencd@0: }