diff --git a/org_mode_samples/object/text_markup/target_substring.org b/org_mode_samples/object/text_markup/target_substring.org new file mode 100644 index 00000000..25d14d7e --- /dev/null +++ b/org_mode_samples/object/text_markup/target_substring.org @@ -0,0 +1,4 @@ +# Since "foos" has an extra "s", this does not match the target. +the foos bar + +The <<>> and stuff. diff --git a/scripts/run_docker_compare.bash b/scripts/run_docker_compare.bash index e77491df..38372b99 100755 --- a/scripts/run_docker_compare.bash +++ b/scripts/run_docker_compare.bash @@ -8,7 +8,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" : ${TRACE:="NO"} # or YES to send traces to jaeger : ${BACKTRACE:="NO"} # or YES to print a rust backtrace when panicking : ${NO_COLOR:=""} # Set to anything to disable color output -: ${PROFILE:="release-lto"} +: ${PROFILE:="debug"} REALPATH=$(command -v uu-realpath || command -v realpath) MAKE=$(command -v gmake || command -v make) diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index c2dd27bb..2671675e 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -4,11 +4,13 @@ use nom::bytes::complete::tag_no_case; use nom::character::complete::anychar; use nom::character::complete::line_ending; use nom::character::complete::one_of; +use nom::combinator::eof; use nom::combinator::peek; use nom::combinator::recognize; use nom::combinator::verify; use nom::multi::many1; use nom::multi::many_till; +use nom::sequence::tuple; use super::org_source::OrgSource; use super::radio_link::RematchObject; @@ -87,11 +89,17 @@ impl<'x> RematchObject<'x> for PlainText<'x> { break; } - // let is_whitespace = recognize(many1(org_space_or_line_ending))(input); let is_not_whitespace = is_not::<&str, &str, CustomError<_>>(" \t\r\n")(goal); match is_not_whitespace { Ok((new_goal, payload)) => { - let (new_remaining, _) = tag_no_case(payload)(remaining)?; + let (new_remaining, _) = tuple(( + tag_no_case(payload), + // TODO: Test to see what the REAL condition is. Checking for not-alphabetic works fine for now, but the real criteria might be something like the plain text exit matcher. + peek(alt(( + recognize(verify(anychar, |c| !c.is_alphanumeric())), + eof, + ))), + ))(remaining)?; remaining = new_remaining; goal = new_goal; continue; diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 22762311..be549c89 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -62,6 +62,22 @@ pub(crate) fn rematch_target<'x, 'b, 'g, 'r, 's>( remaining = new_remaining; new_matches.push(new_match); } + Object::Italic(italic) => { + let (new_remaining, new_match) = italic.rematch_object(context, remaining)?; + remaining = new_remaining; + new_matches.push(new_match); + } + Object::Underline(underline) => { + let (new_remaining, new_match) = underline.rematch_object(context, remaining)?; + remaining = new_remaining; + new_matches.push(new_match); + } + Object::StrikeThrough(strikethrough) => { + let (new_remaining, new_match) = + strikethrough.rematch_object(context, remaining)?; + remaining = new_remaining; + new_matches.push(new_match); + } Object::PlainText(plaintext) => { let (new_remaining, new_match) = plaintext.rematch_object(context, remaining)?; remaining = new_remaining; diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index e9eba503..0d4f1933 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -355,6 +355,66 @@ impl<'x> RematchObject<'x> for Bold<'x> { } } +impl<'x> RematchObject<'x> for Italic<'x> { + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + fn rematch_object<'b, 'g, 'r, 's>( + &'x self, + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, + ) -> Res, Object<'s>> { + let (remaining, children) = + _rematch_text_markup_object(_context, input, "/", &self.children)?; + let source = get_consumed(input, remaining); + Ok(( + remaining, + Object::Italic(Italic { + source: source.into(), + children, + }), + )) + } +} + +impl<'x> RematchObject<'x> for Underline<'x> { + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + fn rematch_object<'b, 'g, 'r, 's>( + &'x self, + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, + ) -> Res, Object<'s>> { + let (remaining, children) = + _rematch_text_markup_object(_context, input, "_", &self.children)?; + let source = get_consumed(input, remaining); + Ok(( + remaining, + Object::Underline(Underline { + source: source.into(), + children, + }), + )) + } +} + +impl<'x> RematchObject<'x> for StrikeThrough<'x> { + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + fn rematch_object<'b, 'g, 'r, 's>( + &'x self, + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, + ) -> Res, Object<'s>> { + let (remaining, children) = + _rematch_text_markup_object(_context, input, "+", &self.children)?; + let source = get_consumed(input, remaining); + Ok(( + remaining, + Object::StrikeThrough(StrikeThrough { + source: source.into(), + children, + }), + )) + } +} + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _rematch_text_markup_object<'b, 'g, 'r, 's, 'x>( context: RefContext<'b, 'g, 'r, 's>,