Add a detect object function similar to the detect element function.

This commit is contained in:
Tom Alexander
2023-09-07 02:59:08 -04:00
parent ba291c6776
commit 76a81b73ac
3 changed files with 37 additions and 2 deletions

View File

@@ -4,8 +4,11 @@ use nom::combinator::map;
use super::org_source::OrgSource;
use super::plain_text::plain_text;
use super::regular_link::regular_link;
use super::subscript_and_superscript::detect_subscript_or_superscript;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
use crate::error::Res;
use crate::parser::angle_link::angle_link;
use crate::parser::citation::citation;
@@ -165,6 +168,23 @@ pub fn any_object_except_plain_text<'b, 'g, 'r, 's>(
Ok((remaining, object))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn detect_any_object_except_plain_text<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> {
if detect_subscript_or_superscript(input).is_ok() {
return Ok((input, ()));
}
if any_object_except_plain_text(context, input).is_ok() {
return Ok((input, ()));
}
return Err(nom::Err::Error(CustomError::MyError(MyError(
"No object detected.".into(),
))));
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn regular_link_description_object_set<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,