Markdown parser fork with extended syntax for personal use.
at hack 190 lines 5.3 kB view raw
1use markdown::{message, to_html, to_html_with_options, CompileOptions, Options}; 2use pretty_assertions::assert_eq; 3 4#[test] 5fn line_ending() -> Result<(), message::Message> { 6 let danger = &Options { 7 compile: CompileOptions { 8 allow_dangerous_html: true, 9 allow_dangerous_protocol: true, 10 ..Default::default() 11 }, 12 ..Default::default() 13 }; 14 15 assert_eq!(to_html("\n"), "", "should support just a line feed"); 16 17 assert_eq!(to_html("\r"), "", "should support just a carriage return"); 18 19 assert_eq!( 20 to_html("\r\n"), 21 "", 22 "should support just a carriage return + line feed" 23 ); 24 25 assert_eq!(to_html("\n\n"), "", "should support just two line feeds"); 26 27 assert_eq!( 28 to_html("\r\r"), 29 "", 30 "should support just two carriage return" 31 ); 32 33 assert_eq!( 34 to_html("\r\n\r\n"), 35 "", 36 "should support just two carriage return + line feeds" 37 ); 38 39 assert_eq!( 40 to_html("a\nb"), 41 "<p>a\nb</p>", 42 "should support a line feed for a line ending inside a paragraph" 43 ); 44 45 assert_eq!( 46 to_html("a\rb"), 47 "<p>a\rb</p>", 48 "should support a carriage return for a line ending inside a paragraph" 49 ); 50 51 assert_eq!( 52 to_html("a\r\nb"), 53 "<p>a\r\nb</p>", 54 "should support a carriage return + line feed for a line ending inside a paragraph" 55 ); 56 57 assert_eq!( 58 to_html("\ta\n\tb"), 59 "<pre><code>a\nb\n</code></pre>", 60 "should support a line feed in indented code (and prefer it)" 61 ); 62 63 assert_eq!( 64 to_html("\ta\r\tb"), 65 "<pre><code>a\rb\r</code></pre>", 66 "should support a carriage return in indented code (and prefer it)" 67 ); 68 69 assert_eq!( 70 to_html("\ta\r\n\tb"), 71 "<pre><code>a\r\nb\r\n</code></pre>", 72 "should support a carriage return + line feed in indented code (and prefer it)" 73 ); 74 75 assert_eq!( 76 to_html("***\n### Heading"), 77 "<hr />\n<h3>Heading</h3>", 78 "should support a line feed between flow" 79 ); 80 81 assert_eq!( 82 to_html("***\r### Heading"), 83 "<hr />\r<h3>Heading</h3>", 84 "should support a carriage return between flow" 85 ); 86 87 assert_eq!( 88 to_html("***\r\n### Heading"), 89 "<hr />\r\n<h3>Heading</h3>", 90 "should support a carriage return + line feed between flow" 91 ); 92 93 assert_eq!( 94 to_html("***\n\n\n### Heading\n"), 95 "<hr />\n<h3>Heading</h3>\n", 96 "should support several line feeds between flow" 97 ); 98 99 assert_eq!( 100 to_html("***\r\r\r### Heading\r"), 101 "<hr />\r<h3>Heading</h3>\r", 102 "should support several carriage returns between flow" 103 ); 104 105 assert_eq!( 106 to_html("***\r\n\r\n\r\n### Heading\r\n"), 107 "<hr />\r\n<h3>Heading</h3>\r\n", 108 "should support several carriage return + line feeds between flow" 109 ); 110 111 assert_eq!( 112 to_html("```x\n\n\ny\n\n\n```\n\n\n"), 113 "<pre><code class=\"language-x\">\n\ny\n\n\n</code></pre>\n", 114 "should support several line feeds in fenced code" 115 ); 116 117 assert_eq!( 118 to_html("```x\r\r\ry\r\r\r```\r\r\r"), 119 "<pre><code class=\"language-x\">\r\ry\r\r\r</code></pre>\r", 120 "should support several carriage returns in fenced code" 121 ); 122 123 assert_eq!( 124 to_html("```x\r\n\r\n\r\ny\r\n\r\n\r\n```\r\n\r\n\r\n"), 125 "<pre><code class=\"language-x\">\r\n\r\ny\r\n\r\n\r\n</code></pre>\r\n", 126 "should support several carriage return + line feeds in fenced code" 127 ); 128 129 assert_eq!( 130 to_html("A\r\nB\r\n-\r\nC"), 131 "<h2>A\r\nB</h2>\r\n<p>C</p>", 132 "should support a carriage return + line feed in content" 133 ); 134 135 assert_eq!( 136 to_html_with_options("<div\n", danger)?, 137 "<div\n", 138 "should support a line feed after html" 139 ); 140 141 assert_eq!( 142 to_html_with_options("<div\r", danger)?, 143 "<div\r", 144 "should support a carriage return after html" 145 ); 146 147 assert_eq!( 148 to_html_with_options("<div\r\n", danger)?, 149 "<div\r\n", 150 "should support a carriage return + line feed after html" 151 ); 152 153 assert_eq!( 154 to_html_with_options("<div>\n\nx", danger)?, 155 "<div>\n<p>x</p>", 156 "should support a blank line w/ line feeds after html" 157 ); 158 159 assert_eq!( 160 to_html_with_options("<div>\r\rx", danger)?, 161 "<div>\r<p>x</p>", 162 "should support a blank line w/ carriage returns after html" 163 ); 164 165 assert_eq!( 166 to_html_with_options("<div>\r\n\r\nx", danger)?, 167 "<div>\r\n<p>x</p>", 168 "should support a blank line w/ carriage return + line feeds after html" 169 ); 170 171 assert_eq!( 172 to_html_with_options("<div>\nx", danger)?, 173 "<div>\nx", 174 "should support a non-blank line w/ line feed in html" 175 ); 176 177 assert_eq!( 178 to_html_with_options("<div>\rx", danger)?, 179 "<div>\rx", 180 "should support a non-blank line w/ carriage return in html" 181 ); 182 183 assert_eq!( 184 to_html_with_options("<div>\r\nx", danger)?, 185 "<div>\r\nx", 186 "should support a non-blank line w/ carriage return + line feed in html" 187 ); 188 189 Ok(()) 190}