use markdown::{to_html, to_html_with_options, CompileOptions, Options}; use pretty_assertions::assert_eq; #[test] fn line_ending() -> Result<(), String> { let danger = &Options { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, ..Default::default() }, ..Default::default() }; assert_eq!(to_html("\n"), "", "should support just a line feed"); assert_eq!(to_html("\r"), "", "should support just a carriage return"); assert_eq!( to_html("\r\n"), "", "should support just a carriage return + line feed" ); assert_eq!(to_html("\n\n"), "", "should support just two line feeds"); assert_eq!( to_html("\r\r"), "", "should support just two carriage return" ); assert_eq!( to_html("\r\n\r\n"), "", "should support just two carriage return + line feeds" ); assert_eq!( to_html("a\nb"), "

a\nb

", "should support a line feed for a line ending inside a paragraph" ); assert_eq!( to_html("a\rb"), "

a\rb

", "should support a carriage return for a line ending inside a paragraph" ); assert_eq!( to_html("a\r\nb"), "

a\r\nb

", "should support a carriage return + line feed for a line ending inside a paragraph" ); assert_eq!( to_html("\ta\n\tb"), "
a\nb\n
", "should support a line feed in indented code (and prefer it)" ); assert_eq!( to_html("\ta\r\tb"), "
a\rb\r
", "should support a carriage return in indented code (and prefer it)" ); assert_eq!( to_html("\ta\r\n\tb"), "
a\r\nb\r\n
", "should support a carriage return + line feed in indented code (and prefer it)" ); assert_eq!( to_html("***\n### Heading"), "
\n

Heading

", "should support a line feed between flow" ); assert_eq!( to_html("***\r### Heading"), "
\r

Heading

", "should support a carriage return between flow" ); assert_eq!( to_html("***\r\n### Heading"), "
\r\n

Heading

", "should support a carriage return + line feed between flow" ); assert_eq!( to_html("***\n\n\n### Heading\n"), "
\n

Heading

\n", "should support several line feeds between flow" ); assert_eq!( to_html("***\r\r\r### Heading\r"), "
\r

Heading

\r", "should support several carriage returns between flow" ); assert_eq!( to_html("***\r\n\r\n\r\n### Heading\r\n"), "
\r\n

Heading

\r\n", "should support several carriage return + line feeds between flow" ); assert_eq!( to_html("```x\n\n\ny\n\n\n```\n\n\n"), "
\n\ny\n\n\n
\n", "should support several line feeds in fenced code" ); assert_eq!( to_html("```x\r\r\ry\r\r\r```\r\r\r"), "
\r\ry\r\r\r
\r", "should support several carriage returns in fenced code" ); assert_eq!( to_html("```x\r\n\r\n\r\ny\r\n\r\n\r\n```\r\n\r\n\r\n"), "
\r\n\r\ny\r\n\r\n\r\n
\r\n", "should support several carriage return + line feeds in fenced code" ); assert_eq!( to_html("A\r\nB\r\n-\r\nC"), "

A\r\nB

\r\n

C

", "should support a carriage return + line feed in content" ); assert_eq!( to_html_with_options("\n\nx", danger)?, "
\n

x

", "should support a blank line w/ line feeds after html" ); assert_eq!( to_html_with_options("
\r\rx", danger)?, "
\r

x

", "should support a blank line w/ carriage returns after html" ); assert_eq!( to_html_with_options("
\r\n\r\nx", danger)?, "
\r\n

x

", "should support a blank line w/ carriage return + line feeds after html" ); assert_eq!( to_html_with_options("
\nx", danger)?, "
\nx", "should support a non-blank line w/ line feed in html" ); assert_eq!( to_html_with_options("
\rx", danger)?, "
\rx", "should support a non-blank line w/ carriage return in html" ); assert_eq!( to_html_with_options("
\r\nx", danger)?, "
\r\nx", "should support a non-blank line w/ carriage return + line feed in html" ); Ok(()) }