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 rustls::ServerConfig;
use std::{net::TcpStream, sync::Arc}; use std::{net::TcpStream, sync::Arc};

View file

@ -2,7 +2,11 @@ pub mod builder;
pub mod error; pub mod error;
pub mod verifier; 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)] #[derive(Debug)]
pub struct Connection { pub struct Connection {

View file

@ -1,6 +1,6 @@
use rustls::server::ClientCertVerifier; use rustls::server::ClientCertVerifier;
use crate::{prelude::CertificateStore, mailuser::Mailuser}; use crate::{mailuser::Mailuser, prelude::CertificateStore};
use std::sync::Mutex; use std::sync::Mutex;
#[derive(Debug)] #[derive(Debug)]
@ -20,11 +20,11 @@ impl<S: FingerPrintStore> ClientCertVerifier for Verifier<S> {
} }
fn verify_client_cert( fn verify_client_cert(
&self, &self,
end_entity: &rustls::Certificate, end_entity: &rustls::Certificate,
intermediates: &[rustls::Certificate], intermediates: &[rustls::Certificate],
now: std::time::SystemTime, now: std::time::SystemTime,
) -> Result<rustls::server::ClientCertVerified, rustls::Error> { ) -> Result<rustls::server::ClientCertVerified, rustls::Error> {
todo!() todo!()
} }
} }

View file

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

View file

@ -1,6 +1,6 @@
use std::fmt;
use crate::prelude::Mailbox;
use super::{Link, Recipients}; use super::{Link, Recipients};
use crate::prelude::Mailbox;
use std::fmt;
#[derive(Debug)] #[derive(Debug)]
pub struct PreBlk<'a> { pub struct PreBlk<'a> {
@ -121,7 +121,7 @@ impl<'a> Parser<'a> {
Self { Self {
state: State::Normal, state: State::Normal,
title: None, title: None,
lines: vec![] lines: vec![],
} }
} }
@ -145,7 +145,7 @@ impl<'a> Parser<'a> {
if self.title.is_none() { if self.title.is_none() {
match &line { match &line {
GemtextNode::Heading1(t) => self.title = Some(t.clone()), GemtextNode::Heading1(t) => self.title = Some(t.clone()),
_ => {}, _ => {}
} }
} }
self.lines.push(line); self.lines.push(line);
@ -172,6 +172,17 @@ impl<'a> Parser<'a> {
self.state = State::Preformatted(preblk); 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) { fn senders(&mut self, line: &'a str) {
self.lines.push(GemtextNode::parse_senders(line)); 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.senders(s),
s if s.starts_with(':') => self.recipients(s), s if s.starts_with(':') => self.recipients(s),
s if s.starts_with('@') => {}, s if s.starts_with('@') => {},
s => {}, s => self.lines.push(GemtextNode::Text(s.to_string())),
} }
} }
fn parse_preformatted(&mut self, line: &'a str) { 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) { fn parse_quote(&mut self, line: &'a str) {
todo!() todo!()
} }
} }