Fix the implementation of post.

This commit is contained in:
Tom Alexander 2023-04-22 20:02:51 -04:00
parent a4cce121c0
commit b6233811c3
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 11 additions and 23 deletions

View File

@ -1,14 +1,13 @@
use crate::error::Res;
use crate::parser::text_markup::text_markup;
use nom::branch::alt;
use nom::combinator::map;
use nom::combinator::not;
use crate::parser::object::Object;
use super::parser_with_context::parser_with_context;
use super::plain_text::plain_text;
use super::Context;
use crate::error::Res;
use crate::parser::object::Object;
use crate::parser::text_markup::text_markup;
#[tracing::instrument(ret, level = "debug")]
pub fn standard_set_object<'r, 's>(
@ -49,9 +48,7 @@ pub fn any_object_except_plain_text<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>> {
// TODO: add entities, LaTeX fragments, export snippets, footnote references, citations (NOT citation references), inline babel calls, inline source blocks, line breaks, links, macros, targets and radio targets, statistics cookies, subscript and superscript, timestamps, and text markup.
not(|i| context.check_exit_matcher(i))(input)?;
// Used for exit matchers so this does not check exit matcher condition.
alt((map(
parser_with_context!(text_markup)(context),
Object::TextMarkup,

View File

@ -1,6 +1,10 @@
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::character::complete::line_ending;
use nom::character::complete::one_of;
use nom::character::complete::space0;
use nom::combinator::peek;
use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many_till;
use nom::sequence::terminated;
@ -43,6 +47,7 @@ pub fn text_markup<'r, 's>(
// TODO: Sometimes its plain text, not objects
let (remaining, close) = text_markup_end_specialized(context, remaining)?;
let (remaining, _trailing_whitespace) = space0(remaining)?;
let source = get_consumed(input, remaining);
@ -71,22 +76,8 @@ pub fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()>
#[tracing::instrument(ret, level = "debug")]
pub fn post<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
let document_root = context.get_document_root().unwrap();
let preceding_character = get_one_before(document_root, input)
.map(|slice| slice.chars().next())
.flatten();
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(_) => {
// Not at start of line, cannot be a heading
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Not a valid pre character for text markup.",
))));
}
};
Ok((input, ()))
let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"")), line_ending))(input)?;
Ok((remaining, ()))
}
#[tracing::instrument(ret, level = "debug")]