use once_cell::sync::Lazy; #[test] fn title_example() { let parser = &mut markdown_it::MarkdownIt::new(); markdown_it::plugins::cmark::add(parser); let ast = parser.parse("Hello **world**!"); let html = ast.render(); assert_eq!(html, "
Hello world!
\n"); } #[test] fn lazy_singleton() { static MD : LazyHello world!
\n"); } #[test] fn no_plugins() { let md = &mut markdown_it::MarkdownIt::new(); let node = md.parse("hello\nworld"); let result = node.render(); assert_eq!(result, "hello\nworld\n"); } #[test] fn no_max_indent() { let md = &mut markdown_it::MarkdownIt::new(); markdown_it::plugins::cmark::block::paragraph::add(md); markdown_it::plugins::cmark::block::list::add(md); md.max_indent = i32::MAX; let node = md.parse(" paragraph\n - item"); let result = node.render(); assert_eq!(result, "paragraph
\nHello!
"); } #[test] fn regression_list_markers() { run("- foo\n- bar", ""#); } #[test] fn null_char_replacement() { run("", "
foo
foo
\u{FFFD}
"); run("\0", "\u{FFFD}
"); } #[test] fn cr_only_newlines() { run("foo\rbar", "foo\nbar
"); run(" foo\r bar", "foo\nbar\n
");
}
#[test]
fn cr_lf_newlines() {
run("foo\r\nbar", "foo\nbar
"); run(" foo\r\n bar", "foo\nbar\n
");
}
#[test]
fn beautify_links() {
run("www.reddit.com/r/programming/comments/…/ifyqsqt/?…
"); } #[test] fn regression_test_newlines_with_images() { run("There is a newline in this image ![here\nit is](https://github.com/executablebooks/)", "There is a newline in this image
"); } #[test] fn test_node_ext_propagation() { use markdown_it::parser::block::{BlockRule, BlockState}; use markdown_it::parser::core::CoreRule; use markdown_it::parser::extset::NodeExt; use markdown_it::parser::inline::{InlineRule, InlineState}; use markdown_it::{MarkdownIt, Node}; #[derive(Debug, Default)] struct NodeErrors(Vec<&'static str>); impl NodeExt for NodeErrors {} struct MyInlineRule; impl InlineRule for MyInlineRule { const MARKER: char = '@'; fn run(state: &mut InlineState) -> Option<(Node, usize)> { let err = state.node.ext.get_or_insert_default::