Parser - implement preformatted mode
This commit is contained in:
parent
1dd66684bf
commit
5113775933
5 changed files with 41 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
|||
use super::{Verifier, FingerPrintStore};
|
||||
use super::{FingerPrintStore, Verifier};
|
||||
use rustls::ServerConfig;
|
||||
use std::{net::TcpStream, sync::Arc};
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)]
|
||||
|
@ -20,11 +20,11 @@ impl<S: FingerPrintStore> ClientCertVerifier for Verifier<S> {
|
|||
}
|
||||
|
||||
fn verify_client_cert(
|
||||
&self,
|
||||
end_entity: &rustls::Certificate,
|
||||
intermediates: &[rustls::Certificate],
|
||||
now: std::time::SystemTime,
|
||||
) -> Result<rustls::server::ClientCertVerified, rustls::Error> {
|
||||
&self,
|
||||
end_entity: &rustls::Certificate,
|
||||
intermediates: &[rustls::Certificate],
|
||||
now: std::time::SystemTime,
|
||||
) -> Result<rustls::server::ClientCertVerified, rustls::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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!()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue