use std::collections::{BTreeMap, HashMap};
use serde::Deserialize;
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "StringifyOptions"))]
pub struct Stringify {
pub allow_dangerous_html: bool,
pub allow_dangerous_characters: bool,
pub allow_parse_errors: bool,
pub bogus_comments: bool,
pub close_empty_elements: bool,
pub close_self_closing: bool,
pub collapse_empty_attributes: bool,
pub omit_optional_tags: bool,
pub prefer_unquoted: bool,
pub quote: Option<String>,
pub quote_smart: bool,
pub space: Option<String>,
pub tight_attributes: bool,
pub tight_comma_separated_lists: bool,
pub tight_doctype: bool,
pub tight_self_closing: bool,
pub upper_doctype: bool,
pub voids: Option<Vec<String>>,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "ParseOptions"))]
pub struct Parse {
pub fragment: bool,
pub emit_parse_errors: bool,
pub verbose: bool,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "SanitizeOptions"))]
pub struct Sanitize {
pub allow_comments: Option<bool>,
pub allow_doctypes: Option<bool>,
pub ancestors: Option<HashMap<String, Vec<String>>>,
pub attributes: Option<HashMap<String, Vec<AttributeDefinition>>>,
pub clobber: Option<Vec<String>>,
pub clobber_prefix: Option<String>,
pub protocols: Option<HashMap<String, Vec<String>>>,
pub required: Option<HashMap<String, BTreeMap<String, Primitive>>>,
pub strip: Option<Vec<String>>,
pub tag_names: Option<Vec<String>>,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum AttributeDefinition {
Name(String),
Values(Vec<Primitive>),
}
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum Primitive {
Boolean(bool),
Number(f64),
String(String),
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "HighlightOptions"))]
pub struct Highlight {
pub themes: Option<serde_json::Map<String, serde_json::Value>>,
pub theme: Option<String>,
pub default_language: Option<String>,
pub fallback_language: Option<String>,
pub color_replacements: BTreeMap<String, ColorReplacement>,
pub add_language_class: bool,
pub inline: Option<InlineCode>,
pub meta_property: Option<String>,
pub transformers: Vec<HighlightTransformer>,
pub tokenize_max_line_length: Option<usize>,
pub line_attributes: BTreeMap<String, LineMark>,
pub word_attribute: Option<String>,
pub line_number_attribute: Option<String>,
pub skip_elements: bool,
pub keep_properties: bool,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum LineMark {
Line(Classes),
Both {
line: Classes,
#[serde(default)]
pre: Option<Classes>,
},
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum ColorReplacement {
Color(String),
Theme(BTreeMap<String, String>),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum InlineCode {
#[serde(rename = "tailing-curly-colon")]
TailingCurlyColon,
#[serde(rename = "class")]
Class,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum HighlightTransformer {
Name(TransformerName),
Configured(ConfiguredTransformer),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub enum TransformerName {
NotationDiff,
NotationFocus,
NotationHighlight,
NotationErrorLevel,
MetaHighlight,
MetaWordHighlight,
RenderLineNumber,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(tag = "name", rename_all = "camelCase")]
pub enum ConfiguredTransformer {
#[serde(rename_all = "camelCase")]
NotationDiff {
class_line_add: Option<Classes>,
class_line_remove: Option<Classes>,
class_active_pre: Option<Classes>,
class_active_code: Option<Classes>,
},
#[serde(rename_all = "camelCase")]
NotationFocus {
class_active_line: Option<Classes>,
class_active_pre: Option<Classes>,
class_active_code: Option<Classes>,
},
#[serde(rename_all = "camelCase")]
NotationHighlight {
class_active_line: Option<Classes>,
class_active_pre: Option<Classes>,
class_active_code: Option<Classes>,
},
#[serde(rename_all = "camelCase")]
NotationErrorLevel {
class_map: Option<BTreeMap<String, Classes>>,
class_active_pre: Option<Classes>,
class_active_code: Option<Classes>,
},
#[serde(rename_all = "camelCase")]
MetaHighlight {
class_name: Option<Classes>,
#[serde(default)]
zero_indexed: bool,
},
#[serde(rename_all = "camelCase")]
MetaWordHighlight { class_name: Option<Classes> },
#[serde(rename_all = "camelCase")]
RenderLineNumber {
class_line_number: Option<Classes>,
start: Option<usize>,
},
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum Classes {
One(String),
Many(Vec<String>),
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "ExternalLinksOptions"))]
pub struct ExternalLinks {
pub target: Option<String>,
pub rel: Option<Tokens>,
pub protocols: Option<Vec<String>>,
pub properties: Option<serde_json::Map<String, serde_json::Value>>,
pub content: Option<serde_json::Value>,
pub content_properties: Option<serde_json::Map<String, serde_json::Value>>,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum Tokens {
One(String),
Many(Vec<String>),
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "KatexOptions"))]
pub struct Katex {
pub output: Option<KatexOutput>,
pub leqno: bool,
pub fleqn: bool,
pub error_color: Option<String>,
pub macros: BTreeMap<String, String>,
pub min_rule_thickness: Option<f64>,
pub color_is_text_color: bool,
pub strict: Option<KatexStrict>,
pub trust: bool,
pub max_size: Option<f64>,
pub max_expand: Option<usize>,
pub global_group: bool,
pub tag_names: Vec<String>,
}
#[derive(Clone, Copy, Debug, PartialEq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub enum KatexOutput {
Html,
Mathml,
HtmlAndMathml,
}
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum KatexStrict {
Boolean(bool),
Mode(KatexStrictMode),
}
#[derive(Clone, Copy, Debug, PartialEq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub enum KatexStrictMode {
Ignore,
Warn,
Error,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "ExtractTocOptions"))]
pub struct ExtractToc {
pub skip: Vec<String>,
pub skip_inside: Vec<String>,
pub min_depth: Option<u8>,
pub max_depth: Option<u8>,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "SlugOptions"))]
pub struct Slug {
pub prefix: String,
pub reserve_existing: bool,
pub ranks: Option<Vec<u8>>,
pub autolink: Option<Autolink>,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum Autolink {
Enabled(bool),
Options(Box<AutolinkOptions>),
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
pub struct AutolinkOptions {
pub behavior: AutolinkBehavior,
pub properties: Option<serde_json::Map<String, serde_json::Value>>,
pub content: Option<serde_json::Value>,
pub group: Option<serde_json::Value>,
pub heading_properties: Option<serde_json::Map<String, serde_json::Value>>,
pub test: Option<TagNames>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum AutolinkBehavior {
#[default]
Prepend,
Append,
Wrap,
Before,
After,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum TagNames {
One(String),
Many(Vec<String>),
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "ToMarkdownOptions"))]
pub struct ToMarkdown {
pub document: bool,
pub newlines: bool,
pub checked: Option<String>,
pub unchecked: Option<String>,
pub quotes: Option<Vec<String>>,
pub math: bool,
pub code_meta: BTreeMap<String, String>,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "RawOptions"))]
pub struct Raw {
pub pass_through: Vec<String>,
pub tagfilter: bool,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "FormatOptions"))]
pub struct Format {
pub blanks: Vec<String>,
pub indent: Option<Indent>,
pub indent_initial: Option<bool>,
pub minify: Option<Minify>,
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum Minify {
Enabled(bool),
Options(MinifyOptions),
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
pub struct MinifyOptions {
pub newlines: bool,
}
impl Format {
pub(crate) fn minify_newlines(&self) -> Option<bool> {
match &self.minify {
Some(Minify::Enabled(true)) => Some(false),
Some(Minify::Options(options)) => Some(options.newlines),
Some(Minify::Enabled(false)) | None => None,
}
}
}
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
pub enum Indent {
Spaces(usize),
Text(String),
}
pub const PROSE_IGNORE: &[&str] = &[
"a", "code", "pre", "kbd", "samp", "script", "style", "textarea", "title", "math",
"svg",
];
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "MathOptions"))]
pub struct Math {
pub single_dollar_text_math: bool,
pub ignore: Option<Vec<String>>,
pub ignore_attributes: Vec<String>,
}
impl Default for Math {
fn default() -> Self {
Math {
single_dollar_text_math: true,
ignore: None,
ignore_attributes: Vec::new(),
}
}
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "LinkifyOptions"))]
pub struct Linkify {
pub ignore: Option<Vec<String>>,
pub ignore_attributes: Vec<String>,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "GemojiOptions"))]
pub struct Gemoji {
pub accessible: bool,
pub ignore: Option<Vec<String>>,
pub ignore_attributes: Vec<String>,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(default, rename_all = "camelCase")]
#[cfg_attr(feature = "schema", schemars(rename = "PathRewriteOptions"))]
pub struct PathRewrite {
pub root: Option<String>,
pub base: Option<String>,
pub pages: BTreeMap<String, String>,
pub attributes: Option<Vec<String>>,
}