Handle the possibility of a title-less headline.
This commit is contained in:
@@ -8,6 +8,7 @@ use nom::combinator::eof;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
@@ -19,6 +20,11 @@ use nom::sequence::tuple;
|
||||
use super::org_source::OrgSource;
|
||||
use super::section::section;
|
||||
use super::util::get_consumed;
|
||||
use super::util::org_line_ending;
|
||||
use super::util::org_space;
|
||||
use super::util::org_space_or_line_ending;
|
||||
use super::util::org_spaces0;
|
||||
use super::util::org_spaces1;
|
||||
use super::util::start_of_line;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::ContextElement;
|
||||
@@ -81,10 +87,10 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
Heading {
|
||||
source: source.into(),
|
||||
stars: star_count,
|
||||
todo_keyword: maybe_todo_keyword.map(|((todo_keyword_type, todo_keyword), _ws)| {
|
||||
todo_keyword: maybe_todo_keyword.map(|(todo_keyword_type, todo_keyword)| {
|
||||
(todo_keyword_type, Into::<&str>::into(todo_keyword))
|
||||
}),
|
||||
priority_cookie: maybe_priority.map(|(priority, _)| priority),
|
||||
priority_cookie: maybe_priority.map(|(_, priority)| priority),
|
||||
title,
|
||||
tags: heading_tags,
|
||||
children,
|
||||
@@ -109,9 +115,9 @@ fn headline<'b, 'g, 'r, 's>(
|
||||
OrgSource<'s>,
|
||||
(
|
||||
usize,
|
||||
Option<((TodoKeywordType, OrgSource<'s>), OrgSource<'s>)>,
|
||||
Option<(PriorityCookie, OrgSource<'s>)>,
|
||||
Option<(OrgSource<'s>, OrgSource<'s>)>,
|
||||
Option<(TodoKeywordType, OrgSource<'s>)>,
|
||||
Option<(OrgSource<'s>, PriorityCookie)>,
|
||||
Option<OrgSource<'s>>,
|
||||
Vec<Object<'s>>,
|
||||
Vec<&'s str>,
|
||||
),
|
||||
@@ -122,45 +128,45 @@ fn headline<'b, 'g, 'r, 's>(
|
||||
});
|
||||
let parser_context = context.with_additional_node(&parser_context);
|
||||
|
||||
let (
|
||||
remaining,
|
||||
(
|
||||
_,
|
||||
star_count,
|
||||
_,
|
||||
maybe_todo_keyword,
|
||||
maybe_priority,
|
||||
maybe_comment,
|
||||
title,
|
||||
maybe_tags,
|
||||
_,
|
||||
_,
|
||||
),
|
||||
) = tuple((
|
||||
let (remaining, (_, star_count, _)) = tuple((
|
||||
start_of_line,
|
||||
verify(many1_count(tag("*")), |star_count| {
|
||||
*star_count > parent_stars
|
||||
}),
|
||||
space1,
|
||||
opt(tuple((
|
||||
parser_with_context!(heading_keyword)(&parser_context),
|
||||
space1,
|
||||
))),
|
||||
opt(tuple((priority_cookie, space1))),
|
||||
opt(tuple((tag("COMMENT"), space1))),
|
||||
many1(parser_with_context!(standard_set_object)(&parser_context)),
|
||||
opt(tuple((space0, tags))),
|
||||
space0,
|
||||
alt((line_ending, eof)),
|
||||
peek(org_space),
|
||||
))(input)?;
|
||||
|
||||
let (remaining, maybe_todo_keyword) = opt(tuple((
|
||||
org_spaces1,
|
||||
parser_with_context!(heading_keyword)(&parser_context),
|
||||
peek(org_space_or_line_ending),
|
||||
)))(remaining)?;
|
||||
|
||||
let (remaining, maybe_priority) = opt(tuple((org_spaces1, priority_cookie)))(remaining)?;
|
||||
|
||||
let (remaining, maybe_comment) = opt(tuple((
|
||||
org_spaces1,
|
||||
tag("COMMENT"),
|
||||
peek(org_space_or_line_ending),
|
||||
)))(remaining)?;
|
||||
|
||||
let (remaining, maybe_title) = opt(tuple((
|
||||
org_spaces1,
|
||||
many1(parser_with_context!(standard_set_object)(&parser_context)),
|
||||
)))(remaining)?;
|
||||
|
||||
let (remaining, maybe_tags) = opt(tuple((org_spaces0, tags)))(remaining)?;
|
||||
|
||||
let (remaining, _) = tuple((org_spaces0, org_line_ending))(remaining)?;
|
||||
|
||||
Ok((
|
||||
remaining,
|
||||
(
|
||||
star_count,
|
||||
maybe_todo_keyword,
|
||||
maybe_todo_keyword.map(|(_, todo, _)| todo),
|
||||
maybe_priority,
|
||||
maybe_comment,
|
||||
title,
|
||||
maybe_comment.map(|(_, comment, _)| comment),
|
||||
maybe_title.map(|(_, title)| title).unwrap_or(Vec::new()),
|
||||
maybe_tags
|
||||
.map(|(_ws, tags)| {
|
||||
tags.into_iter()
|
||||
|
||||
Reference in New Issue
Block a user