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
33
34
use super::*;
use std::fmt::{Display, Formatter};

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct Document {
    pub kind: DocumentKind,
    pub text: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum DocumentKind {
    GFM,
}

impl Default for DocumentKind {
    fn default() -> Self {
        Self::GFM
    }
}

impl Display for Document {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        for line in self.text.lines() {
            writeln!(f, "/// {}", line)?
        }
        Ok(())
    }
}

impl Document {
    pub fn markdown(text: impl Into<String>) -> Self {
        Self { kind: DocumentKind::GFM, text: text.into() }
    }
}