Separate out the text markup types into their own types.
This commit is contained in:
@@ -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>;
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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")]
|
||||
|
||||
Reference in New Issue
Block a user