diff --git a/src/configuration.rs b/src/configuration.rs index fe5698bb..57efa219 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -31,6 +31,11 @@ use alloc::{boxed::Box, fmt, string::String}; /// ``` #[allow(clippy::struct_excessive_bools)] #[derive(Clone, Debug, Eq, PartialEq)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "camelCase") +)] pub struct Constructs { /// Attention. /// @@ -467,6 +472,11 @@ impl Constructs { /// ``` #[allow(clippy::struct_excessive_bools)] #[derive(Clone, Debug, Default)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(default, rename_all = "camelCase") +)] pub struct CompileOptions { /// Whether to allow (dangerous) HTML. /// @@ -930,6 +940,11 @@ impl CompileOptions { /// # } /// ``` #[allow(clippy::struct_excessive_bools)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(default, rename_all = "camelCase") +)] pub struct ParseOptions { // Note: when adding fields, don’t forget to add them to `fmt::Debug` below. /// Which constructs to enable and disable. @@ -968,6 +983,7 @@ pub struct ParseOptions { /// # Ok(()) /// # } /// ``` + #[cfg_attr(feature = "serde", serde(default))] pub constructs: Constructs, /// Whether to support GFM strikethrough with a single tilde @@ -1020,6 +1036,7 @@ pub struct ParseOptions { /// # Ok(()) /// # } /// ``` + #[cfg_attr(feature = "serde", serde(default))] pub gfm_strikethrough_single_tilde: bool, /// Whether to support math (text) with a single dollar @@ -1079,6 +1096,7 @@ pub struct ParseOptions { /// # Ok(()) /// # } /// ``` + #[cfg_attr(feature = "serde", serde(default))] pub math_text_single_dollar: bool, /// Function to parse expressions with. @@ -1091,6 +1109,7 @@ pub struct ParseOptions { /// /// For an example that adds support for JavaScript with SWC, see /// `tests/test_utils/mod.rs`. + #[cfg_attr(feature = "serde", serde(skip))] pub mdx_expression_parse: Option>, /// Function to parse ESM with. @@ -1107,6 +1126,8 @@ pub struct ParseOptions { /// /// For an example that adds support for JavaScript with SWC, see /// `tests/test_utils/mod.rs`. + /// + #[cfg_attr(feature = "serde", serde(skip))] pub mdx_esm_parse: Option>, // Note: when adding fields, don’t forget to add them to `fmt::Debug` below. } @@ -1208,6 +1229,11 @@ impl ParseOptions { /// ``` #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Default)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(default) +)] pub struct Options { /// Configuration that describes how to parse from markdown. pub parse: ParseOptions, diff --git a/src/lib.rs b/src/lib.rs index 584861ef..46a8e5c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ //! * **`default`** //! — nothing is enabled by default //! * **`serde`** -//! — enable serde to serialize the AST (includes `dep:serde`) +//! — enable serde to serialize the AST and configuration objects (includes `dep:serde`) //! * **`log`** //! — enable logging (includes `dep:log`); //! you can show logs with `RUST_LOG=debug` diff --git a/src/util/line_ending.rs b/src/util/line_ending.rs index be4d8a33..93068b33 100644 --- a/src/util/line_ending.rs +++ b/src/util/line_ending.rs @@ -16,6 +16,7 @@ use alloc::{str::FromStr, string::String}; /// # } /// ``` #[derive(Clone, Debug, Default, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum LineEnding { /// Both a carriage return (`\r`) and a line feed (`\n`). /// @@ -25,6 +26,7 @@ pub enum LineEnding { /// a␍␊ /// b /// ``` + #[cfg_attr(feature = "serde", serde(rename = "\r\n"))] CarriageReturnLineFeed, /// Sole carriage return (`\r`). /// @@ -34,6 +36,7 @@ pub enum LineEnding { /// a␍ /// b /// ``` + #[cfg_attr(feature = "serde", serde(rename = "\r"))] CarriageReturn, /// Sole line feed (`\n`). /// @@ -44,6 +47,7 @@ pub enum LineEnding { /// b /// ``` #[default] + #[cfg_attr(feature = "serde", serde(rename = "\n"))] LineFeed, }