Skip to content

Commit

Permalink
chore: exploring markdown-rs frontmatter construct related to md yaml…
Browse files Browse the repository at this point in the history
… metadata section
  • Loading branch information
husni-zuhdi committed Sep 2, 2024
1 parent fbbcaf1 commit a1e65f4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions internal/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
use crate::model::version::Version;
use markdown::{to_html_with_options, Options};
use log::debug;
use markdown::{to_html_with_options, CompileOptions, Constructs, Options, ParseOptions};
use std::fs;
use std::io::BufReader;

/// md_to_html: Markdown to HTML
/// take String of filename
/// return String of converted markdown in html or String of error
pub fn md_to_html(filename: String) -> Result<String, String> {
let body_md = fs::read_to_string(filename).expect("Failed to read markdown blog file");
let html = to_html_with_options(&body_md, &Options::gfm())
.expect("Failed to convert html with options");
let body_md = fs::read_to_string(filename.clone()).expect("Failed to read markdown blog file");
debug!("Markdown Body for filename {}: {}", &filename, body_md);

let html = to_html_with_options(
&body_md,
&Options {
parse: ParseOptions {
constructs: Constructs {
// In case you want to activeat frontmatter in the future
// frontmatter: true,
..Constructs::gfm()
},
..ParseOptions::gfm()
},
compile: CompileOptions::gfm(),
},
)
.expect("Failed to convert html with options");
Ok(html)
}

Expand Down

0 comments on commit a1e65f4

Please sign in to comment.