Do not consume trailing whitespace if the parent exit matcher is matching.
This commit is contained in:
parent
895ee9f3b6
commit
1ecdd61fed
@ -19,7 +19,7 @@ use crate::parser::parser_context::ChainBehavior;
|
|||||||
use crate::parser::parser_context::ContextElement;
|
use crate::parser::parser_context::ContextElement;
|
||||||
use crate::parser::parser_context::ContextTree;
|
use crate::parser::parser_context::ContextTree;
|
||||||
use crate::parser::parser_context::ExitMatcherNode;
|
use crate::parser::parser_context::ExitMatcherNode;
|
||||||
use crate::parser::util::maybe_consume_trailing_whitespace;
|
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
|
|
||||||
use super::element::Element;
|
use super::element::Element;
|
||||||
use super::error::Res;
|
use super::error::Res;
|
||||||
@ -111,7 +111,7 @@ fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Sec
|
|||||||
|(children, _exit_contents)| !children.is_empty(),
|
|(children, _exit_contents)| !children.is_empty(),
|
||||||
)(input)?;
|
)(input)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace(context, remaining)?;
|
let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((remaining, Section { source, children }))
|
Ok((remaining, Section { source, children }))
|
||||||
|
@ -11,6 +11,7 @@ use crate::parser::util::blank_line;
|
|||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::util::maybe_consume_trailing_whitespace;
|
use crate::parser::util::maybe_consume_trailing_whitespace;
|
||||||
|
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
use crate::parser::util::start_of_line;
|
use crate::parser::util::start_of_line;
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
@ -44,7 +45,8 @@ pub fn footnote_definition<'r, 's>(
|
|||||||
let (remaining, (children, _exit_contents)) =
|
let (remaining, (children, _exit_contents)) =
|
||||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace(context, remaining)?;
|
let (remaining, _trailing_ws) =
|
||||||
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
|
@ -10,7 +10,7 @@ use crate::parser::parser_context::ExitMatcherNode;
|
|||||||
use crate::parser::parser_with_context::parser_with_context;
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::util::maybe_consume_trailing_whitespace;
|
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
use crate::parser::util::start_of_line;
|
use crate::parser::util::start_of_line;
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::bytes::complete::is_not;
|
use nom::bytes::complete::is_not;
|
||||||
@ -57,7 +57,8 @@ pub fn greater_block<'r, 's>(
|
|||||||
|
|
||||||
// Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block
|
// Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block
|
||||||
|
|
||||||
let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace(context, remaining)?;
|
let (remaining, _trailing_ws) =
|
||||||
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
let parameters = match parameters {
|
let parameters = match parameters {
|
||||||
Some((_ws, parameters)) => Some(parameters),
|
Some((_ws, parameters)) => Some(parameters),
|
||||||
|
@ -12,7 +12,7 @@ use crate::parser::parser_context::ContextElement;
|
|||||||
use crate::parser::parser_context::ExitMatcherNode;
|
use crate::parser::parser_context::ExitMatcherNode;
|
||||||
use crate::parser::parser_with_context::parser_with_context;
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::maybe_consume_trailing_whitespace;
|
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
use crate::parser::util::start_of_line;
|
use crate::parser::util::start_of_line;
|
||||||
|
|
||||||
use super::element::non_paragraph_element;
|
use super::element::non_paragraph_element;
|
||||||
@ -38,7 +38,8 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
|
|||||||
|
|
||||||
// Not checking parent exit matcher because if there are any children matched then we have a valid paragraph.
|
// Not checking parent exit matcher because if there are any children matched then we have a valid paragraph.
|
||||||
|
|
||||||
let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace(context, remaining)?;
|
let (remaining, _trailing_ws) =
|
||||||
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use super::error::Res;
|
|||||||
use super::greater_element::PlainList;
|
use super::greater_element::PlainList;
|
||||||
use super::greater_element::PlainListItem;
|
use super::greater_element::PlainListItem;
|
||||||
use super::parser_with_context::parser_with_context;
|
use super::parser_with_context::parser_with_context;
|
||||||
use super::util::maybe_consume_trailing_whitespace;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
use super::util::non_whitespace_character;
|
use super::util::non_whitespace_character;
|
||||||
use super::Context;
|
use super::Context;
|
||||||
use crate::parser::element::element;
|
use crate::parser::element::element;
|
||||||
@ -51,7 +51,8 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace(context, remaining)?;
|
let (remaining, _trailing_ws) =
|
||||||
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((remaining, PlainList { source, children }))
|
Ok((remaining, PlainList { source, children }))
|
||||||
|
@ -92,6 +92,21 @@ pub fn element_trailing_whitespace<'r, 's>(
|
|||||||
alt((eof, recognize(many0(blank_line))))(input)
|
alt((eof, recognize(many0(blank_line))))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
) -> Res<&'s str, Option<&'s str>> {
|
||||||
|
if context.should_consume_trailing_whitespace() && exit_matcher_parser(context, input).is_err()
|
||||||
|
{
|
||||||
|
Ok(opt(parser_with_context!(element_trailing_whitespace)(
|
||||||
|
context,
|
||||||
|
))(input)?)
|
||||||
|
} else {
|
||||||
|
Ok((input, None))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
pub fn maybe_consume_trailing_whitespace<'r, 's>(
|
pub fn maybe_consume_trailing_whitespace<'r, 's>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user