Some work towards the gemtext parser
This commit is contained in:
parent
8b0af76b8f
commit
805e5cdd14
6 changed files with 141 additions and 40 deletions
|
@ -10,7 +10,10 @@ pub struct Builder<S: CertificateStore> {
|
|||
|
||||
impl<S: CertificateStore> Default for Builder<S> {
|
||||
fn default() -> Self {
|
||||
Self { stream: None, verifier: None }
|
||||
Self {
|
||||
stream: None,
|
||||
verifier: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,5 +7,4 @@ pub struct Connection {
|
|||
pub inner: rustls::ServerConnection,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
}
|
||||
impl Connection {}
|
||||
|
|
|
@ -86,9 +86,7 @@ impl MailStore for Domain {
|
|||
}
|
||||
|
||||
fn has_mailuser(&self, mailuser: &str) -> bool {
|
||||
self.users()
|
||||
.iter()
|
||||
.any(|x| x.username == mailuser)
|
||||
self.users().iter().any(|x| x.username == mailuser)
|
||||
}
|
||||
|
||||
fn get_folder(&self, user: &str, folder: &str) -> Option<Folder> {
|
||||
|
|
|
@ -27,9 +27,15 @@ impl FromStr for Link {
|
|||
return Err(super::Error::MalformedLink);
|
||||
};
|
||||
if let Some((url, display)) = s.split_once(char::is_whitespace) {
|
||||
Ok(Self { url: url.to_string(), display: Some(display.to_string()) })
|
||||
Ok(Self {
|
||||
url: url.to_string(),
|
||||
display: Some(display.to_string()),
|
||||
})
|
||||
} else {
|
||||
Ok(Self { url: s.to_string(), display: None })
|
||||
Ok(Self {
|
||||
url: s.to_string(),
|
||||
display: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,37 +21,6 @@ impl fmt::Display for Recipients {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Lines {
|
||||
Sender(Mailbox),
|
||||
Recipients(Recipients),
|
||||
Timestamp(String),
|
||||
Text(String),
|
||||
Heading1(String),
|
||||
Heading2(String),
|
||||
Heading3(String),
|
||||
Quote(String),
|
||||
Preformatted(String),
|
||||
Link(Link),
|
||||
}
|
||||
|
||||
impl fmt::Display for Lines {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Sender(m) => writeln!(f, "< {m}"),
|
||||
Self::Recipients(r) => writeln!(f, "{r}"),
|
||||
Self::Timestamp(t) => writeln!(f, "@ {t}"),
|
||||
Self::Text(t) => writeln!(f, "{t}"),
|
||||
Self::Heading1(h) => writeln!(f, "# {h}"),
|
||||
Self::Heading2(h) => writeln!(f, "## {h}"),
|
||||
Self::Heading3(h) => writeln!(f, "### {h}"),
|
||||
Self::Quote(q) => writeln!(f, "> {q}"),
|
||||
Self::Preformatted(p) => writeln!(f, "```\n{p}\n```"),
|
||||
Self::Link(l) => writeln!(f, "=> {l}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
pub struct Message {
|
||||
|
|
|
@ -1,2 +1,128 @@
|
|||
use std::fmt;
|
||||
use crate::prelude::Mailbox;
|
||||
use super::{Link, Recipients};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Parser;
|
||||
pub struct PreBlk<'a> {
|
||||
alt: Option<&'a str>,
|
||||
lines: Vec<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum State<'a> {
|
||||
Normal,
|
||||
Preformatted(PreBlk<'a>),
|
||||
Quote(Vec<&'a str>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum GemtextNode {
|
||||
Sender(Mailbox),
|
||||
Recipients(Recipients),
|
||||
Timestamp(String),
|
||||
Text(String),
|
||||
Heading1(String),
|
||||
Heading2(String),
|
||||
Heading3(String),
|
||||
Quote(String),
|
||||
Preformatted(String),
|
||||
Link(Link),
|
||||
}
|
||||
|
||||
impl fmt::Display for GemtextNode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Sender(m) => writeln!(f, "< {m}"),
|
||||
Self::Recipients(r) => writeln!(f, "{r}"),
|
||||
Self::Timestamp(t) => writeln!(f, "@ {t}"),
|
||||
Self::Text(t) => writeln!(f, "{t}"),
|
||||
Self::Heading1(h) => writeln!(f, "# {h}"),
|
||||
Self::Heading2(h) => writeln!(f, "## {h}"),
|
||||
Self::Heading3(h) => writeln!(f, "### {h}"),
|
||||
Self::Quote(q) => writeln!(f, "> {q}"),
|
||||
Self::Preformatted(p) => writeln!(f, "```\n{p}\n```"),
|
||||
Self::Link(l) => writeln!(f, "=> {l}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GemtextNode {
|
||||
fn parse_link(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_prompt(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_heading(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_list_item(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_blockquote(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_senders(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_recipients(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_timestamp(text: &'a str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Parser<'a> {
|
||||
state: State<'a>,
|
||||
lines: Vec<GemtextNode>,
|
||||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state: State::Normal,
|
||||
lines: vec![]
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(mut self, raw: &'a str) -> Vec<GemtextNode> {
|
||||
for line in raw.lines() {
|
||||
match self.state {
|
||||
State::Normal => self.parse_normal(line),
|
||||
State::Preformatted(_) => self.parse_preformatted(line),
|
||||
State::Quote(_) => self.parse_quote(line),
|
||||
}
|
||||
}
|
||||
self.lines
|
||||
}
|
||||
|
||||
fn parse_normal(&mut self, line: &'a str) {
|
||||
match line {
|
||||
s if s.starts_with("=>") => {},
|
||||
s if s.starts_with('#') => {},
|
||||
s if s.starts_with('*') => {},
|
||||
s if s.starts_with('>') => {},
|
||||
s if s.starts_with("```") => {},
|
||||
s if s.starts_with('<') => {},
|
||||
s if s.starts_with(':') => {},
|
||||
s if s.starts_with('@') => {},
|
||||
s => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_preformatted(&mut self, line: &'a str) {
|
||||
}
|
||||
|
||||
fn parse_quote(&mut self, line: &'a str) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue