Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Options (De)serialisable with serde #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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<Box<MdxExpressionParse>>,

/// Function to parse ESM with.
Expand All @@ -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<Box<MdxEsmParse>>,
// Note: when adding fields, don’t forget to add them to `fmt::Debug` below.
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 4 additions & 0 deletions src/util/line_ending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
///
Expand All @@ -25,6 +26,7 @@ pub enum LineEnding {
/// a␍␊
/// b
/// ```
#[cfg_attr(feature = "serde", serde(rename = "\r\n"))]
CarriageReturnLineFeed,
/// Sole carriage return (`\r`).
///
Expand All @@ -34,6 +36,7 @@ pub enum LineEnding {
/// a␍
/// b
/// ```
#[cfg_attr(feature = "serde", serde(rename = "\r"))]
CarriageReturn,
/// Sole line feed (`\n`).
///
Expand All @@ -44,6 +47,7 @@ pub enum LineEnding {
/// b
/// ```
#[default]
#[cfg_attr(feature = "serde", serde(rename = "\n"))]
LineFeed,
}

Expand Down