Check that the preceding line for a line break is non-empty.
This commit is contained in:
@@ -9,6 +9,7 @@ use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::get_current_line_before_position;
|
||||
use crate::parser::util::get_one_before;
|
||||
use crate::parser::LineBreak;
|
||||
|
||||
@@ -28,7 +29,6 @@ fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
let preceding_character = get_one_before(document_root, input)
|
||||
.map(|slice| slice.chars().next())
|
||||
.flatten();
|
||||
// TODO: Must be at the end of a non-empty line so instead of getting one character before, we need to grab the entire line.
|
||||
match preceding_character {
|
||||
// If None, we are at the start of the file
|
||||
None | Some('\\') => {
|
||||
@@ -38,5 +38,22 @@ fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
let current_line = get_current_line_before_position(document_root, input);
|
||||
match current_line {
|
||||
Some(line) => {
|
||||
let is_non_empty_line = line.chars().any(|c| !c.is_whitespace());
|
||||
if !is_non_empty_line {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not a valid pre line for line break.",
|
||||
))));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"No preceding line for line break.",
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
Ok((input, ()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user