pub struct Markdown(Vec); pub enum MdElement { Heading(u8, Vec), Paragraph(Vec), Code { syntax: String, content: String }, } pub enum RichText { Text(String), Bold(Box), Strike(Box), Italic(Box), Code(Box), Link(String, Vec), } impl Markdown { pub fn parse(s: &str) -> anyhow::Result { let mut c = vec![]; let mut lines = s.lines(); while let Some(line) = lines.next() { if line.starts_with("#") { let (hashes, h) = line.split_once(' ').unwrap(); c.push(MdElement::Heading(hashes.len() as u8, RichText::parse(h)?)); } else if line.starts_with("```") { todo!() } else { let mut block = line.to_string(); while let Some(line) = lines.next() { if line == "" { break; } block += line; } c.push(MdElement::Paragraph(RichText::parse(&block)?)) } } Ok(Markdown(c)) } } impl RichText { pub fn parse(s: &str) -> anyhow::Result> { let mut before = String::new(); let mut after = String::new(); let mut after_el = false; for c in s.chars() { match c { _ => {} } } Ok(segs) } }