#[derive(Debug, Clone)]
pub struct WriterOptions {
pub strict: bool,
pub hard_break_spaces: bool,
pub indent_spaces: usize,
pub list_marker: char,
pub thematic_break_char: char,
pub emphasis_char: char,
pub strong_char: char,
#[cfg(feature = "gfm")]
pub enable_gfm: bool,
#[cfg(feature = "gfm")]
pub gfm_strikethrough: bool,
#[cfg(feature = "gfm")]
pub gfm_tasklists: bool,
#[cfg(feature = "gfm")]
pub gfm_tables: bool,
#[cfg(feature = "gfm")]
pub gfm_autolinks: bool,
#[cfg(feature = "gfm")]
pub gfm_disallowed_html_tags: Vec<String>,
}
impl Default for WriterOptions {
fn default() -> Self {
Self {
strict: true,
hard_break_spaces: false,
indent_spaces: 4,
list_marker: '-',
thematic_break_char: '-',
emphasis_char: '_',
strong_char: '*',
#[cfg(feature = "gfm")]
enable_gfm: false,
#[cfg(feature = "gfm")]
gfm_strikethrough: false,
#[cfg(feature = "gfm")]
gfm_tasklists: false,
#[cfg(feature = "gfm")]
gfm_tables: false,
#[cfg(feature = "gfm")]
gfm_autolinks: false,
#[cfg(feature = "gfm")]
gfm_disallowed_html_tags: vec![
"title".to_string(),
"textarea".to_string(),
"style".to_string(),
"xmp".to_string(),
"iframe".to_string(),
"noembed".to_string(),
"noframes".to_string(),
"script".to_string(),
"plaintext".to_string(),
],
}
}
}
pub struct WriterOptionsBuilder {
options: WriterOptions,
}
impl WriterOptionsBuilder {
pub fn new() -> Self {
Self {
options: WriterOptions::default(),
}
}
pub fn strict(mut self, strict: bool) -> Self {
self.options.strict = strict;
self
}
pub fn hard_break_spaces(mut self, hard_break_spaces: bool) -> Self {
self.options.hard_break_spaces = hard_break_spaces;
self
}
pub fn indent_spaces(mut self, indent_spaces: usize) -> Self {
self.options.indent_spaces = indent_spaces;
self
}
pub fn list_marker(mut self, marker: char) -> Self {
if marker == '-' || marker == '+' || marker == '*' {
self.options.list_marker = marker;
}
self
}
pub fn thematic_break_char(mut self, char: char) -> Self {
if char == '-' || char == '*' || char == '_' {
self.options.thematic_break_char = char;
}
self
}
pub fn emphasis_char(mut self, char: char) -> Self {
if char == '_' || char == '*' {
self.options.emphasis_char = char;
}
self
}
pub fn strong_char(mut self, char: char) -> Self {
if char == '_' || char == '*' {
self.options.strong_char = char;
}
self
}
#[cfg(feature = "gfm")]
pub fn enable_gfm(mut self) -> Self {
self.options.enable_gfm = true;
self.options.gfm_strikethrough = true;
self.options.gfm_tasklists = true;
self.options.gfm_tables = true;
self.options.gfm_autolinks = true;
self
}
#[cfg(feature = "gfm")]
pub fn gfm_strikethrough(mut self, enable: bool) -> Self {
self.options.gfm_strikethrough = enable;
if enable {
self.options.enable_gfm = true;
}
self
}
#[cfg(feature = "gfm")]
pub fn gfm_tasklists(mut self, enable: bool) -> Self {
self.options.gfm_tasklists = enable;
if enable {
self.options.enable_gfm = true;
}
self
}
#[cfg(feature = "gfm")]
pub fn gfm_tables(mut self, enable: bool) -> Self {
self.options.gfm_tables = enable;
if enable {
self.options.enable_gfm = true;
}
self
}
#[cfg(feature = "gfm")]
pub fn gfm_autolinks(mut self, enable: bool) -> Self {
self.options.gfm_autolinks = enable;
if enable {
self.options.enable_gfm = true;
}
self
}
#[cfg(feature = "gfm")]
pub fn gfm_disallowed_html_tags(mut self, tags: Vec<String>) -> Self {
self.options.gfm_disallowed_html_tags = tags;
self
}
pub fn build(self) -> WriterOptions {
self.options
}
}
impl Default for WriterOptionsBuilder {
fn default() -> Self {
Self::new()
}
}