diff --git a/src/lib.rs b/src/lib.rs index 107c88c..4758e8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#[derive(Debug)] +#[derive(Debug, PartialEq)] struct Url { scheme: String, user: String, @@ -10,6 +10,7 @@ struct Url { fragment: String, } +#[derive(Debug, PartialEq)] pub struct RGBA { red: u8, green: u8, @@ -17,16 +18,19 @@ pub struct RGBA { alpha: u8, } +#[derive(Debug, PartialEq)] pub struct Header { label: String, level: u8, } +#[derive(Debug, PartialEq)] pub struct CodeBlock { language: String, text: String, } +#[derive(Debug, PartialEq)] pub struct StyledText { italic: bool, bold: bool, @@ -35,17 +39,20 @@ pub struct StyledText { text: String, } +#[derive(Debug, PartialEq)] pub struct Blockquote { level: u8, text: String, } +#[derive(Debug, PartialEq)] pub struct Link { text: String, url: Url, title: Option, } +#[derive(Debug, PartialEq)] pub struct Image { text: String, image: Url, @@ -53,12 +60,14 @@ pub struct Image { link: Option, } +#[derive(Debug, PartialEq)] pub enum Node { Header(Header), Paragraph(Vec), HRule, } +#[derive(Debug, PartialEq)] pub struct Document(Vec); // TODO: able take care of lists i am too drunk for this tonight @@ -70,4 +79,40 @@ pub enum ListType { pub struct List {} -pub fn parse() {} +pub fn parse(source: &str) -> Document { + let lines = source.lines().collect::>(); + let mut document = vec![]; + let mut paragraph = vec![]; + + for line in lines { + if line.starts_with('#') { + todo!() + } else if line.is_empty() { + document.push(paragraph.join(" ")); + } else { + paragraph.push(line); + } + } + + todo!() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn basic_text() { + let text = "Hello World!"; + let doc = parse(text); + let doc_ref = Document(vec![Node::Paragraph(vec![StyledText { + italic: false, + bold: false, + underline: false, + color: None, + text: "Hello World!".to_string(), + }])]); + + assert_eq!(doc, doc_ref); + } +}