Populate the name field on elements.

This commit is contained in:
Tom Alexander
2023-10-04 21:21:26 -04:00
parent 5b308ea76f
commit 93fe46e4e7
15 changed files with 73 additions and 28 deletions

View File

@@ -19,6 +19,7 @@ use nom::sequence::tuple;
use super::keyword::affiliated_keyword;
use super::org_source::OrgSource;
use super::util::get_name;
use super::util::in_section;
use crate::context::parser_with_context;
use crate::context::ContextElement;
@@ -36,6 +37,7 @@ use crate::parser::util::get_consumed;
use crate::parser::util::start_of_line;
use crate::types::CenterBlock;
use crate::types::Element;
use crate::types::Keyword;
use crate::types::Paragraph;
use crate::types::QuoteBlock;
use crate::types::SetSource;
@@ -60,9 +62,9 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>(
))(remaining)?;
let name = Into::<&str>::into(name);
let (remaining, element) = match name.to_lowercase().as_str() {
"center" => center_block(context, remaining, input)?,
"quote" => quote_block(context, remaining, input)?,
_ => special_block(name)(context, remaining, input)?,
"center" => center_block(context, remaining, input, &affiliated_keywords)?,
"quote" => quote_block(context, remaining, input, &affiliated_keywords)?,
_ => special_block(name)(context, remaining, input, &affiliated_keywords)?,
};
Ok((remaining, element))
}
@@ -72,6 +74,7 @@ fn center_block<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
original_input: OrgSource<'s>,
affiliated_keywords: &Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, (source, children)) =
greater_block_body(context, input, original_input, "center", "center block")?;
@@ -79,7 +82,7 @@ fn center_block<'b, 'g, 'r, 's>(
remaining,
Element::CenterBlock(CenterBlock {
source,
name: None, // TODO
name: get_name(&affiliated_keywords),
children,
}),
))
@@ -90,6 +93,7 @@ fn quote_block<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
original_input: OrgSource<'s>,
affiliated_keywords: &Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, (source, children)) =
greater_block_body(context, input, original_input, "quote", "quote block")?;
@@ -97,7 +101,7 @@ fn quote_block<'b, 'g, 'r, 's>(
remaining,
Element::QuoteBlock(QuoteBlock {
source,
name: None, // TODO
name: get_name(&affiliated_keywords),
children,
}),
))
@@ -109,11 +113,19 @@ fn special_block<'s>(
RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>,
OrgSource<'s>,
&Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>>
+ 's {
let context_name = format!("special block {}", name);
move |context, input, original_input| {
_special_block(context, input, original_input, name, context_name.as_str())
move |context, input, original_input, affiliated_keywords| {
_special_block(
context,
input,
original_input,
name,
context_name.as_str(),
affiliated_keywords,
)
}
}
@@ -124,6 +136,7 @@ fn _special_block<'c, 'b, 'g, 'r, 's>(
original_input: OrgSource<'s>,
name: &'s str,
context_name: &'c str,
affiliated_keywords: &Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?;
let (remaining, (source, children)) =
@@ -132,7 +145,7 @@ fn _special_block<'c, 'b, 'g, 'r, 's>(
remaining,
Element::SpecialBlock(SpecialBlock {
source,
name: None, // TODO
name: get_name(&affiliated_keywords),
children,
block_type: name,
parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)),