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 Rst,
11 Plaintext,
12}
13
14impl Format {
15 pub fn from_path(path: &Path) -> Self {
17 match path.extension().and_then(|e| e.to_str()) {
18 Some("org") => Format::Org,
19 Some("tex" | "latex" | "ltx" | "sty" | "cls") => Format::Latex,
20 Some("md" | "markdown" | "mkd" | "mdx") => Format::Markdown,
21 Some("rst" | "rest") => Format::Rst,
22 _ => Format::Plaintext,
23 }
24 }
25
26 pub fn from_arg(arg: FormatArg) -> Self {
27 match arg {
28 FormatArg::Org => Format::Org,
29 FormatArg::Latex => Format::Latex,
30 FormatArg::Markdown => Format::Markdown,
31 FormatArg::Rst => Format::Rst,
32 FormatArg::Plaintext => Format::Plaintext,
33 }
34 }
35}