wayver's git archive


an obsidian renderer
git clone https://git.wayver.dev/sable

sable-markdown/src/parser/inline/inline_link.rs@2b84405277e54ab809e328cf0237374d4b4dbd0c

raw
Date Commit Message Author Files + -
2026-02-23 01:55 initial mvp wayverd 139 17808 0
...

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