#[derive(Debug, Clone)]
pub struct MarkdownOptions {
pub include_styles: bool,
pub include_metadata: bool,
pub table_style: TableStyle,
pub html_table_indent: usize,
pub formula_style: FormulaStyle,
pub list_indent: usize,
pub script_style: ScriptStyle,
pub strikethrough_style: StrikethroughStyle,
}
impl Default for MarkdownOptions {
fn default() -> Self {
Self {
include_styles: true,
include_metadata: false,
table_style: TableStyle::Markdown,
html_table_indent: 2,
formula_style: FormulaStyle::LaTeX,
list_indent: 2,
script_style: ScriptStyle::Html,
strikethrough_style: StrikethroughStyle::Markdown,
}
}
}
impl MarkdownOptions {
#[inline]
pub fn new() -> Self {
Self::default()
}
#[inline]
pub fn with_styles(mut self, include: bool) -> Self {
self.include_styles = include;
self
}
#[inline]
pub fn with_metadata(mut self, include: bool) -> Self {
self.include_metadata = include;
self
}
#[inline]
pub fn with_table_style(mut self, style: TableStyle) -> Self {
self.table_style = style;
self
}
#[inline]
pub fn with_html_table_indent(mut self, indent: usize) -> Self {
self.html_table_indent = indent;
self
}
#[inline]
pub fn with_formula_style(mut self, style: FormulaStyle) -> Self {
self.formula_style = style;
self
}
#[inline]
pub fn with_list_indent(mut self, indent: usize) -> Self {
self.list_indent = indent;
self
}
#[inline]
pub fn with_script_style(mut self, style: ScriptStyle) -> Self {
self.script_style = style;
self
}
#[inline]
pub fn with_strikethrough_style(mut self, style: StrikethroughStyle) -> Self {
self.strikethrough_style = style;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TableStyle {
Markdown,
MinimalHtml,
StyledHtml,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FormulaStyle {
LaTeX,
Dollar,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ScriptStyle {
Html,
Unicode,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StrikethroughStyle {
Markdown,
Html,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_markdown_options_builder() {
let options = MarkdownOptions::new()
.with_styles(true)
.with_metadata(false)
.with_table_style(TableStyle::MinimalHtml)
.with_html_table_indent(4)
.with_formula_style(FormulaStyle::Dollar)
.with_list_indent(4)
.with_script_style(ScriptStyle::Unicode)
.with_strikethrough_style(StrikethroughStyle::Html);
assert!(options.include_styles);
assert!(!options.include_metadata);
assert_eq!(options.table_style, TableStyle::MinimalHtml);
assert_eq!(options.html_table_indent, 4);
assert_eq!(options.formula_style, FormulaStyle::Dollar);
assert_eq!(options.list_indent, 4);
assert_eq!(options.script_style, ScriptStyle::Unicode);
assert_eq!(options.strikethrough_style, StrikethroughStyle::Html);
}
#[test]
fn test_markdown_options_default() {
let options = MarkdownOptions::default();
assert!(options.include_styles);
assert!(!options.include_metadata);
assert_eq!(options.table_style, TableStyle::Markdown);
assert_eq!(options.html_table_indent, 2);
assert_eq!(options.formula_style, FormulaStyle::LaTeX);
assert_eq!(options.list_indent, 2);
assert_eq!(options.script_style, ScriptStyle::Html);
assert_eq!(options.strikethrough_style, StrikethroughStyle::Markdown);
}
}