2023-07-13 18:30:18 -04:00
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::character::complete::none_of;
|
|
|
|
use nom::combinator::eof;
|
|
|
|
use nom::combinator::recognize;
|
|
|
|
|
2023-07-13 18:18:07 -04:00
|
|
|
use super::Context;
|
2023-07-13 18:30:18 -04:00
|
|
|
use crate::error::CustomError;
|
|
|
|
use crate::error::MyError;
|
2023-07-13 18:18:07 -04:00
|
|
|
use crate::error::Res;
|
|
|
|
use crate::parser::object::PlainLink;
|
2023-07-13 18:30:18 -04:00
|
|
|
use crate::parser::util::get_one_before;
|
2023-07-13 18:18:07 -04:00
|
|
|
use crate::parser::util::not_yet_implemented;
|
2023-07-13 18:30:18 -04:00
|
|
|
use crate::parser::util::WORD_CONSTITUENT_CHARACTERS;
|
2023-07-13 18:18:07 -04:00
|
|
|
|
|
|
|
#[tracing::instrument(ret, level = "debug")]
|
|
|
|
pub fn plain_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainLink<'s>> {
|
|
|
|
not_yet_implemented()?;
|
|
|
|
todo!();
|
|
|
|
}
|
2023-07-13 18:30:18 -04:00
|
|
|
|
|
|
|
#[tracing::instrument(ret, level = "debug")]
|
|
|
|
pub fn pre<'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 fine
|
|
|
|
None => {}
|
|
|
|
Some(x) if !WORD_CONSTITUENT_CHARACTERS.contains(x) => {}
|
|
|
|
Some(_) => {
|
|
|
|
// Not at start of line, cannot be a heading
|
|
|
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
|
|
"Not a valid pre character for plain link.",
|
|
|
|
))));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ok((input, ()))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(ret, level = "debug")]
|
|
|
|
pub fn post<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
|
|
|
let (remaining, _) = alt((eof, recognize(none_of(WORD_CONSTITUENT_CHARACTERS))))(input)?;
|
|
|
|
Ok((remaining, ()))
|
|
|
|
}
|