aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compiler.rs4
-rw-r--r--src/lib.rs8
-rw-r--r--tests/misc_default_line_ending.rs4
3 files changed, 7 insertions, 9 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index db52837..0993987 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -247,10 +247,8 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String {
// Figure out which line ending style we’ll use.
let line_ending_default = if let Some(value) = line_ending_inferred {
value
- } else if let Some(value) = &options.default_line_ending {
- value.clone()
} else {
- LineEnding::LineFeed
+ options.default_line_ending.clone()
};
let mut enter_map: Map = HashMap::new();
diff --git a/src/lib.rs b/src/lib.rs
index 224f8d0..196eb4e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,7 +20,7 @@ use crate::parser::parse;
use crate::tokenizer::Code;
/// Type of line endings in markdown.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Default, Clone, PartialEq)]
pub enum LineEnding {
/// Both a carriage return (`\r`) and a line feed (`\n`).
///
@@ -48,6 +48,7 @@ pub enum LineEnding {
/// a␊
/// b
/// ```
+ #[default]
LineFeed,
}
@@ -349,15 +350,14 @@ pub struct Options {
/// micromark_with_options(
/// "> a",
/// &Options {
- /// default_line_ending: Some(LineEnding::CarriageReturnLineFeed),
+ /// default_line_ending: LineEnding::CarriageReturnLineFeed,
/// ..Options::default()
/// }
/// ),
/// "<blockquote>\r\n<p>a</p>\r\n</blockquote>"
/// );
/// ```
- // To do: use `default`? <https://doc.rust-lang.org/std/default/trait.Default.html#enums>
- pub default_line_ending: Option<LineEnding>,
+ pub default_line_ending: LineEnding,
/// Which constructs to enable and disable.
/// The default is to follow `CommonMark`.
diff --git a/tests/misc_default_line_ending.rs b/tests/misc_default_line_ending.rs
index ceada62..547cae1 100644
--- a/tests/misc_default_line_ending.rs
+++ b/tests/misc_default_line_ending.rs
@@ -31,7 +31,7 @@ fn default_line_ending() {
micromark_with_options(
"> a",
&Options {
- default_line_ending: Some(LineEnding::CarriageReturn),
+ default_line_ending: LineEnding::CarriageReturn,
..Options::default()
}
),
@@ -43,7 +43,7 @@ fn default_line_ending() {
micromark_with_options(
"> a\n",
&Options {
- default_line_ending: Some(LineEnding::CarriageReturn),
+ default_line_ending: LineEnding::CarriageReturn,
..Options::default()
}
),