Separate out the text markup types into their own types.

This commit is contained in:
Tom Alexander
2023-04-22 20:22:07 -04:00
parent 401fb339d0
commit d2fc8a513f
4 changed files with 131 additions and 13 deletions

View File

@@ -61,9 +61,14 @@ pub use lesser_element::Planning;
pub use lesser_element::SrcBlock;
pub use lesser_element::TableCell;
pub use lesser_element::VerseBlock;
pub use object::Bold;
pub use object::Code;
pub use object::Italic;
pub use object::Object;
pub use object::PlainText;
pub use object::RegularLink;
pub use object::TextMarkup;
pub use object::StrikeThrough;
pub use object::Underline;
pub use object::Verbatim;
pub use source::Source;
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;

View File

@@ -2,8 +2,12 @@ use super::source::Source;
#[derive(Debug)]
pub enum Object<'s> {
#[allow(dead_code)]
TextMarkup(TextMarkup<'s>),
Bold(Bold<'s>),
Italic(Italic<'s>),
Underline(Underline<'s>),
StrikeThrough(StrikeThrough<'s>),
Code(Code<'s>),
Verbatim(Verbatim<'s>),
PlainText(PlainText<'s>),
@@ -12,11 +16,41 @@ pub enum Object<'s> {
}
#[derive(Debug)]
pub struct TextMarkup<'s> {
pub struct Bold<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct Italic<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct Underline<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct StrikeThrough<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct Code<'s> {
pub source: &'s str,
pub contents: &'s str,
}
#[derive(Debug)]
pub struct Verbatim<'s> {
pub source: &'s str,
pub contents: &'s str,
}
#[derive(Debug)]
pub struct PlainText<'s> {
pub source: &'s str,
@@ -30,7 +64,12 @@ pub struct RegularLink<'s> {
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
Object::TextMarkup(obj) => obj.source,
Object::Bold(obj) => obj.source,
Object::Italic(obj) => obj.source,
Object::Underline(obj) => obj.source,
Object::StrikeThrough(obj) => obj.source,
Object::Code(obj) => obj.source,
Object::Verbatim(obj) => obj.source,
Object::PlainText(obj) => obj.source,
Object::RegularLink(obj) => obj.source,
}

View File

@@ -21,13 +21,12 @@ use crate::parser::parser_with_context::parser_with_context;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::parser::util::get_one_before;
use crate::parser::TextMarkup;
#[tracing::instrument(ret, level = "debug")]
pub fn text_markup<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, TextMarkup<'s>> {
) -> Res<&'s str, TextMarkupObject<'s>> {
let (remaining, _) = pre(context, input)?;
let (remaining, open) = marker(remaining)?;
let text_markup_end_specialized = text_markup_end(open);
@@ -51,7 +50,7 @@ pub fn text_markup<'r, 's>(
let source = get_consumed(input, remaining);
Ok((remaining, TextMarkup { source, children }))
Ok((remaining, TextMarkupObject { source, children }))
}
#[tracing::instrument(ret, level = "debug")]