feat: Org::keywords function

This commit is contained in:
PoiScript 2019-10-30 21:05:37 +08:00
parent b446471535
commit ab377b2cc5

View file

@ -4,7 +4,7 @@ use std::ops::{Index, IndexMut};
use crate::{ use crate::{
config::{ParseConfig, DEFAULT_CONFIG}, config::{ParseConfig, DEFAULT_CONFIG},
elements::Element, elements::{Element, Keyword},
export::{DefaultHtmlHandler, DefaultOrgHandler, HtmlHandler, OrgHandler}, export::{DefaultHtmlHandler, DefaultOrgHandler, HtmlHandler, OrgHandler},
parsers::{blank_lines, parse_container, Container}, parsers::{blank_lines, parse_container, Container},
}; };
@ -78,6 +78,17 @@ impl<'a> Org<'a> {
}) })
} }
/// Returns an iterator of `Keyword`s.
pub fn keywords(&self) -> impl Iterator<Item = &Keyword<'_>> {
self.root
.descendants(&self.arena)
.skip(1)
.filter_map(move |node| match &self[node] {
Element::Keyword(kw) => Some(kw),
_ => None,
})
}
/// Writes an `Org` struct as html format. /// Writes an `Org` struct as html format.
pub fn write_html<W>(&self, writer: W) -> Result<(), Error> pub fn write_html<W>(&self, writer: W) -> Result<(), Error>
where where