From 129ea34b18aaf7f5a01d404effbdc78cbbe67a74 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 14 Jun 2022 14:17:15 +0200 Subject: Add examples to some docs --- src/compiler.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/compiler.rs') diff --git a/src/compiler.rs b/src/compiler.rs index e1ce440..2a3f101 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -14,11 +14,59 @@ pub struct CompileOptions { /// Whether to allow (dangerous) HTML. /// The default is `false`, you can turn it on to `true` for trusted /// content. + /// + /// ## Examples + /// + /// ```rust + /// use micromark::{micromark, micromark_with_options, CompileOptions}; + /// + /// // micromark is safe by default: + /// assert_eq!( + /// micromark("Hi, venus!"), + /// "

Hi, <i>venus</i>!

" + /// ); + /// + /// // Turn `allow_dangerous_html` on to allow potentially dangerous HTML: + /// assert_eq!( + /// micromark_with_options( + /// "Hi, venus!", + /// &CompileOptions { + /// allow_dangerous_html: true, + /// allow_dangerous_protocol: false, + /// } + /// ), + /// "

Hi, venus!

" + /// ); + /// ``` pub allow_dangerous_html: bool, /// Whether to allow (dangerous) protocols in links and images. /// The default is `false`, you can turn it on to `true` for trusted /// content. + /// + /// ## Examples + /// + /// ```rust + /// use micromark::{micromark, micromark_with_options, CompileOptions}; + /// + /// // micromark is safe by default: + /// assert_eq!( + /// micromark(""), + /// "

javascript:alert(1)

" + /// ); + /// + /// // Turn `allow_dangerous_protocol` on to allow potentially dangerous protocols: + /// assert_eq!( + /// micromark_with_options( + /// "", + /// &CompileOptions { + /// allow_dangerous_html: false, + /// allow_dangerous_protocol: true, + /// } + /// ), + /// "

javascript:alert(1)

" + /// ); + /// ``` pub allow_dangerous_protocol: bool, } -- cgit