#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Mode {
#[default]
Off,
Short,
Rec,
Full,
}
impl Mode {
pub fn parse(s: &str) -> Option<Mode> {
Some(match s.trim().to_ascii_lowercase().as_str() {
"none" | "off" | "false" | "no" => Mode::Off,
"short" | "on" | "true" | "yes" => Mode::Short,
"rec" | "recursive" | "long" => Mode::Rec,
"full" => Mode::Full,
_ => return None,
})
}
pub fn name(self) -> &'static str {
match self {
Mode::Off => "none",
Mode::Short => "short",
Mode::Rec => "rec",
Mode::Full => "full",
}
}
pub fn is_on(self) -> bool {
!matches!(self, Mode::Off)
}
pub fn recurses(self) -> bool {
matches!(self, Mode::Rec | Mode::Full)
}
pub fn framed(self) -> bool {
matches!(self, Mode::Short | Mode::Rec)
}
}
#[derive(Default)]
pub struct Fences {
open: Option<String>,
}
impl Fences {
pub fn literal(&mut self, line: &str) -> bool {
let t = line.trim_start();
match &self.open {
Some(open) => {
if t.starts_with(open.as_str()) {
self.open = None;
}
true
}
None => {
if t.starts_with("```") || t.starts_with("~~~") {
self.open =
Some(t.chars().take_while(|c| *c == '`' || *c == '~').collect());
return true;
}
false
}
}
}
}
pub mod compile;
pub mod link;
pub mod preview;
use std::path::Path;
pub fn same_file(a: &Path, b: &Path) -> bool {
match (std::fs::canonicalize(a), std::fs::canonicalize(b)) {
(Ok(x), Ok(y)) => x == y,
_ => a == b,
}
}