aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-14 14:17:15 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-14 14:35:11 +0200
commit129ea34b18aaf7f5a01d404effbdc78cbbe67a74 (patch)
tree18157c97e6349c37d97861bcefe12b0c1c46724d /src/compiler.rs
parenta1ce43e428754084474a7ecf88ae6debf88b9164 (diff)
downloadmarkdown-rs-129ea34b18aaf7f5a01d404effbdc78cbbe67a74.tar.gz
markdown-rs-129ea34b18aaf7f5a01d404effbdc78cbbe67a74.tar.bz2
markdown-rs-129ea34b18aaf7f5a01d404effbdc78cbbe67a74.zip
Add examples to some docs
Diffstat (limited to '')
-rw-r--r--src/compiler.rs48
1 files changed, 48 insertions, 0 deletions
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, <i>venus</i>!"),
+ /// "<p>Hi, &lt;i&gt;venus&lt;/i&gt;!</p>"
+ /// );
+ ///
+ /// // Turn `allow_dangerous_html` on to allow potentially dangerous HTML:
+ /// assert_eq!(
+ /// micromark_with_options(
+ /// "Hi, <i>venus</i>!",
+ /// &CompileOptions {
+ /// allow_dangerous_html: true,
+ /// allow_dangerous_protocol: false,
+ /// }
+ /// ),
+ /// "<p>Hi, <i>venus</i>!</p>"
+ /// );
+ /// ```
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)>"),
+ /// "<p><a href=\"\">javascript:alert(1)</a></p>"
+ /// );
+ ///
+ /// // Turn `allow_dangerous_protocol` on to allow potentially dangerous protocols:
+ /// assert_eq!(
+ /// micromark_with_options(
+ /// "<javascript:alert(1)>",
+ /// &CompileOptions {
+ /// allow_dangerous_html: false,
+ /// allow_dangerous_protocol: true,
+ /// }
+ /// ),
+ /// "<p><a href=\"javascript:alert(1)\">javascript:alert(1)</a></p>"
+ /// );
+ /// ```
pub allow_dangerous_protocol: bool,
}