Files
organic/src/parser/horizontal_rule.rs

55 lines
1.6 KiB
Rust
Raw Normal View History

2023-04-21 22:23:59 -04:00
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::character::complete::line_ending;
use nom::character::complete::space0;
use nom::combinator::eof;
use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many1_count;
use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::org_source::OrgSource;
use super::util::get_consumed;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
2023-09-03 12:23:18 -04:00
use crate::context::RefContext;
2023-04-21 22:23:59 -04:00
use crate::error::Res;
use crate::parser::util::start_of_line;
2023-09-03 12:23:18 -04:00
use crate::types::HorizontalRule;
use crate::types::Keyword;
2023-04-21 22:23:59 -04:00
2023-10-09 19:52:32 -04:00
#[cfg_attr(
feature = "tracing",
2023-10-14 19:02:35 -04:00
tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords))
2023-10-09 19:52:32 -04:00
)]
pub(crate) fn horizontal_rule<'b, 'g, 'r, 's, AK>(
affiliated_keywords: AK,
remaining: OrgSource<'s>,
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, HorizontalRule<'s>>
where
AK: IntoIterator<Item = Keyword<'s>>,
{
start_of_line(remaining)?;
let (remaining, _rule) = recognize(tuple((
2023-04-21 22:23:59 -04:00
space0,
verify(many1_count(tag("-")), |dashes| *dashes >= 5),
space0,
alt((line_ending, eof)),
)))(remaining)?;
let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
HorizontalRule {
source: source.into(),
affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
},
))
2023-04-21 22:23:59 -04:00
}