use maudit::content::markdown::components::*;
// Custom heading component that adds icons and anchor links
pub struct CustomHeading;
impl HeadingComponent for CustomHeading {
fn render_start(&self, level: u8, id: Option<&str>, classes: &[&str]) -> String {
let id_attr = id.map(|i| format!(" id=\"{}\"", i)).unwrap_or_default();
let class_attr = if classes.is_empty() {
String::new()
} else {
format!(" class=\"{}\"", classes.join(" "))
};
let icon = match level {
1 => "đ¯",
2 => "đ",
3 => "â",
4 => "đš",
5 => "đ¸",
6 => "đ",
_ => "đˇ",
};
format!("
".to_string() } fn render_end(&self) -> String { "
".to_string() } } // Custom link with external link detection pub struct CustomLink; impl LinkComponent for CustomLink { fn render_start(&self, url: &str, title: Option<&str>, _link_type: LinkType) -> String { let title_attr = title .map(|t| format!(" title=\"{}\"", t)) .unwrap_or_default(); let class = if url.starts_with("http") { "external-link" } else { "internal-link" }; format!("", url, class, title_attr) } fn render_end(&self) -> String { "".to_string() } } // Custom image with figure wrapper pub struct CustomImage; impl ImageComponent for CustomImage { fn render(&self, url: &str, alt: &str, title: Option<&str>) -> String { let title_attr = title .map(|t| format!(" title=\"{}\"", t)) .unwrap_or_default(); format!( "{}", code)
}
}
// Custom blockquote with different styles per type
pub struct CustomBlockquote;
impl BlockquoteComponent for CustomBlockquote {
fn render_start(&self, kind: Option".to_string(), Some(BlockQuoteKind::Tip) => "".to_string(), Some(BlockQuoteKind::Warning) => "".to_string(), Some(BlockQuoteKind::Important) => "".to_string(), Some(BlockQuoteKind::Caution) => "".to_string() } else { "".to_string() } } } // Custom hard break pub struct CustomHardBreak; impl HardBreakComponent for CustomHardBreak { fn render(&self) -> String { "".to_string(), None => "".to_string(), } } fn render_end(&self, kind: Option) -> String { if kind.is_some() { "
".to_string() } } // Custom horizontal rule pub struct CustomHorizontalRule; impl HorizontalRuleComponent for CustomHorizontalRule { fn render(&self) -> String { "
".to_string() } } // Custom list with different styling pub struct CustomList; impl ListComponent for CustomList { fn render_start(&self, list_type: ListType, start_number: Option) -> String { match list_type { ListType::Ordered => { let start_attr = start_number .map(|n| format!(" start=\"{}\"", n)) .unwrap_or_default(); format!(" ", start_attr) } ListType::Unordered => { "
".to_string(), ListType::Unordered => "".to_string(), } } } // Custom list item pub struct CustomListItem; impl ListItemComponent for CustomListItem { fn render_start(&self) -> String { "".to_string() } } } fn render_end(&self, list_type: ListType) -> String { match list_type { ListType::Ordered => "
".to_string() } fn render_end(&self) -> String { " ".to_string() } } // Custom strikethrough pub struct CustomStrikethrough; impl StrikethroughComponent for CustomStrikethrough { fn render_start(&self) -> String { "".to_string() } fn render_end(&self) -> String { "".to_string() } } // Custom task list marker pub struct CustomTaskListMarker; impl TaskListMarkerComponent for CustomTaskListMarker { fn render(&self, checked: bool) -> String { if checked { "".to_string() } else { "".to_string() } } } // Custom table pub struct CustomTable; impl TableComponent for CustomTable { fn render_start(&self, _alignments: &[TableAlignment]) -> String { "".to_string() } fn render_end(&self) -> String { "
".to_string() } } // Custom table head pub struct CustomTableHead; impl TableHeadComponent for CustomTableHead { fn render_start(&self) -> String { "".to_string() } fn render_end(&self) -> String { "".to_string() } } // Custom table row pub struct CustomTableRow; impl TableRowComponent for CustomTableRow { fn render_start(&self) -> String { "".to_string() } fn render_end(&self) -> String { " ".to_string() } } // Custom table cell pub struct CustomTableCell; impl TableCellComponent for CustomTableCell { fn render_start(&self, is_header: bool, alignment: Option) -> String { let tag = if is_header { "th" } else { "td" }; let mut class = "table-cell".to_string(); match alignment { Some(TableAlignment::Center) => class.push_str(" center"), Some(TableAlignment::Right) => class.push_str(" right"), _ => {} }; format!("<{} class=\"{}\">", tag, class) } fn render_end(&self, is_header: bool) -> String { let tag = if is_header { "th" } else { "td" }; format!("{}>", tag) } }