2022-12-04 04:53:52 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Token<'a> {
|
|
|
|
TextElement(TextElement<'a>),
|
2022-12-16 06:35:49 +00:00
|
|
|
Paragraph(Paragraph<'a>),
|
2022-12-04 04:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Into<Token<'a>> for TextElement<'a> {
|
|
|
|
fn into(self) -> Token<'a> {
|
|
|
|
Token::TextElement(self)
|
|
|
|
}
|
|
|
|
}
|
2022-12-16 06:35:49 +00:00
|
|
|
|
|
|
|
impl<'a> Into<Token<'a>> for Paragraph<'a> {
|
|
|
|
fn into(self) -> Token<'a> {
|
|
|
|
Token::Paragraph(self)
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 08:24:35 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum TextElement<'a> {
|
|
|
|
Span(Span<'a>),
|
|
|
|
Space(Space<'a>),
|
|
|
|
LineBreak(LineBreak<'a>),
|
|
|
|
Symbol(Symbol<'a>),
|
|
|
|
Bold(Bold<'a>),
|
|
|
|
Link(Link<'a>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Span<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Space<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct LineBreak<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Symbol<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct BlankLine<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Sequence<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Bold<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Link<'a> {
|
2022-12-18 09:40:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Paragraph<'a> {
|
2022-12-18 09:30:44 +00:00
|
|
|
pub source: &'a str,
|
2022-12-18 08:24:35 +00:00
|
|
|
pub contents: Vec<TextElement<'a>>,
|
|
|
|
pub paragraph_end: &'a str,
|
|
|
|
}
|
2022-12-18 08:43:13 +00:00
|
|
|
|
|
|
|
pub trait Source<'a> {
|
|
|
|
fn get_source(&'a self) -> &'a str;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Source<'a> for TextElement<'a> {
|
|
|
|
fn get_source(&'a self) -> &'a str {
|
|
|
|
match self {
|
2022-12-18 09:40:44 +00:00
|
|
|
TextElement::Span(elem) => elem.source,
|
|
|
|
TextElement::Space(elem) => elem.source,
|
|
|
|
TextElement::LineBreak(elem) => elem.source,
|
|
|
|
TextElement::Symbol(elem) => elem.source,
|
|
|
|
TextElement::Bold(elem) => elem.source,
|
|
|
|
TextElement::Link(elem) => elem.source,
|
2022-12-18 08:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Source<'a> for Paragraph<'a> {
|
|
|
|
fn get_source(&'a self) -> &'a str {
|
2022-12-18 09:30:44 +00:00
|
|
|
self.source
|
2022-12-18 08:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-18 08:29:01 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct PlainList<'a> {
|
|
|
|
pub source: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Source<'a> for PlainList<'a> {
|
|
|
|
fn get_source(&'a self) -> &'a str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 10:02:32 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ListItem<'a> {
|
|
|
|
pub source: &'a str,
|
2023-03-17 20:37:47 +00:00
|
|
|
pub leading_whitespace: &'a str,
|
2022-12-18 12:18:42 +00:00
|
|
|
pub bullet: &'a str,
|
2022-12-18 12:40:52 +00:00
|
|
|
pub counter_set: Option<&'a str>,
|
|
|
|
pub check_box: Option<&'a str>,
|
|
|
|
pub item_tag: Option<&'a str>,
|
2022-12-18 12:18:42 +00:00
|
|
|
pub contents: Vec<TextElement<'a>>,
|
2022-12-18 10:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Source<'a> for ListItem<'a> {
|
|
|
|
fn get_source(&'a self) -> &'a str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ListCounter<'a> {
|
|
|
|
pub source: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Source<'a> for ListCounter<'a> {
|
|
|
|
fn get_source(&'a self) -> &'a str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|