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;
|
|
|
|
|
|
2023-10-11 14:44:25 -04:00
|
|
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
2023-08-23 00:30:26 -04:00
|
|
|
use super::org_source::OrgSource;
|
2023-10-06 11:45:15 -04:00
|
|
|
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;
|
2023-10-12 17:12:55 -04:00
|
|
|
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
|
|
|
)]
|
2023-10-12 17:12:55 -04:00
|
|
|
pub(crate) fn horizontal_rule<'b, 'g, 'r, 's, AK>(
|
|
|
|
|
affiliated_keywords: AK,
|
|
|
|
|
remaining: OrgSource<'s>,
|
2023-10-06 11:45:15 -04:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 00:30:26 -04:00
|
|
|
input: OrgSource<'s>,
|
2023-10-12 17:12:55 -04:00
|
|
|
) -> Res<OrgSource<'s>, HorizontalRule<'s>>
|
|
|
|
|
where
|
|
|
|
|
AK: IntoIterator<Item = Keyword<'s>>,
|
|
|
|
|
{
|
2023-10-06 11:45:15 -04:00
|
|
|
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)),
|
2023-10-06 11:45:15 -04:00
|
|
|
)))(remaining)?;
|
|
|
|
|
let (remaining, _trailing_ws) =
|
|
|
|
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
|
|
|
|
let source = get_consumed(input, remaining);
|
2023-08-23 00:30:26 -04:00
|
|
|
Ok((
|
|
|
|
|
remaining,
|
|
|
|
|
HorizontalRule {
|
2023-10-06 11:45:15 -04:00
|
|
|
source: source.into(),
|
2023-10-11 14:44:25 -04:00
|
|
|
affiliated_keywords: parse_affiliated_keywords(
|
|
|
|
|
context.get_global_settings(),
|
|
|
|
|
affiliated_keywords,
|
|
|
|
|
),
|
2023-08-23 00:30:26 -04:00
|
|
|
},
|
|
|
|
|
))
|
2023-04-21 22:23:59 -04:00
|
|
|
}
|