Fix handling of whitespace at the end of paragraphs and mandatory whitespace in list items.
This commit is contained in:
parent
0e070f2d4c
commit
b5b335b9b0
@ -1,5 +1,4 @@
|
|||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::character::complete::line_ending;
|
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
@ -14,6 +13,7 @@ use crate::parser::parser_context::ContextElement;
|
|||||||
use crate::parser::parser_context::ExitMatcherNode;
|
use crate::parser::parser_context::ExitMatcherNode;
|
||||||
use crate::parser::parser_with_context::parser_with_context;
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
|
use crate::parser::util::start_of_line;
|
||||||
|
|
||||||
use super::element::non_paragraph_element;
|
use super::element::non_paragraph_element;
|
||||||
use super::error::Res;
|
use super::error::Res;
|
||||||
@ -32,14 +32,10 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
|
|||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
|
|
||||||
let (remaining, (children, _exit_contents)) = verify(
|
let (remaining, (children, _exit_contents)) = verify(
|
||||||
many_till(
|
many_till(standard_set_object_matcher, peek(recognize(exit_matcher))),
|
||||||
standard_set_object_matcher,
|
|
||||||
peek(alt((eof, recognize(tuple((line_ending, exit_matcher)))))),
|
|
||||||
),
|
|
||||||
|(children, _exit_contents)| !children.is_empty(),
|
|(children, _exit_contents)| !children.is_empty(),
|
||||||
)(input)?;
|
)(input)?;
|
||||||
|
|
||||||
let (remaining, _linebreak) = alt((eof, line_ending))(remaining)?;
|
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
|
|
||||||
Ok((remaining, Paragraph { source, children }))
|
Ok((remaining, Paragraph { source, children }))
|
||||||
@ -48,8 +44,9 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
|
|||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
let non_paragraph_element_matcher = parser_with_context!(non_paragraph_element)(context);
|
let non_paragraph_element_matcher = parser_with_context!(non_paragraph_element)(context);
|
||||||
|
let start_of_line_matcher = parser_with_context!(start_of_line)(&context);
|
||||||
alt((
|
alt((
|
||||||
recognize(many1(blank_line)),
|
recognize(tuple((start_of_line_matcher, many1(blank_line)))),
|
||||||
recognize(non_paragraph_element_matcher),
|
recognize(non_paragraph_element_matcher),
|
||||||
eof,
|
eof,
|
||||||
))(input)
|
))(input)
|
||||||
|
@ -16,8 +16,10 @@ use crate::parser::util::start_of_line;
|
|||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::character::complete::digit1;
|
use nom::character::complete::digit1;
|
||||||
|
use nom::character::complete::line_ending;
|
||||||
use nom::character::complete::one_of;
|
use nom::character::complete::one_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
|
use nom::character::complete::space1;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::verify;
|
use nom::combinator::verify;
|
||||||
@ -57,24 +59,42 @@ pub fn plain_list_item<'r, 's>(
|
|||||||
|
|
||||||
let element_matcher = parser_with_context!(element)(&parser_context);
|
let element_matcher = parser_with_context!(element)(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
let (remaining, (bull, _ws)) = tuple((bullet, space0))(remaining)?;
|
let (remaining, bull) = bullet(remaining)?;
|
||||||
let (remaining, (contents, _exit_contents)) =
|
let maybe_contentless_item: Res<&str, &str> = alt((eof, line_ending))(remaining);
|
||||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
match maybe_contentless_item {
|
||||||
let source = get_consumed(input, remaining);
|
Ok((rem, _ws)) => {
|
||||||
|
let source = get_consumed(input, rem);
|
||||||
Ok((
|
return Ok((
|
||||||
remaining,
|
rem,
|
||||||
PlainListItem {
|
PlainListItem {
|
||||||
source,
|
source,
|
||||||
indentation: indent_level,
|
indentation: indent_level,
|
||||||
bullet: bull,
|
bullet: bull,
|
||||||
contents,
|
contents: Vec::new(),
|
||||||
},
|
},
|
||||||
))
|
));
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
let (remaining, _ws) = space1(remaining)?;
|
||||||
|
let (remaining, (contents, _exit_contents)) =
|
||||||
|
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
return Ok((
|
||||||
|
remaining,
|
||||||
|
PlainListItem {
|
||||||
|
source,
|
||||||
|
indentation: indent_level,
|
||||||
|
bullet: bull,
|
||||||
|
contents,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
fn bullet<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
fn bullet<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
||||||
|
// TODO: If asterisk, it cannot be at start of line or it would be a headline
|
||||||
alt((
|
alt((
|
||||||
tag("*"),
|
tag("*"),
|
||||||
tag("-"),
|
tag("-"),
|
||||||
|
@ -1,3 +1,24 @@
|
|||||||
|
prologue *goes here* I guess *bold
|
||||||
|
text*
|
||||||
|
|
||||||
|
bold*wont* start *or stop*when there is text outside it
|
||||||
|
|
||||||
|
I guess *regular
|
||||||
|
|
||||||
|
text*
|
||||||
|
|
||||||
|
[foo *bar] baz* car
|
||||||
|
|
||||||
|
|
||||||
|
*nesting *bold entrances* and* exits
|
||||||
|
|
||||||
|
* Heading
|
||||||
|
|
||||||
|
body of heading
|
||||||
|
|
||||||
|
** Child heading
|
||||||
|
** Immediate second child heading
|
||||||
|
|
||||||
* Second top-level heading
|
* Second top-level heading
|
||||||
foo bar
|
foo bar
|
||||||
1. This is a list immediately after a paragraph
|
1. This is a list immediately after a paragraph
|
||||||
|
Loading…
x
Reference in New Issue
Block a user