#[derive(Debug, Clone)]
pub struct MarkdownConfig {
pub enable_gfm: bool,
pub enable_footnotes: bool,
pub enable_definition_lists: bool,
pub enable_super_sub: bool,
pub max_heading_level: usize,
pub min_heading_level: usize,
pub include_code_blocks: bool,
pub include_images: bool,
pub include_links: bool,
pub include_tables: bool,
pub parse_frontmatter: bool,
pub parse_toml_frontmatter: bool,
pub frontmatter_fields: Vec<String>,
pub min_heading_chars: usize,
pub create_preamble_node: bool,
pub preamble_title: String,
}
impl Default for MarkdownConfig {
fn default() -> Self {
Self {
enable_gfm: true,
enable_footnotes: false,
enable_definition_lists: false,
enable_super_sub: false,
max_heading_level: 6,
min_heading_level: 1,
include_code_blocks: true,
include_images: true,
include_links: true,
include_tables: true,
parse_frontmatter: true,
parse_toml_frontmatter: false,
frontmatter_fields: vec!["title".into(), "description".into()],
min_heading_chars: 1,
create_preamble_node: true,
preamble_title: "Introduction".into(),
}
}
}
impl MarkdownConfig {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn gfm() -> Self {
Self::default()
}
#[must_use]
pub fn commonmark() -> Self {
Self {
enable_gfm: false,
..Self::default()
}
}
#[must_use]
pub fn documentation() -> Self {
Self {
enable_footnotes: true,
enable_definition_lists: true,
..Self::default()
}
}
#[must_use]
pub fn no_code_blocks() -> Self {
Self {
include_code_blocks: false,
..Self::default()
}
}
#[must_use]
pub fn with_max_heading_level(mut self, level: usize) -> Self {
self.max_heading_level = level.clamp(1, 6);
self
}
#[must_use]
pub fn with_code_blocks(mut self, include: bool) -> Self {
self.include_code_blocks = include;
self
}
#[must_use]
pub fn with_frontmatter(mut self, parse: bool) -> Self {
self.parse_frontmatter = parse;
self
}
#[must_use]
pub fn with_preamble_title(mut self, title: impl Into<String>) -> Self {
self.preamble_title = title.into();
self
}
}