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:
@@ -16,6 +16,7 @@ use super::keyword::affiliated_keyword;
|
||||
use super::org_source::OrgSource;
|
||||
use super::util::get_consumed;
|
||||
use super::util::get_name;
|
||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::ContextElement;
|
||||
use crate::context::ContextMatcher;
|
||||
@@ -32,9 +33,10 @@ pub(crate) fn latex_environment<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, LatexEnvironment<'s>> {
|
||||
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
start_of_line(input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
let value_start = remaining;
|
||||
start_of_line(remaining)?;
|
||||
let (remaining, _leading_whitespace) = space0(remaining)?;
|
||||
let (remaining, (_opening, name, _open_close_brace, _ws, _line_ending)) = tuple((
|
||||
tag_no_case(r#"\begin{"#),
|
||||
name,
|
||||
@@ -52,13 +54,18 @@ pub(crate) fn latex_environment<'b, 'g, 'r, 's>(
|
||||
|
||||
let (remaining, _contents) = contents(&latex_environment_end_specialized)(context, remaining)?;
|
||||
let (remaining, _end) = latex_environment_end_specialized(&parser_context, remaining)?;
|
||||
let value_end = remaining;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
let value = get_consumed(value_start, value_end);
|
||||
Ok((
|
||||
remaining,
|
||||
LatexEnvironment {
|
||||
source: source.into(),
|
||||
name: get_name(&affiliated_keywords),
|
||||
value: value.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user