Apply a similar optimization to the detect element parser but also unify detection of affiliated keywords.
This commit is contained in:
@@ -273,23 +273,60 @@ fn _detect_element<'b, 'g, 'r, 's>(
|
||||
input: OrgSource<'s>,
|
||||
can_be_paragraph: bool,
|
||||
) -> Res<OrgSource<'s>, ()> {
|
||||
// TODO: unify parsing of affiliated keywords like we did for the element parser.
|
||||
if alt((
|
||||
parser_with_context!(detect_plain_list)(context),
|
||||
parser_with_context!(detect_footnote_definition)(context),
|
||||
parser_with_context!(detect_diary_sexp)(context),
|
||||
detect_comment,
|
||||
parser_with_context!(detect_fixed_width_area)(context),
|
||||
parser_with_context!(detect_table)(context),
|
||||
))(input)
|
||||
.is_ok()
|
||||
{
|
||||
let (post_affiliated_keywords_input, affiliated_keywords) =
|
||||
many0(parser_with_context!(affiliated_keyword)(context))(input)?;
|
||||
|
||||
let mut affiliated_keywords = affiliated_keywords.into_iter();
|
||||
|
||||
ak_element!(
|
||||
detect_plain_list,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input
|
||||
);
|
||||
|
||||
ak_element!(
|
||||
detect_footnote_definition,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input
|
||||
);
|
||||
|
||||
ak_element!(
|
||||
detect_diary_sexp,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input
|
||||
);
|
||||
|
||||
if let Ok((_, _)) = detect_comment(input) {
|
||||
return Ok((input, ()));
|
||||
}
|
||||
|
||||
ak_element!(
|
||||
detect_fixed_width_area,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input
|
||||
);
|
||||
|
||||
ak_element!(
|
||||
detect_table,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input
|
||||
);
|
||||
|
||||
if _element(context, input, can_be_paragraph).is_ok() {
|
||||
return Ok((input, ()));
|
||||
}
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
|
||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"No element detected.".into(),
|
||||
))));
|
||||
))))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user