wayver's git archive


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

sable-markdown/src/parser/inline/wikilink.rs@337ba67f65eaa17b44e371af7c0f0c761d6aa914

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

1use nom::{
2    IResult, Parser as _,
3    bytes::complete::{tag, take_till1},
4    character::complete::{char, space0},
5    combinator::opt,
6    sequence::{delimited, preceded},
7};
8
9use crate::ast::Wikilink;
10
11pub(super) fn wikilink<'a>() -> impl FnMut(&'a str) -> IResult<&'a str, Wikilink> {
12    move |input: &'a str| {
13        let (input, (link, target, name)) = delimited(
14            (tag("[["), space0),
15            (
16                take_till1(|c| matches!(c, '#' | '|' | ']')),
17                opt(preceded(char('#'), take_till1(|c| matches!(c, '|' | ']')))),
18                opt(preceded(char('|'), take_till1(|c| matches!(c, ']')))),
19            ),
20            (space0, tag("]]")),
21        )
22        .parse(input)?;
23
24        let tag = Wikilink {
25            link: link.to_owned(),
26            target: target.map(ToOwned::to_owned),
27            name: name.map(ToOwned::to_owned),
28        };
29
30        Ok((input, tag))
31    }
32}
33