From 59ebfca815fc482f624cd3cf1c40c78bd7640623 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 21 Jun 2022 18:15:51 +0200 Subject: Add docs for `default_line_ending` --- readme.md | 2 +- src/compiler.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 3bfed37..1d3cedc 100644 --- a/readme.md +++ b/readme.md @@ -68,7 +68,6 @@ cargo doc --document-private-items #### Docs -- [ ] (1) Add docs for `default_line_ending` - [ ] (1) Add docs for virtual spaces - [ ] (1) Add docs to `subtokenize.rs` - [ ] (1) Add docs for `link.rs` @@ -234,6 +233,7 @@ cargo doc --document-private-items `construct/mod.rs`) - [x] (1) Configurable tokens (destination, label, title) - [x] (1) Configurable limit (destination) +- [x] (1) Add docs for `default_line_ending` ### Extensions diff --git a/src/compiler.rs b/src/compiler.rs index f51305b..e6275f1 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -105,7 +105,47 @@ pub struct Options { /// ``` pub allow_dangerous_protocol: bool, - /// To do. + /// Default line ending to use, for line endings not in `value`. + /// + /// Generally, micromark copies line endings (`\r`, `\n`, `\r\n`) in the + /// markdown document over to the compiled HTML. + /// In some cases, such as `> a`, CommonMark requires that extra line + /// endings are added: `
\n

a

\n
`. + /// + /// To create that line ending, the document is checked for the first line + /// ending that is used. + /// If there is no line ending, `default_line_ending` is used. + /// If that isn’t configured, `\n` is used. + /// + /// ## Examples + /// + /// ```rust + /// use micromark::{micromark, micromark_with_options, Options, LineEnding}; + /// + /// // micromark is safe by default: + /// assert_eq!( + /// micromark("> a"), + /// // To do: block quote + /// // "
\n

a

\n
" + /// "

> a

" + /// ); + /// + /// // Define `default_line_ending` to configure the default: + /// assert_eq!( + /// micromark_with_options( + /// "> a", + /// &Options { + /// allow_dangerous_html: false, + /// allow_dangerous_protocol: false, + /// default_line_ending: Some(LineEnding::CarriageReturnLineFeed), + /// + /// } + /// ), + /// // To do: block quote + /// // "
\r\n

a

\r\n
" + /// "

> a

" + /// ); + /// ``` pub default_line_ending: Option, } -- cgit