Parser - implement preformatted mode

This commit is contained in:
Nathan Fisher 2023-06-02 10:27:45 -04:00
parent 1dd66684bf
commit 5113775933
5 changed files with 41 additions and 16 deletions

View file

@ -1,4 +1,4 @@
use super::{Verifier, FingerPrintStore};
use super::{FingerPrintStore, Verifier};
use rustls::ServerConfig;
use std::{net::TcpStream, sync::Arc};

View file

@ -2,7 +2,11 @@ pub mod builder;
pub mod error;
pub mod verifier;
pub use self::{builder::Builder, error::Error, verifier::{FingerPrintStore, Verifier}};
pub use self::{
builder::Builder,
error::Error,
verifier::{FingerPrintStore, Verifier},
};
#[derive(Debug)]
pub struct Connection {

View file

@ -1,6 +1,6 @@
use rustls::server::ClientCertVerifier;
use crate::{prelude::CertificateStore, mailuser::Mailuser};
use crate::{mailuser::Mailuser, prelude::CertificateStore};
use std::sync::Mutex;
#[derive(Debug)]

View file

@ -7,7 +7,11 @@ use serde::{Deserialize, Serialize};
mod error;
mod link;
mod parser;
pub use {error::Error, link::Link, parser::{GemtextNode, Parser}};
pub use {
error::Error,
link::Link,
parser::{GemtextNode, Parser},
};
#[derive(Clone, Debug, PartialEq)]
pub struct Recipients {

View file

@ -1,6 +1,6 @@
use std::fmt;
use crate::prelude::Mailbox;
use super::{Link, Recipients};
use crate::prelude::Mailbox;
use std::fmt;
#[derive(Debug)]
pub struct PreBlk<'a> {
@ -121,7 +121,7 @@ impl<'a> Parser<'a> {
Self {
state: State::Normal,
title: None,
lines: vec![]
lines: vec![],
}
}
@ -145,7 +145,7 @@ impl<'a> Parser<'a> {
if self.title.is_none() {
match &line {
GemtextNode::Heading1(t) => self.title = Some(t.clone()),
_ => {},
_ => {}
}
}
self.lines.push(line);
@ -172,6 +172,17 @@ impl<'a> Parser<'a> {
self.state = State::Preformatted(preblk);
}
fn leave_preformatted(&mut self) {
match &self.state {
State::Preformatted(v) => {
let s = v.lines.join("\n").to_string();
self.lines.push(GemtextNode::Text(s));
self.state = State::Normal;
}
_ => panic!("Attempted to leave preformatted mode when not in preformatted mode"),
}
}
fn senders(&mut self, line: &'a str) {
self.lines.push(GemtextNode::parse_senders(line));
}
@ -190,16 +201,22 @@ impl<'a> Parser<'a> {
s if s.starts_with('<') => self.senders(s),
s if s.starts_with(':') => self.recipients(s),
s if s.starts_with('@') => {},
s => {},
s => self.lines.push(GemtextNode::Text(s.to_string())),
}
}
fn parse_preformatted(&mut self, line: &'a str) {
todo!()
if line.starts_with("```") {
self.leave_preformatted();
} else {
match &mut self.state {
State::Preformatted(p) => p.lines.push(line),
_ => panic!("Attempt to parse as preformatted when not in preformatted mode"),
}
}
}
fn parse_quote(&mut self, line: &'a str) {
todo!()
}
}