markdown_linkify/
link.rs

1pub(crate) use std::vec::IntoIter;
2
3use pulldown_cmark::{CowStr, Event, LinkType, Tag};
4
5/// A link with items as represented by [`pulldown_cmark::Event`].
6/// Except, instead of separate events, this is one complete datastructure
7/// suitable to run a replacer on.
8#[derive(Debug, Clone)]
9pub struct Link<'a> {
10    pub link_type: LinkType,
11    pub destination: CowStr<'a>,
12    pub title: CowStr<'a>,
13    pub text: Vec<Event<'a>>,
14}
15
16impl<'a> IntoIterator for Link<'a> {
17    type Item = Event<'a>;
18
19    type IntoIter = IntoIter<Event<'a>>;
20
21    fn into_iter(mut self) -> Self::IntoIter {
22        let start = Event::Start(Tag::Link(
23            self.link_type,
24            self.destination.clone(),
25            self.title.clone(),
26        ));
27        let end = Event::End(Tag::Link(self.link_type, self.destination, self.title));
28        self.text.insert(0, start);
29        self.text.push(end);
30        self.text.into_iter()
31    }
32}