Merge branch 'issue1' of ssh://git.ablecorp.us:20/Mesh/meshup into issue1

This commit is contained in:
Able 2021-11-27 22:03:56 -06:00
commit 622fd3fba5

View file

@ -1,4 +1,4 @@
#[derive(Debug)] #[derive(Debug, PartialEq)]
struct Url { struct Url {
scheme: String, scheme: String,
user: String, user: String,
@ -10,6 +10,7 @@ struct Url {
fragment: String, fragment: String,
} }
#[derive(Debug, PartialEq)]
pub struct RGBA { pub struct RGBA {
red: u8, red: u8,
green: u8, green: u8,
@ -17,16 +18,19 @@ pub struct RGBA {
alpha: u8, alpha: u8,
} }
#[derive(Debug, PartialEq)]
pub struct Header { pub struct Header {
label: String, label: String,
level: u8, level: u8,
} }
#[derive(Debug, PartialEq)]
pub struct CodeBlock { pub struct CodeBlock {
language: String, language: String,
text: String, text: String,
} }
#[derive(Debug, PartialEq)]
pub struct StyledText { pub struct StyledText {
italic: bool, italic: bool,
bold: bool, bold: bool,
@ -35,17 +39,20 @@ pub struct StyledText {
text: String, text: String,
} }
#[derive(Debug, PartialEq)]
pub struct Blockquote { pub struct Blockquote {
level: u8, level: u8,
text: String, text: String,
} }
#[derive(Debug, PartialEq)]
pub struct Link { pub struct Link {
text: String, text: String,
url: Url, url: Url,
title: Option<String>, title: Option<String>,
} }
#[derive(Debug, PartialEq)]
pub struct Image { pub struct Image {
text: String, text: String,
image: Url, image: Url,
@ -53,12 +60,14 @@ pub struct Image {
link: Option<Link>, link: Option<Link>,
} }
#[derive(Debug, PartialEq)]
pub enum Node { pub enum Node {
Header(Header), Header(Header),
Paragraph(Vec<StyledText>), Paragraph(Vec<StyledText>),
HRule, HRule,
} }
#[derive(Debug, PartialEq)]
pub struct Document(Vec<Node>); pub struct Document(Vec<Node>);
// TODO: able take care of lists i am too drunk for this tonight // TODO: able take care of lists i am too drunk for this tonight
@ -70,4 +79,40 @@ pub enum ListType {
pub struct List {} pub struct List {}
pub fn parse() {} pub fn parse(source: &str) -> Document {
let lines = source.lines().collect::<Vec<_>>();
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);
}
}