Define pre and post matchers for plain link.
All checks were successful
organic-test Build organic-test has succeeded
All checks were successful
organic-test Build organic-test has succeeded
This commit is contained in:
parent
dcec5c490a
commit
59f061ecca
@ -1,10 +1,45 @@
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::none_of;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::recognize;
|
||||
|
||||
use super::Context;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::object::PlainLink;
|
||||
use crate::parser::util::get_one_before;
|
||||
use crate::parser::util::not_yet_implemented;
|
||||
use crate::parser::util::WORD_CONSTITUENT_CHARACTERS;
|
||||
|
||||
#[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!();
|
||||
}
|
||||
|
||||
#[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, ()))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user