use markdown::{ mdast::{Code, Node, Root}, to_html, to_html_with_options, to_mdast, unist::Position, CompileOptions, Constructs, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn code_indented() -> Result<(), String> { assert_eq!( to_html(" a simple\n indented code block"), "
a simple\n indented code block\n
",
"should support indented code"
);
assert_eq!(
to_html(" - foo\n\n bar"),
"foo
\nbar
\nfoo
\n<a/>\n*hi*\n\n- one\n
",
"should support blank lines in indented code (1)"
);
assert_eq!(
to_html(" chunk1\n\n chunk2\n \n \n \n chunk3"),
"chunk1\n\nchunk2\n\n\n\nchunk3\n
",
"should support blank lines in indented code (2)"
);
assert_eq!(
to_html(" chunk1\n \n chunk2"),
"chunk1\n \n chunk2\n
",
"should support blank lines in indented code (3)"
);
assert_eq!(
to_html("Foo\n bar"),
"Foo\nbar
", "should not support interrupting paragraphs" ); assert_eq!( to_html(" foo\nbar"), "foo\n
\nbar
", "should support paragraphs directly after indented code" ); assert_eq!( to_html("# Heading\n foo\nHeading\n------\n foo\n----"), "foo\n
\nfoo\n
\n foo\nbar\n
",
"should support extra whitespace on the first line"
);
assert_eq!(
to_html("\n \n foo\n "),
"foo\n
",
"should not support initial blank lines"
);
assert_eq!(
to_html(" foo "),
"foo \n
",
"should support trailing whitespace"
);
assert_eq!(
to_html("> a\nb"),
"\n\n\na\n
b
", "should not support lazyness (1)" ); assert_eq!( to_html("> a\n b"), "\n", "should not support lazyness (2)" ); assert_eq!( to_html("> a\n b"), "a\nb
\n
\n", "should not support lazyness (3)" ); assert_eq!( to_html("> a\n b"), "a\nb
\n
\n", "should not support lazyness (4)" ); assert_eq!( to_html("> a\n b"), "a\nb
\n
\n\n\na\n
b\n
",
"should not support lazyness (5)"
);
assert_eq!(
to_html("> a\n b"),
"\n\n\na\n
b\n
",
"should not support lazyness (6)"
);
assert_eq!(
to_html("> a\n b"),
"\n\n\na\n
b\n
",
"should not support lazyness (7)"
);
let off = Options {
parse: ParseOptions {
constructs: Constructs {
code_indented: false,
..Default::default()
},
..Default::default()
},
..Default::default()
};
assert_eq!(
to_html_with_options(" a", &off)?,
"a
", "should support turning off code (indented, 1)" ); assert_eq!( to_html_with_options("> a\n b", &off)?, "\n", "should support turning off code (indented, 2)" ); assert_eq!( to_html_with_options("- a\n b", &off)?, "a\nb
\n
a\n
",
"should support turning off code (indented, 6)"
);
assert_eq!(
to_html_with_options(
"a \n ?>",
&Options {
parse: ParseOptions {
constructs: Constructs {
code_indented: false,
..Default::default()
},
..Default::default()
},
compile: CompileOptions {
allow_dangerous_html: true,
..Default::default()
}
}
)?,
"a \n?>
", "should support turning off code (indented, 7)" ); assert_eq!( to_html_with_options("- Foo\n---", &off)?, "