use comrak::{ Arena, Options, create_formatter, html::ChildRendering, nodes::NodeValue, parse_document, }; use std::fmt::Write; create_formatter!(ExternalLinkFormatter, { NodeValue::Link(ref nl) => |context, node, entering| { let skip = context.options.parse.relaxed_autolinks && node.parent().is_some_and(|p| comrak::node_matches!(p, NodeValue::Link(..))); if skip { return Ok(ChildRendering::HTML); } if entering { context.write_str("", )?; } else { context.write_str("")?; } }, }); pub fn parse_markdown(input: &str) -> String { let mut options = Options::default(); options.extension.strikethrough = true; options.extension.table = true; options.extension.tasklist = true; options.extension.autolink = true; options.render.r#unsafe = true; let arena = Arena::new(); let doc = parse_document(&arena, input, &options); let mut html = String::new(); ExternalLinkFormatter::format_document(doc, &options, &mut html).unwrap_or_default(); html } #[tauri::command] #[specta::specta] pub async fn parse_markdown_command(markdown: String) -> Result { Ok(parse_markdown(&markdown)) }