Move consuming trailing element whitespace inside the parsers.
This ensures the parsers can take into account the affiliated keywords when setting their source without needing the SetSource trait.
This commit is contained in:
@@ -21,6 +21,7 @@ use super::footnote_definition::footnote_definition;
|
||||
use super::greater_block::greater_block;
|
||||
use super::horizontal_rule::horizontal_rule;
|
||||
use super::keyword::affiliated_keyword;
|
||||
use super::keyword::affiliated_keyword_as_regular_keyword;
|
||||
use super::keyword::keyword;
|
||||
use super::latex_environment::latex_environment;
|
||||
use super::lesser_block::comment_block;
|
||||
@@ -33,8 +34,6 @@ use super::paragraph::paragraph;
|
||||
use super::plain_list::detect_plain_list;
|
||||
use super::plain_list::plain_list;
|
||||
use super::table::detect_table;
|
||||
use super::util::get_consumed;
|
||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::RefContext;
|
||||
use crate::error::CustomError;
|
||||
@@ -42,7 +41,6 @@ use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::table::org_mode_table;
|
||||
use crate::types::Element;
|
||||
use crate::types::SetSource;
|
||||
|
||||
pub(crate) const fn element(
|
||||
can_be_paragraph: bool,
|
||||
@@ -137,7 +135,10 @@ fn _element<'b, 'g, 'r, 's>(
|
||||
#[cfg(feature = "tracing")]
|
||||
let _enter = span.enter();
|
||||
|
||||
let (remain, kw) = opt(map(affiliated_keyword, Element::Keyword))(remaining)?;
|
||||
let (remain, kw) = opt(map(
|
||||
parser_with_context!(affiliated_keyword_as_regular_keyword)(context),
|
||||
Element::Keyword,
|
||||
))(remaining)?;
|
||||
if kw.is_some() {
|
||||
maybe_element = kw;
|
||||
remaining = remain;
|
||||
@@ -164,13 +165,7 @@ fn _element<'b, 'g, 'r, 's>(
|
||||
"No element.",
|
||||
))));
|
||||
}
|
||||
let mut element = maybe_element.expect("The above if-statement ensures this is Some().");
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
element.set_source(source.into());
|
||||
let element = maybe_element.expect("The above if-statement ensures this is Some().");
|
||||
|
||||
Ok((remaining, element))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user