#![allow(dead_code)]
use super::markdown::md_link_destination;
use crate::parser::Link;
use crate::parser::markdown::md_link_destination_enclosed;
use crate::parser::markdown::md_link_text;
use crate::take_until_unbalanced;
use html_escape::decode_html_entities;
use nom::Parser;
use nom::bytes::complete::tag;
use nom::combinator::*;
use std::borrow::Cow;
pub fn md_img_link(i: &'_ str) -> nom::IResult<&'_ str, Link<'_>> {
let (i, (alt, src)) = md_img(i)?;
Ok((i, Link::Image(alt, src)))
}
pub fn md_img(i: &'_ str) -> nom::IResult<&'_ str, (Cow<'_, str>, Cow<'_, str>)> {
nom::sequence::preceded(
tag("!"),
(md_link_text, md_img_link_destination_enclosed),
)
.parse(i)
}
fn md_img_link_destination_enclosed(i: &'_ str) -> nom::IResult<&'_ str, Cow<'_, str>> {
map_parser(
nom::sequence::delimited(tag("("), take_until_unbalanced('(', ')'), tag(")")),
md_link_destination,
)
.parse(i)
}
pub fn md_img2dest_link(i: &'_ str) -> nom::IResult<&'_ str, Link<'_>> {
let (i, (text1, img_alt, img_src, text2, dest, title)) = md_img2dest(i)?;
Ok((
i,
Link::Image2Dest(text1, img_alt, img_src, text2, dest, title),
))
}
#[allow(clippy::type_complexity)]
pub fn md_img2dest(
i: &'_ str,
) -> nom::IResult<
&'_ str,
(
Cow<'_, str>,
Cow<'_, str>,
Cow<'_, str>,
Cow<'_, str>,
Cow<'_, str>,
Cow<'_, str>,
),
> {
map(
(
map_parser(
nom::sequence::delimited(tag("["), take_until_unbalanced('[', ']'), tag("]")),
(
nom::bytes::complete::take_until("!["),
md_img,
nom::combinator::rest,
),
),
md_link_destination_enclosed,
),
|((a, (b, c), d), (e, f))| (decode_html_entities(a), b, c, decode_html_entities(d), e, f),
)
.parse(i)
}