Convert Markdown to HTML

markdown HTML

We are using the new incarnation of the markdown crate that has not replaced the old one yet. The source code explains it and referres us to the version number of the most recent release of the new crate.


name = "markdow-to-html"
version = "0.1.0"
edition = "2021"

markdown = "1.0.0-alpha.17"

The code

In the code I wrapped the parameters in a new function call. This is how I use the crate in the Code Maven SSG the code that generates the Rust Maven web site.

Setting the allow_dangerous_html means we can embed HTML tags in the Markdown and they will be passed on without escaping the HTML tags.


fn main() -> Result<(), Box<dyn std::error::Error>> {
    let markdown = std::fs::read_to_string("")?;
    match markdown2html(&markdown) {
        Ok(html) => println!("{html}"),
        Err(err) => return Err(Box::<dyn std::error::Error>::from(format!("{err}"))),


fn markdown2html(content: &str) -> Result<String, markdown::message::Message> {
    let html = markdown::to_html_with_options(
        &markdown::Options {
            compile: markdown::CompileOptions {
                allow_dangerous_html: true,


Some simple markdown file

The following file was used for the example


# Main title

This text is under the main title

## First subtitle

* apple
* banana
* peach

A [link to the markdown crate]( that we use.

## Code snippet:

fn main() {



There is a command in here: cargo run to run the crate.


Some bold and italic and anything else.


Gabor Szabo (szabgab)

Gabor Szabo, the author of the Rust Maven web site maintains several Open source projects in Rust and while he still feels he has tons of new things to learn about Rust he already offers training courses in Rust and still teaches Python, Perl, git, GitHub, GitLab, CI, and testing.

Gabor Szabo