fml 0.6.5

Friendly Markup Language
Documentation
use derive_deref::{Deref, DerefMut};
use std::io::{self, ErrorKind::Unsupported};

#[derive(Deref, DerefMut, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct Content(pub Vec<Section>);

// #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
// pub struct Values(pub Vec<FmlValue>);

#[derive(Deref, DerefMut, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct Section(pub FmlValues);

#[derive(Deref, DerefMut, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct FmlValues(pub Vec<FmlValue>);

#[derive(Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct ListItem(pub FmlValues);

#[derive(Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct FmlList(pub Vec<ListItem>);

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub enum FmlValue {
    /// Linebreak, for convenience between environments.
    Linebreak,

    /// Equivalent of HTML's <h1>, spans entire line. "# "
    Heading1(FmlValues),
    /// Equivalent of HTML's <h2>, spans entire line. "## "
    Heading2(FmlValues),
    /// Equivalent of HTML's <h3>, spans entire line. "### "
    Heading3(FmlValues),

    /// Superscript spanning the entire line. "#^"
    Superline(FmlValues),
    /// Subscript spanning the entire line. "#_" or "#!"
    Subline(FmlValues),

    /// Bold text "*"
    Bold(FmlValues),
    /// Italicized text "_"
    Italic(FmlValues),
    /// Strikethrough text "~"
    Strikethrough(FmlValues),

    /// Quote, is its own section. "> "
    Quote(FmlValues),
    List(FmlList),

    /// Superscript. "^{body}"
    Superscript(FmlValues),
    /// Subscript. "_{body}"
    Subscript(FmlValues),
    /// Underlined text. "__"
    Underline(FmlValues),

    /// Colored foreground, uses HTML color name or 6-digit hexadecimal RRGGBB with a "0x" or "#" prefix.\
    /// "#fg<blue>{body}" or "#color<0x00FF00>{body}"
    ColorFg(FmlColor),

    /// Colored background, uses HTML color name or 6-digit hexadecimal RRGGBB with a "0x" or "#" prefix.\
    /// "#bg<blue>{body}" or "#bg<0x00FF00>{body}"
    ColorBg(FmlColor),

    /// Content-warning. "#cw<reason>{body}" or "|spoiler|"
    ContentWarning {
        reason: String,
        body: FmlValues,
    },

    /// Code-block, optional `lang` var for syntax-highlighting. "```"
    CodeBlock {
        lang: Option<String>,
        body: String,
    },

    // TODO: document
    Hyperlink {
        fml: FmlValues,
        uri: String,
    },

    /// Inline code. "`"
    CodeInline(String),

    /// Typst block. Its body gets passed to the typst compiler.
    Typst(String),

    /// Bottom-most element of every other FmlValue,
    /// a catch-all for whatever does not belong in the other tokens.
    Text(String),
}

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub enum FmlCodeBlockValue {
    Str(String),
    Linebreak,
}

// #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
// pub struct FmlFunction {
//     pub name: String,
//     pub params: Option<String>,
//     pub body: FmlValues,
// }

#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct FmlColor {
    pub color: String,
    pub body: FmlValues,
}