diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-08 15:52:16 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-08 15:52:16 +0200 |
commit | 4c06c8554c35887f8f5147783953b2b7e7c2327f (patch) | |
tree | 1b2463848a3ae4c645f7f1a325877ee829ab65c5 /src/lib.rs | |
download | markdown-rs-4c06c8554c35887f8f5147783953b2b7e7c2327f.tar.gz markdown-rs-4c06c8554c35887f8f5147783953b2b7e7c2327f.tar.bz2 markdown-rs-4c06c8554c35887f8f5147783953b2b7e7c2327f.zip |
.
Diffstat (limited to '')
-rw-r--r-- | src/lib.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..1624a22 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,52 @@ +//! Public API of micromark. +//! +//! This module exposes [`micromark`][] (and [`micromark_with_options`][]). +//! `micromark` is a safe way to transform (untrusted?) markdown into HTML. +//! `micromark_with_options` allows you to configure how markdown is turned into +//! HTML, such as by allowing dangerous HTML when you trust it. +mod compiler; +mod constant; +mod construct; +mod content; +mod parser; +mod tokenizer; +mod util; + +use crate::compiler::compile; +pub use crate::compiler::CompileOptions; +use crate::parser::parse; + +/// Turn markdown into HTML. +/// +/// ## Examples +/// +/// ```rust +/// use micromark::micromark; +/// +/// let result = micromark("# Hello, world!"); +/// +/// assert_eq!(result, "<h1>Hello, world!</h1>"); +/// ``` +#[must_use] +pub fn micromark(value: &str) -> String { + micromark_with_options(value, &CompileOptions::default()) +} + +/// Turn markdown into HTML, with configuration. +/// +/// ## Examples +/// +/// ```rust +/// use micromark::{micromark_with_options, CompileOptions}; +/// +/// let result = micromark_with_options("<div>\n\n# Hello, world!\n\n</div>", &CompileOptions { +/// allow_dangerous_html: true, +/// }); +/// +/// assert_eq!(result, "<div>\n<h1>Hello, world!</h1>\n</div>"); +/// ``` +#[must_use] +pub fn micromark_with_options(value: &str, options: &CompileOptions) -> String { + let (events, codes) = parse(value); + compile(&events, &codes, options) +} |