From faff343baf40dd5163b7a04a397755572302a447 Mon Sep 17 00:00:00 2001 From: sam lovelace Date: Sun, 28 Nov 2021 03:40:18 +0000 Subject: [PATCH 1/2] fixed stupid shit --- src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2ca2b65..b2dd46b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,6 @@ pub struct Blockquote { text: String, } -<<<<<<< HEAD pub struct Link { text: String, url: Url, @@ -43,7 +42,6 @@ pub struct Image { title: Option, link: Option, } -======= pub enum Node { Header(Header), Paragraph(Vec), @@ -51,7 +49,6 @@ pub enum Node { } pub struct Document(Vec); ->>>>>>> d808ae46ad469d6024e76ad006f7b3e0832fe8cb // TODO: able take care of lists i am too drunk for this tonight From 3e8ea9f57798d50ef001492c68d9942c217ac9fc Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Sat, 27 Nov 2021 21:01:38 -0700 Subject: [PATCH 2/2] Add one failing test :) --- src/lib.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b2dd46b..782a346 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ +#[derive(Debug, PartialEq)] pub struct Url; +#[derive(Debug, PartialEq)] pub struct RGBA { red: u8, green: u8, @@ -7,16 +9,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, @@ -25,29 +30,35 @@ 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, title: Option, 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 @@ -59,4 +70,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); + } +}