fml 0.6.1

Friendly Markup Language
Documentation
mod debug;
pub use debug::*;

mod from;
#[cfg(feature = "parser")]
mod try_from;
#[cfg(feature = "parser")]
pub use try_from::*;

#[cfg(feature = "parser")]
use std::str::FromStr;
use std::{
    fmt::Debug,
    io::{self, ErrorKind::Unsupported},
};

use super::data::{Content, FmlCodeBlockValue, FmlColor, FmlValue, FmlValue::*, Section};

impl FmlValue {
    /// Append another fml-value to oneself.
    pub fn join(&mut self, other: Self) -> io::Result<()> {
        match self {
            Heading1(v) | Heading2(v) | Heading3(v) | Superline(v) | Subline(v) | Bold(v)
            | Italic(v) | Strikethrough(v) | Quote(v) | Superscript(v) | Subscript(v)
            | Underline(v) => {
                v.push(other);
            }

            ColorFg(FmlColor { color: _, body })
            | ColorBg(FmlColor { color: _, body })
            | ContentWarning { reason: _, body } => {
                body.push(other);
            }

            List(l1) => {
                if let List(mut l2) = other {
                    l1.append(&mut l2);
                }
            }

            Text(s1) => {
                if let Text(s2) = other {
                    s1.push_str(&s2);
                } else {
                    return Err(io::Error::from(Unsupported));
                }
            }

            _ => {
                return Err(io::Error::from(Unsupported));
            }
        }

        Ok(())
    }
}