use crate::util::line_ending::LineEnding;
use alloc::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 {
pub attention: bool,
pub autolink: bool,
pub block_quote: bool,
pub character_escape: bool,
pub character_reference: bool,
pub code_indented: bool,
pub code_fenced: bool,
pub code_text: bool,
pub definition: bool,
pub frontmatter: bool,
pub autolink_literal: bool,
pub footnote_definition: bool,
pub label_start_footnote: bool,
pub strikethrough: bool,
pub table: bool,
pub task_list_item: bool,
pub hard_break_escape: bool,
pub hard_break_trailing: bool,
pub heading_atx: bool,
pub heading_setext: bool,
pub html_flow: bool,
pub html_text: 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 Constructs {
fn default() -> Self {
Self {
attention: true,
autolink: true,
block_quote: true,
character_escape: true,
character_reference: true,
code_indented: true,
code_fenced: true,
code_text: true,
definition: true,
frontmatter: false,
autolink_literal: false,
label_start_footnote: false,
footnote_definition: false,
strikethrough: false,
table: false,
task_list_item: false,
hard_break_escape: true,
hard_break_trailing: true,
heading_atx: true,
heading_setext: true,
html_flow: true,
html_text: 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 Constructs {
pub fn gfm() -> Self {
Self {
autolink_literal: true,
footnote_definition: true,
label_start_footnote: true,
strikethrough: true,
table: true,
task_list_item: true,
..Self::default()
}
}
}
#[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 {
pub allow_any_img_src: bool,
pub allow_dangerous_html: bool,
pub allow_dangerous_protocol: bool,
#[allow(clippy::doc_markdown)]
pub default_line_ending: LineEnding,
pub footnote_back_label: Option<String>,
pub footnote_clobber_prefix: Option<String>,
pub footnote_label_attributes: Option<String>,
pub footnote_label_tag_name: Option<String>,
pub footnote_label: Option<String>,
pub task_list_item_checkable: bool,
pub tagfilter: bool,
pub heading_ids: bool,
}
impl CompileOptions {
pub fn gfm() -> Self {
Self {
tagfilter: true,
..Self::default()
}
}
}
#[allow(clippy::struct_excessive_bools)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(default, rename_all = "camelCase")
)]
#[derive(Debug)]
pub struct ParseOptions {
#[cfg_attr(feature = "serde", serde(default))]
pub constructs: Constructs,
#[cfg_attr(feature = "serde", serde(default))]
pub inline_code_info: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub html_block_blank_lines: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub html_tag_namespaces: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub strikethrough_single_tilde: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub math_text_single_dollar: bool,
}
impl Default for ParseOptions {
fn default() -> Self {
Self {
constructs: Constructs::default(),
inline_code_info: false,
html_block_blank_lines: false,
html_tag_namespaces: false,
strikethrough_single_tilde: true,
math_text_single_dollar: true,
}
}
}
impl ParseOptions {
pub fn gfm() -> Self {
Self {
constructs: Constructs::gfm(),
..Self::default()
}
}
}
#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Default)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(default)
)]
pub struct Options {
pub parse: ParseOptions,
pub compile: CompileOptions,
}
impl Options {
pub fn gfm() -> Self {
Self {
parse: ParseOptions::gfm(),
compile: CompileOptions::gfm(),
}
}
}
#[cfg(test)]
#[path = "configuration/tests.rs"]
mod tests;