Do not match text markup end with empty contents.

This commit is contained in:
Tom Alexander 2023-09-21 23:00:28 -04:00
parent b7c7057095
commit 31c782499e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 20 additions and 5 deletions

View File

@ -59,6 +59,10 @@ impl<'s> OrgSource<'s> {
self.end - self.start
}
pub(crate) fn get_byte_offset(&self) -> usize {
self.start
}
pub(crate) fn get_preceding_character(&self) -> Option<char> {
self.preceding_character
}

View File

@ -182,7 +182,7 @@ fn _text_markup_object<'b, 'g, 'r, 's, 'c>(
let (remaining, open) = tag(marker_symbol)(remaining)?;
let (remaining, _peek_not_whitespace) =
peek(verify(anychar, |c| !c.is_whitespace() && *c != '\u{200B}'))(remaining)?;
let text_markup_end_specialized = text_markup_end(open.into());
let text_markup_end_specialized = text_markup_end(open.into(), remaining.get_byte_offset());
let contexts = [
ContextElement::ContextObject(marker_symbol),
ContextElement::ExitMatcherNode(ExitMatcherNode {
@ -244,7 +244,7 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>(
let (remaining, open) = tag(marker_symbol)(remaining)?;
let (remaining, _peek_not_whitespace) =
peek(verify(anychar, |c| !c.is_whitespace() && *c != '\u{200B}'))(remaining)?;
let text_markup_end_specialized = text_markup_end(open.into());
let text_markup_end_specialized = text_markup_end(open.into(), remaining.get_byte_offset());
let contexts = [
ContextElement::ContextObject(marker_symbol),
ContextElement::ExitMatcherNode(ExitMatcherNode {
@ -315,8 +315,13 @@ fn post<'b, 'g, 'r, 's>(
Ok((remaining, ()))
}
fn text_markup_end<'c>(marker_symbol: &'c str) -> impl ContextMatcher + 'c {
move |context, input: OrgSource<'_>| _text_markup_end(context, input, marker_symbol)
fn text_markup_end<'c>(
marker_symbol: &'c str,
contents_start_offset: usize,
) -> impl ContextMatcher + 'c {
move |context, input: OrgSource<'_>| {
_text_markup_end(context, input, marker_symbol, contents_start_offset)
}
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
@ -324,7 +329,13 @@ fn _text_markup_end<'b, 'g, 'r, 's, 'c>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
marker_symbol: &'c str,
contents_start_offset: usize,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
if input.get_byte_offset() == contents_start_offset {
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Text markup cannot be empty".into(),
))));
}
not(preceded_by_whitespace(false))(input)?;
let (remaining, _marker) = terminated(
tag(marker_symbol),
@ -424,7 +435,7 @@ fn _rematch_text_markup_object<'b, 'g, 'r, 's, 'x>(
let (remaining, _) = pre(context, input)?;
let (remaining, open) = tag(marker_symbol)(remaining)?;
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
let text_markup_end_specialized = text_markup_end(open.into());
let text_markup_end_specialized = text_markup_end(open.into(), remaining.get_byte_offset());
let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Gamma,
exit_matcher: &text_markup_end_specialized,