html_generator::performance

Function async_generate_html

source
pub async fn async_generate_html(markdown: &str) -> Result<String>
Expand description

Asynchronously generate HTML from Markdown.

This function converts a Markdown string into an HTML string using Comrak, a CommonMark-compliant Markdown parser and renderer. The conversion is performed in a separate thread to avoid blocking.

§Arguments

  • markdown - A reference to a Markdown string.

§Returns

  • Result<String, HtmlError> - A result containing a string with the generated HTML.

§Examples

use html_generator::performance::async_generate_html;

#[tokio::main]
async fn main() {
    let markdown = "# Hello\n\nThis is a test.";
    match async_generate_html(markdown).await {
        Ok(html) => println!("Generated HTML: {}", html),
        Err(e) => eprintln!("Error: {}", e),
    }
}