2022-12-03 23:53:52 -05:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Token<'a> {
|
|
|
|
TextElement(TextElement<'a>),
|
2022-12-16 01:35:49 -05:00
|
|
|
Paragraph(Paragraph<'a>),
|
2022-12-03 23:53:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Into<Token<'a>> for TextElement<'a> {
|
|
|
|
fn into(self) -> Token<'a> {
|
|
|
|
Token::TextElement(self)
|
|
|
|
}
|
|
|
|
}
|
2022-12-16 01:35:49 -05:00
|
|
|
|
|
|
|
impl<'a> Into<Token<'a>> for Paragraph<'a> {
|
|
|
|
fn into(self) -> Token<'a> {
|
|
|
|
Token::Paragraph(self)
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 03:24:35 -05: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 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Space<'a> {
|
2022-12-18 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct LineBreak<'a> {
|
2022-12-18 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Symbol<'a> {
|
2022-12-18 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct BlankLine<'a> {
|
2022-12-18 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Sequence<'a> {
|
2022-12-18 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Bold<'a> {
|
2022-12-18 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Link<'a> {
|
2022-12-18 04:40:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Paragraph<'a> {
|
2022-12-18 04:30:44 -05:00
|
|
|
pub source: &'a str,
|
2022-12-18 03:24:35 -05:00
|
|
|
pub contents: Vec<TextElement<'a>>,
|
|
|
|
pub paragraph_end: &'a str,
|
|
|
|
}
|
2022-12-18 03:43:13 -05: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 04:40:44 -05: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 03:43:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Source<'a> for Paragraph<'a> {
|
|
|
|
fn get_source(&'a self) -> &'a str {
|
2022-12-18 04:30:44 -05:00
|
|
|
self.source
|
2022-12-18 03:43:13 -05:00
|
|
|
}
|
|
|
|
}
|
2022-12-18 03:29:01 -05: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 05:02:32 -05:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ListItem<'a> {
|
|
|
|
pub source: &'a str,
|
2023-03-17 16:37:47 -04:00
|
|
|
pub leading_whitespace: &'a str,
|
2022-12-18 07:18:42 -05:00
|
|
|
pub bullet: &'a str,
|
2022-12-18 07:40:52 -05:00
|
|
|
pub counter_set: Option<&'a str>,
|
|
|
|
pub check_box: Option<&'a str>,
|
|
|
|
pub item_tag: Option<&'a str>,
|
2022-12-18 07:18:42 -05:00
|
|
|
pub contents: Vec<TextElement<'a>>,
|
2022-12-18 05:02:32 -05: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
|
|
|
|
}
|
|
|
|
}
|