1use std::path::Path;
2
3use crate::cli::FormatArg;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum Format {
7 Org,
8 Latex,
9 Markdown,
10 Plaintext,
11}
12
13impl Format {
14 pub fn from_path(path: &Path) -> Self {
16 match path.extension().and_then(|e| e.to_str()) {
17 Some("org") => Format::Org,
18 Some("tex" | "latex" | "ltx" | "sty" | "cls") => Format::Latex,
19 Some("md" | "markdown" | "mkd" | "mdx") => Format::Markdown,
20 _ => Format::Plaintext,
21 }
22 }
23
24 pub fn from_arg(arg: FormatArg) -> Self {
25 match arg {
26 FormatArg::Org => Format::Org,
27 FormatArg::Latex => Format::Latex,
28 FormatArg::Markdown => Format::Markdown,
29 FormatArg::Plaintext => Format::Plaintext,
30 }
31 }
32}