use pulldown_cmark::{Options, Parser, html}; /// Format the startup greeting the bot sends to each room when it comes online. /// /// Uses the bot's configured display name so the message reads naturally /// (e.g. "Timmy is online."). pub fn format_startup_announcement(bot_name: &str) -> String { format!("{bot_name} is online.") } /// Convert a Markdown string to an HTML string using pulldown-cmark. /// /// Enables the standard extension set (tables, footnotes, strikethrough, /// tasklists) so that common Markdown constructs render correctly in Matrix /// clients such as Element. pub fn markdown_to_html(markdown: &str) -> String { let normalized = crate::chat::util::normalize_line_breaks(markdown); let options = Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES | Options::ENABLE_STRIKETHROUGH | Options::ENABLE_TASKLISTS; let parser = Parser::new_ext(&normalized, options); let mut html_output = String::new(); html::push_html(&mut html_output, parser); html_output } // --------------------------------------------------------------------------- // Tests // --------------------------------------------------------------------------- #[cfg(test)] mod tests { use super::*; #[test] fn markdown_to_html_bold() { let html = markdown_to_html("**bold**"); assert!( html.contains("bold"), "expected : {html}" ); } #[test] fn markdown_to_html_unordered_list() { let html = markdown_to_html("- item one\n- item two"); assert!(html.contains("