wayver's git archive


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

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

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

1mod autolink;
2mod code_span;
3mod emphasis;
4mod footnote_reference;
5mod hard_newline;
6mod html_entity;
7mod image;
8mod inline_link;
9mod reference_link;
10mod strikethrough;
11mod tag;
12mod text;
13mod wikilink;
14
15#[cfg(test)]
16mod tests;
17
18use nom::{
19    IResult, Parser,
20    branch::alt,
21    combinator::map,
22    multi::{many0, many1},
23};
24
25use crate::ast::Inline;
26
27pub(super) fn inline_many0<'a>() -> impl FnMut(&'a str) -> IResult<&'a str, Vec<Inline>> {
28    move |input: &'a str| {
29        let (input, list_of_lists) = many0(inline()).parse(input)?;
30        let r: Vec<_> = list_of_lists.into_iter().flatten().collect();
31        Ok((input, r))
32    }
33}
34
35pub(super) fn inline_many1<'a>() -> impl FnMut(&'a str) -> IResult<&'a str, Vec<Inline>> {
36    move |input: &'a str| {
37        let (input, list_of_lists) = many1(inline()).parse(input)?;
38        let r: Vec<_> = list_of_lists.into_iter().flatten().collect();
39        Ok((input, r))
40    }
41}
42
43pub(super) fn inline<'a>() -> impl FnMut(&'a str) -> IResult<&'a str, Vec<Inline>> {
44    move |input: &'a str| {
45        alt((
46            map(wikilink::wikilink(), Inline::Wikilink),
47            map(autolink::autolink, Inline::Autolink),
48            map(inline_link::inline_link(), Inline::Link),
49            footnote_reference::footnote_reference,
50            reference_link::reference_link(),
51            hard_newline::hard_newline,
52            image::image(),
53            map(code_span::code_span, Inline::Code),
54            emphasis::emphasis(),
55            strikethrough::strikethrough(),
56            map(tag::tag(), Inline::Tag),
57            text::text(),
58        ))
59        .map(|v| vec![v])
60        .parse(input)
61    }
62}
63