mlc/
markup.rs

1use serde::Deserialize;
2use std::str::FromStr;
3
4#[derive(Debug)]
5pub struct MarkupFile {
6    pub markup_type: MarkupType,
7    pub path: String,
8}
9
10#[derive(Debug, Clone, Copy, Deserialize)]
11pub enum MarkupType {
12    Markdown,
13    Html,
14}
15
16impl FromStr for MarkupType {
17    type Err = ();
18
19    fn from_str(s: &str) -> Result<MarkupType, ()> {
20        match s {
21            "md" => Ok(MarkupType::Markdown),
22            "html" => Ok(MarkupType::Html),
23            _ => Err(()),
24        }
25    }
26}
27
28impl MarkupType {
29    #[must_use]
30    pub fn file_extensions(&self) -> Vec<String> {
31        match self {
32            MarkupType::Markdown => vec![
33                "md".to_string(),
34                "markdown".to_string(),
35                "mkdown".to_string(),
36                "mkdn".to_string(),
37                "mkd".to_string(),
38                "mdwn".to_string(),
39                "mdtxt".to_string(),
40                "mdtext".to_string(),
41                "text".to_string(),
42                "rmd".to_string(),
43            ],
44            MarkupType::Html => vec!["htm".to_string(), "html".to_string(), "xhtml".to_string()],
45        }
46    }
47}