Do not allow '<' as a pre-character for text-markup but do allow start of file.

This commit is contained in:
Tom Alexander
2023-09-16 14:06:31 -04:00
parent 36bdc54703
commit bdd04f4d5c
2 changed files with 54 additions and 31 deletions

View File

@@ -20,6 +20,7 @@ use super::org_source::OrgSource;
use super::radio_link::RematchObject;
use super::util::in_object_section;
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
use super::util::start_of_line;
use crate::context::parser_with_context;
use crate::context::ContextElement;
use crate::context::ContextMatcher;
@@ -64,8 +65,7 @@ fn bold<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Bold<'s>> {
let text_markup_object_specialized = text_markup_object("*");
let (remaining, children) = text_markup_object_specialized(context, input)?;
let (remaining, children) = text_markup_object("*")(context, input)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
@@ -81,8 +81,7 @@ fn italic<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Italic<'s>> {
let text_markup_object_specialized = text_markup_object("/");
let (remaining, children) = text_markup_object_specialized(context, input)?;
let (remaining, children) = text_markup_object("/")(context, input)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
@@ -98,8 +97,7 @@ fn underline<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Underline<'s>> {
let text_markup_object_specialized = text_markup_object("_");
let (remaining, children) = text_markup_object_specialized(context, input)?;
let (remaining, children) = text_markup_object("_")(context, input)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
@@ -115,8 +113,7 @@ fn strike_through<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, StrikeThrough<'s>> {
let text_markup_object_specialized = text_markup_object("+");
let (remaining, children) = text_markup_object_specialized(context, input)?;
let (remaining, children) = text_markup_object("+")(context, input)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
@@ -132,8 +129,7 @@ fn verbatim<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Verbatim<'s>> {
let text_markup_string_specialized = text_markup_string("=");
let (remaining, contents) = text_markup_string_specialized(context, input)?;
let (remaining, contents) = text_markup_string("=")(context, input)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
@@ -149,8 +145,7 @@ fn code<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Code<'s>> {
let text_markup_string_specialized = text_markup_string("~");
let (remaining, contents) = text_markup_string_specialized(context, input)?;
let (remaining, contents) = text_markup_string("~")(context, input)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
@@ -292,16 +287,22 @@ fn pre<'b, 'g, 'r, 's>(
_context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> {
if start_of_line(input).is_ok() {
return Ok((input, ()));
}
if preceded_by_whitespace(true)(input).is_ok() {
return Ok((input, ()));
}
let preceding_character = input.get_preceding_character();
match preceding_character {
// If None, we are at the start of the file which is technically the beginning of a line.
None | Some('\r') | Some('\n') | Some(' ') | Some('\t') | Some('-') | Some('(')
| Some('{') | Some('\'') | Some('"') | Some('<') => {}
Some('-') | Some('(') | Some('{') | Some('\'') | Some('"') => {}
Some(_) => {
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Not a valid pre character for text markup.".into(),
))));
}
None => unreachable!(), // None is for start of file, which should already be handled by the start_of_line matcher above.
};
Ok((input, ()))
}