wooorm / markdown-rs

CommonMark compliant markdown parser in Rust with ASTs and extensions
https://docs.rs/markdown/1.0.0-alpha.18/markdown/
MIT License
836 stars 41 forks source link

Allow both gfm (for tables) and allow embedding HTML with allow_dangerous_html #89

Closed szabgab closed 7 months ago

szabgab commented 7 months ago

I wanted to both allow for Markdown tables and allow the embedding of HTML tags. (specifically I wanted to use an iframe to embed YouTube videos.

This is what worked for me:

    let content = markdown::to_html_with_options(
        &content,
        &markdown::Options {
            compile: markdown::CompileOptions {
                allow_dangerous_html: true,
                ..markdown::CompileOptions::default()
            },
            ..markdown::Options::gfm()
        },
    )
    .unwrap();

Is this the correct and recommended way? It is unclear to me what should be inside the CompileOptions and what should be outside.

Would it be a good idea to add such example to this example?

wooorm commented 7 months ago

Hey! CompileOptions, like ParseOptions and Options also has gfm: https://docs.rs/markdown/1.0.0-alpha.14/markdown/struct.CompileOptions.html#method.gfm. It doesn’t do much though.

The API docs explain which fields are allowed where, but Rust IDE tooling should also be able to show that. I don’t think another example in that file is useful. There are already so many examples in the docs. That file is not supposed to be exhaustive or long.