Store the tags in the heading.

This commit is contained in:
Tom Alexander 2023-08-25 06:20:06 -04:00
parent 2d4e54845b
commit be6197e4c7
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 19 additions and 3 deletions

View File

@ -54,6 +54,7 @@ pub struct Heading<'s> {
pub source: &'s str, pub source: &'s str,
pub stars: usize, pub stars: usize,
pub title: Vec<Object<'s>>, pub title: Vec<Object<'s>>,
pub tags: Vec<&'s str>,
pub children: Vec<DocumentElement<'s>>, pub children: Vec<DocumentElement<'s>>,
} }
@ -270,7 +271,7 @@ fn heading<'r, 's>(
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Heading<'s>> { ) -> Res<OrgSource<'s>, Heading<'s>> {
not(|i| context.check_exit_matcher(i))(input)?; not(|i| context.check_exit_matcher(i))(input)?;
let (remaining, (star_count, _ws, title)) = headline(context, input)?; let (remaining, (star_count, _ws, title, heading_tags)) = headline(context, input)?;
let section_matcher = parser_with_context!(section)(context); let section_matcher = parser_with_context!(section)(context);
let heading_matcher = parser_with_context!(heading)(context); let heading_matcher = parser_with_context!(heading)(context);
let (remaining, children) = many0(alt(( let (remaining, children) = many0(alt((
@ -287,6 +288,7 @@ fn heading<'r, 's>(
source: source.into(), source: source.into(),
stars: star_count, stars: star_count,
title, title,
tags: heading_tags,
children, children,
}, },
)) ))
@ -296,7 +298,7 @@ fn heading<'r, 's>(
fn headline<'r, 's>( fn headline<'r, 's>(
context: Context<'r, 's>, context: Context<'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, (usize, OrgSource<'s>, Vec<Object<'s>>)> { ) -> Res<OrgSource<'s>, (usize, OrgSource<'s>, Vec<Object<'s>>, Vec<&'s str>)> {
let parser_context = let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Document, class: ExitClass::Document,
@ -313,7 +315,21 @@ fn headline<'r, 's>(
space0, space0,
alt((line_ending, eof)), alt((line_ending, eof)),
))(input)?; ))(input)?;
Ok((remaining, (star_count, ws, title))) Ok((
remaining,
(
star_count,
ws,
title,
maybe_tags
.map(|(_ws, tags)| {
tags.into_iter()
.map(|single_tag| Into::<&str>::into(single_tag))
.collect()
})
.unwrap_or(Vec::new()),
),
))
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]