Skip to content

Commit 4fe5322

Browse files
committed
Refactor examples
1 parent a6f3784 commit 4fe5322

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

examples/lib.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
fn main() -> Result<(), markdown::message::Message> {
2+
// Turn on debugging.
3+
// You can show it with `RUST_LOG=debug cargo run --features log --example lib`
4+
env_logger::init();
5+
6+
// Safely turn (untrusted?) markdown into HTML.
7+
println!("{:?}", markdown::to_html("## Hello, *world*!"));
8+
9+
// Turn trusted markdown into HTML.
10+
println!(
11+
"{:?}",
12+
markdown::to_html_with_options(
13+
"<div style=\"color: goldenrod\">\n\n# Hi, *Saturn*! 🪐\n\n</div>",
14+
&markdown::Options {
15+
compile: markdown::CompileOptions {
16+
allow_dangerous_html: true,
17+
allow_dangerous_protocol: true,
18+
..markdown::CompileOptions::default()
19+
},
20+
..markdown::Options::default()
21+
}
22+
)
23+
);
24+
25+
// Support GFM extensions.
26+
println!(
27+
"{}",
28+
markdown::to_html_with_options(
29+
"* [x] contact ~Mercury~Venus at [email protected]!",
30+
&markdown::Options::gfm()
31+
)?
32+
);
33+
34+
// Access syntax tree and support MDX extensions:
235
println!(
336
"{:?}",
4-
markdown::to_mdast("# Hi *Earth*!", &markdown::ParseOptions::default())?
37+
markdown::to_mdast(
38+
"# <HelloMessage />, {username}!",
39+
&markdown::ParseOptions::mdx()
40+
)?
541
);
642

743
Ok(())

0 commit comments

Comments
 (0)