pub fn to_html_with_options(
    value: &str,
    options: &Options
) -> Result<String, String>
Expand description

Turn markdown into HTML, with configuration.

Errors

to_html_with_options() never errors with normal markdown because markdown does not have syntax errors, so feel free to unwrap(). However, MDX does have syntax errors. When MDX is turned on, there are several errors that can occur with how expressions, ESM, and JSX are written.

Examples

use markdown::{to_html_with_options, CompileOptions, Options};

// Use GFM:
let result = to_html_with_options("~hi~hello!", &Options::gfm())?;

assert_eq!(result, "<p><del>hi</del>hello!</p>");

// Live dangerously / trust the author:
let result = to_html_with_options("<div>\n\n# Hello, world!\n\n</div>", &Options {
    compile: CompileOptions {
      allow_dangerous_html: true,
      allow_dangerous_protocol: true,
      ..CompileOptions::default()
    },
    ..Options::default()
})?;

assert_eq!(result, "<div>\n<h1>Hello, world!</h1>\n</div>");