use crate::mdx_plugin_recma_document::JsxRuntime;
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serializable", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serializable", serde(rename_all = "camelCase", default))]
pub struct MdxConstructs {
pub attention: bool,
pub block_quote: bool,
pub character_escape: bool,
pub character_reference: bool,
pub code_fenced: bool,
pub code_text: bool,
pub definition: bool,
pub frontmatter: bool,
pub gfm_autolink_literal: bool,
pub gfm_footnote_definition: bool,
pub gfm_label_start_footnote: bool,
pub gfm_strikethrough: bool,
pub gfm_table: bool,
pub gfm_task_list_item: bool,
pub hard_break_escape: bool,
pub hard_break_trailing: bool,
pub heading_atx: bool,
pub heading_setext: bool,
pub label_start_image: bool,
pub label_start_link: bool,
pub label_end: bool,
pub list_item: bool,
pub math_flow: bool,
pub math_text: bool,
pub thematic_break: bool,
}
impl Default for MdxConstructs {
fn default() -> Self {
Self {
attention: true,
block_quote: true,
character_escape: true,
character_reference: true,
code_fenced: true,
code_text: true,
definition: true,
frontmatter: false,
gfm_autolink_literal: false,
gfm_label_start_footnote: false,
gfm_footnote_definition: false,
gfm_strikethrough: false,
gfm_table: false,
gfm_task_list_item: false,
hard_break_escape: true,
hard_break_trailing: true,
heading_atx: true,
heading_setext: true,
label_start_image: true,
label_start_link: true,
label_end: true,
list_item: true,
math_flow: false,
math_text: false,
thematic_break: true,
}
}
}
impl MdxConstructs {
pub fn gfm() -> Self {
Self {
gfm_autolink_literal: true,
gfm_footnote_definition: true,
gfm_label_start_footnote: true,
gfm_strikethrough: true,
gfm_table: true,
gfm_task_list_item: true,
..Self::default()
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serializable", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serializable", serde(rename_all = "camelCase", default))]
pub struct MdxParseOptions {
pub constructs: MdxConstructs,
pub gfm_strikethrough_single_tilde: bool,
pub math_text_single_dollar: bool,
}
impl Default for MdxParseOptions {
fn default() -> Self {
Self {
constructs: MdxConstructs::default(),
gfm_strikethrough_single_tilde: true,
math_text_single_dollar: true,
}
}
}
impl MdxParseOptions {
pub fn gfm() -> Self {
Self {
constructs: MdxConstructs::gfm(),
..Self::default()
}
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serializable", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serializable", serde(rename_all = "camelCase", default))]
pub struct Options {
pub parse: MdxParseOptions,
pub development: bool,
pub provider_import_source: Option<String>,
pub jsx: bool,
pub jsx_runtime: Option<JsxRuntime>,
pub jsx_import_source: Option<String>,
pub pragma: Option<String>,
pub pragma_frag: Option<String>,
pub pragma_import_source: Option<String>,
pub filepath: Option<String>,
}
impl Default for Options {
fn default() -> Self {
Self {
parse: MdxParseOptions::default(),
development: false,
provider_import_source: None,
jsx: false,
jsx_runtime: Some(JsxRuntime::default()),
jsx_import_source: None,
pragma: None,
pragma_frag: None,
pragma_import_source: None,
filepath: None,
}
}
}
impl Options {
pub fn gfm() -> Self {
Self {
parse: MdxParseOptions::gfm(),
..Self::default()
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_constructs() {
let constructs = MdxConstructs::default();
assert!(constructs.attention, "should default to `CommonMark` (1)");
assert!(
!constructs.gfm_autolink_literal,
"should default to `CommonMark` (2)"
);
assert!(
!constructs.frontmatter,
"should default to `CommonMark` (3)"
);
let constructs = MdxConstructs::gfm();
assert!(constructs.attention, "should support `gfm` shortcut (1)");
assert!(
constructs.gfm_autolink_literal,
"should support `gfm` shortcut (2)"
);
assert!(!constructs.frontmatter, "should support `gfm` shortcut (3)");
}
#[test]
fn test_parse_options() {
let options = MdxParseOptions::default();
assert!(
options.constructs.attention,
"should default to `CommonMark` (1)"
);
assert!(
!options.constructs.gfm_autolink_literal,
"should default to `CommonMark` (2)"
);
assert!(
!options.constructs.frontmatter,
"should default to `CommonMark` (3)"
);
let options = MdxParseOptions::gfm();
assert!(
options.constructs.attention,
"should support `gfm` shortcut (1)"
);
assert!(
options.constructs.gfm_autolink_literal,
"should support `gfm` shortcut (2)"
);
assert!(
!options.constructs.frontmatter,
"should support `gfm` shortcut (3)"
);
}
#[test]
fn test_options() {
let options = Options::default();
assert!(
options.parse.constructs.attention,
"should default to `CommonMark` (1)"
);
assert!(
!options.parse.constructs.gfm_autolink_literal,
"should default to `CommonMark` (2)"
);
assert!(
!options.parse.constructs.frontmatter,
"should default to `CommonMark` (3)"
);
let options = Options::gfm();
assert!(
options.parse.constructs.attention,
"should support `gfm` shortcut (1)"
);
assert!(
options.parse.constructs.gfm_autolink_literal,
"should support `gfm` shortcut (2)"
);
assert!(
!options.parse.constructs.frontmatter,
"should support `gfm` shortcut (3)"
);
}
}