1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub(crate) use std::vec::IntoIter;

use pulldown_cmark::{CowStr, Event, LinkType, Tag};

/// A link with items as represented by [`pulldown_cmark::Event`].
/// Except, instead of separate events, this is one complete datastructure
/// suitable to run a replacer on.
#[derive(Debug, Clone)]
pub struct Link<'a> {
    pub link_type: LinkType,
    pub destination: CowStr<'a>,
    pub title: CowStr<'a>,
    pub text: Vec<Event<'a>>,
}

impl<'a> IntoIterator for Link<'a> {
    type Item = Event<'a>;

    type IntoIter = IntoIter<Event<'a>>;

    fn into_iter(mut self) -> Self::IntoIter {
        let start = Event::Start(Tag::Link(
            self.link_type,
            self.destination.clone(),
            self.title.clone(),
        ));
        let end = Event::End(Tag::Link(self.link_type, self.destination, self.title));
        self.text.insert(0, start);
        self.text.push(end);
        self.text.into_iter()
    }
}