markdown-parser 0.1.2

😎 This a crate that can parse a markdown file
Documentation
use crate::parser::Markdown;
use crate::{error::Error, parser::parse};

/// read content from a md file
/// and return parse result
pub fn read_file<P>(path: P) -> Result<Markdown, Error>
where
    P: AsRef<std::path::Path>,
{
    parse(std::fs::read_to_string(path)?.as_str())
}

/// write a Markdown struct into a file
pub fn write_file<P>(markdown: &Markdown, path: P) -> Result<(), Error>
where
    P: AsRef<std::path::Path>,
{
    use std::fs::File;
    use std::io::prelude::Write;

    let mut file = File::create(path)?;
    file.write_all(&markdown.bytes())?;

    Ok(())
}