From be6197e4c7e7d749115d7e639bb848705bb07670 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 25 Aug 2023 06:20:06 -0400 Subject: [PATCH] Store the tags in the heading. --- src/parser/document.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/parser/document.rs b/src/parser/document.rs index dd4e117..5112b4e 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -54,6 +54,7 @@ pub struct Heading<'s> { pub source: &'s str, pub stars: usize, pub title: Vec>, + pub tags: Vec<&'s str>, pub children: Vec>, } @@ -270,7 +271,7 @@ fn heading<'r, 's>( input: OrgSource<'s>, ) -> Res, Heading<'s>> { 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 heading_matcher = parser_with_context!(heading)(context); let (remaining, children) = many0(alt(( @@ -287,6 +288,7 @@ fn heading<'r, 's>( source: source.into(), stars: star_count, title, + tags: heading_tags, children, }, )) @@ -296,7 +298,7 @@ fn heading<'r, 's>( fn headline<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, -) -> Res, (usize, OrgSource<'s>, Vec>)> { +) -> Res, (usize, OrgSource<'s>, Vec>, Vec<&'s str>)> { let parser_context = context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Document, @@ -313,7 +315,21 @@ fn headline<'r, 's>( space0, alt((line_ending, eof)), ))(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"))]