raw
1use nom::{
2 IResult, Parser,
3 character::complete::{char, multispace0},
4 combinator::opt,
5 sequence::{delimited, preceded},
6};
7
8use crate::{
9 ast::Link,
10 parser::link_util::{link_destination, link_label, link_title},
11};
12
13pub(super) fn inline_link<'a>() -> impl FnMut(&'a str) -> IResult<&'a str, Link> {
14 move |input: &'a str| {
15 let (input, (children, (destination, title))) = (
16 link_label(),
17 delimited(
18 char('('),
19 (
20 preceded(multispace0, link_destination),
21 opt(preceded(multispace0, link_title)),
22 ),
23 preceded(multispace0, char(')')),
24 ),
25 )
26 .parse(input)?;
27
28 let link = Link {
29 destination,
30 title,
31 children,
32 };
33
34 Ok((input, link))
35 }
36}
37