Markdown parser fork with extended syntax for personal use.
at main 708 lines 26 kB view raw
1use markdown::{ 2 mdast::{List, ListItem, Node, Paragraph, Root, Text}, 3 message, to_html, to_html_with_options, to_mdast, 4 unist::Position, 5 CompileOptions, Constructs, Options, ParseOptions, 6}; 7use pretty_assertions::assert_eq; 8 9#[test] 10fn list() -> Result<(), message::Message> { 11 let danger = Options { 12 compile: CompileOptions { 13 allow_dangerous_html: true, 14 allow_dangerous_protocol: true, 15 ..Default::default() 16 }, 17 ..Default::default() 18 }; 19 20 assert_eq!( 21 to_html( 22 "A paragraph\nwith two lines.\n\n indented code\n\n> A block quote."), 23 "<p>A paragraph\nwith two lines.</p>\n<pre><code>indented code\n</code></pre>\n<blockquote>\n<p>A block quote.</p>\n</blockquote>", 24 "should support documents" 25 ); 26 27 assert_eq!( 28 to_html("1. a\n b.\n\n c\n\n > d."), 29 "<ol>\n<li>\n<p>a\nb.</p>\n<pre><code>c\n</code></pre>\n<blockquote>\n<p>d.</p>\n</blockquote>\n</li>\n</ol>", 30 "should support documents in list items" 31 ); 32 33 assert_eq!( 34 to_html("- one\n\n two"), 35 "<ul>\n<li>one</li>\n</ul>\n<p>two</p>", 36 "should not support 1 space for a two-character list prefix" 37 ); 38 39 assert_eq!( 40 to_html("- a\n\n b"), 41 "<ul>\n<li>\n<p>a</p>\n<p>b</p>\n</li>\n</ul>", 42 "should support blank lines in list items" 43 ); 44 45 assert_eq!( 46 to_html(" - one\n\n two"), 47 "<ul>\n<li>one</li>\n</ul>\n<pre><code> two\n</code></pre>", 48 "should support indented code after lists" 49 ); 50 51 assert_eq!( 52 to_html(" > > 1. one\n>>\n>> two"), 53 "<blockquote>\n<blockquote>\n<ol>\n<li>\n<p>one</p>\n<p>two</p>\n</li>\n</ol>\n</blockquote>\n</blockquote>", 54 "should support proper indent mixed w/ block quotes (1)" 55 ); 56 57 assert_eq!( 58 to_html(">>- one\n>>\n > > two"), 59 "<blockquote>\n<blockquote>\n<ul>\n<li>one</li>\n</ul>\n<p>two</p>\n</blockquote>\n</blockquote>", 60 "should support proper indent mixed w/ block quotes (2)" 61 ); 62 63 assert_eq!( 64 to_html("-one\n\n2.two"), 65 "<p>-one</p>\n<p>2.two</p>", 66 "should not support a missing space after marker" 67 ); 68 69 assert_eq!( 70 to_html("- foo\n\n\n bar"), 71 "<ul>\n<li>\n<p>foo</p>\n<p>bar</p>\n</li>\n</ul>", 72 "should support multiple blank lines between items" 73 ); 74 75 assert_eq!( 76 to_html("1. foo\n\n ```\n bar\n ```\n\n baz\n\n > bam"), 77 "<ol>\n<li>\n<p>foo</p>\n<pre><code>bar\n</code></pre>\n<p>baz</p>\n<blockquote>\n<p>bam</p>\n</blockquote>\n</li>\n</ol>", 78 "should support flow in items" 79 ); 80 81 assert_eq!( 82 to_html("- Foo\n\n bar\n\n\n baz"), 83 "<ul>\n<li>\n<p>Foo</p>\n<pre><code>bar\n\n\nbaz\n</code></pre>\n</li>\n</ul>", 84 "should support blank lines in indented code in items" 85 ); 86 87 assert_eq!( 88 to_html("123456789. ok"), 89 "<ol start=\"123456789\">\n<li>ok</li>\n</ol>", 90 "should support start on the first list item" 91 ); 92 93 assert_eq!( 94 to_html("1234567890. not ok"), 95 "<p>1234567890. not ok</p>", 96 "should not support ordered item values over 10 digits" 97 ); 98 99 assert_eq!( 100 to_html("0. ok"), 101 "<ol start=\"0\">\n<li>ok</li>\n</ol>", 102 "should support ordered item values of `0`" 103 ); 104 105 assert_eq!( 106 to_html("003. ok"), 107 "<ol start=\"3\">\n<li>ok</li>\n</ol>", 108 "should support ordered item values starting w/ `0`s" 109 ); 110 111 assert_eq!( 112 to_html("-1. not ok"), 113 "<p>-1. not ok</p>", 114 "should not support “negative” ordered item values" 115 ); 116 117 assert_eq!( 118 to_html("- foo\n\n bar"), 119 "<ul>\n<li>\n<p>foo</p>\n<pre><code>bar\n</code></pre>\n</li>\n</ul>", 120 "should support indented code in list items (1)" 121 ); 122 123 assert_eq!( 124 to_html(" 10. foo\n\n bar"), 125 "<ol start=\"10\">\n<li>\n<p>foo</p>\n<pre><code>bar\n</code></pre>\n</li>\n</ol>", 126 "should support indented code in list items (2)" 127 ); 128 129 assert_eq!( 130 to_html(" indented code\n\nparagraph\n\n more code"), 131 "<pre><code>indented code\n</code></pre>\n<p>paragraph</p>\n<pre><code>more code\n</code></pre>", 132 "should support indented code in list items (3)" 133 ); 134 135 assert_eq!( 136 to_html("1. indented code\n\n paragraph\n\n more code"), 137 "<ol>\n<li>\n<pre><code>indented code\n</code></pre>\n<p>paragraph</p>\n<pre><code>more code\n</code></pre>\n</li>\n</ol>", 138 "should support indented code in list items (4)" 139 ); 140 141 assert_eq!( 142 to_html("1. indented code\n\n paragraph\n\n more code"), 143 "<ol>\n<li>\n<pre><code> indented code\n</code></pre>\n<p>paragraph</p>\n<pre><code>more code\n</code></pre>\n</li>\n</ol>", 144 "should support indented code in list items (5)" 145 ); 146 147 assert_eq!( 148 to_html(" foo\n\nbar"), 149 "<p>foo</p>\n<p>bar</p>", 150 "should support indented code in list items (6)" 151 ); 152 153 assert_eq!( 154 to_html("- foo\n\n bar"), 155 "<ul>\n<li>foo</li>\n</ul>\n<p>bar</p>", 156 "should support indented code in list items (7)" 157 ); 158 159 assert_eq!( 160 to_html("- foo\n\n bar"), 161 "<ul>\n<li>\n<p>foo</p>\n<p>bar</p>\n</li>\n</ul>", 162 "should support indented code in list items (8)" 163 ); 164 165 assert_eq!( 166 to_html("-\n foo\n-\n ```\n bar\n ```\n-\n baz"), 167 "<ul>\n<li>foo</li>\n<li>\n<pre><code>bar\n</code></pre>\n</li>\n<li>\n<pre><code>baz\n</code></pre>\n</li>\n</ul>", 168 "should support blank first lines (1)" 169 ); 170 171 assert_eq!( 172 to_html("- \n foo"), 173 "<ul>\n<li>foo</li>\n</ul>", 174 "should support blank first lines (2)" 175 ); 176 177 assert_eq!( 178 to_html("-\n\n foo"), 179 "<ul>\n<li></li>\n</ul>\n<p>foo</p>", 180 "should support empty only items" 181 ); 182 183 assert_eq!( 184 to_html("- foo\n-\n- bar"), 185 "<ul>\n<li>foo</li>\n<li></li>\n<li>bar</li>\n</ul>", 186 "should support empty continued items" 187 ); 188 189 assert_eq!( 190 to_html("- foo\n- \n- bar"), 191 "<ul>\n<li>foo</li>\n<li></li>\n<li>bar</li>\n</ul>", 192 "should support blank continued items" 193 ); 194 195 assert_eq!( 196 to_html("1. foo\n2.\n3. bar"), 197 "<ol>\n<li>foo</li>\n<li></li>\n<li>bar</li>\n</ol>", 198 "should support empty continued items (ordered)" 199 ); 200 201 assert_eq!( 202 to_html("*"), 203 "<ul>\n<li></li>\n</ul>", 204 "should support a single empty item" 205 ); 206 207 assert_eq!( 208 to_html("foo\n*\n\nfoo\n1."), 209 "<p>foo\n*</p>\n<p>foo\n1.</p>", 210 "should not support empty items to interrupt paragraphs" 211 ); 212 213 assert_eq!( 214 to_html( 215 " 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."), 216 "<ol>\n<li>\n<p>A paragraph\nwith two lines.</p>\n<pre><code>indented code\n</code></pre>\n<blockquote>\n<p>A block quote.</p>\n</blockquote>\n</li>\n</ol>", 217 "should support indenting w/ 1 space" 218 ); 219 220 assert_eq!( 221 to_html( 222 " 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."), 223 "<ol>\n<li>\n<p>A paragraph\nwith two lines.</p>\n<pre><code>indented code\n</code></pre>\n<blockquote>\n<p>A block quote.</p>\n</blockquote>\n</li>\n</ol>", 224 "should support indenting w/ 2 spaces" 225 ); 226 227 assert_eq!( 228 to_html( 229 " 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."), 230 "<ol>\n<li>\n<p>A paragraph\nwith two lines.</p>\n<pre><code>indented code\n</code></pre>\n<blockquote>\n<p>A block quote.</p>\n</blockquote>\n</li>\n</ol>", 231 "should support indenting w/ 3 spaces" 232 ); 233 234 assert_eq!( 235 to_html( 236 " 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."), 237 "<pre><code>1. A paragraph\n with two lines.\n\n indented code\n\n &gt; A block quote.\n</code></pre>", 238 "should not support indenting w/ 4 spaces" 239 ); 240 241 assert_eq!( 242 to_html( 243 " 1. A paragraph\nwith two lines.\n\n indented code\n\n > A block quote."), 244 "<ol>\n<li>\n<p>A paragraph\nwith two lines.</p>\n<pre><code>indented code\n</code></pre>\n<blockquote>\n<p>A block quote.</p>\n</blockquote>\n</li>\n</ol>", 245 "should support lazy lines" 246 ); 247 248 assert_eq!( 249 to_html(" 1. A paragraph\n with two lines."), 250 "<ol>\n<li>A paragraph\nwith two lines.</li>\n</ol>", 251 "should support partially lazy lines" 252 ); 253 254 assert_eq!( 255 to_html("> 1. > Blockquote\ncontinued here."), 256 "<blockquote>\n<ol>\n<li>\n<blockquote>\n<p>Blockquote\ncontinued here.</p>\n</blockquote>\n</li>\n</ol>\n</blockquote>", 257 "should support lazy lines combined w/ other containers" 258 ); 259 260 assert_eq!( 261 to_html("> 1. > Blockquote\n> continued here."), 262 "<blockquote>\n<ol>\n<li>\n<blockquote>\n<p>Blockquote\ncontinued here.</p>\n</blockquote>\n</li>\n</ol>\n</blockquote>", 263 "should support partially continued, partially lazy lines combined w/ other containers" 264 ); 265 266 assert_eq!( 267 to_html("- [\na"), 268 "<ul>\n<li>[\na</li>\n</ul>", 269 "should support lazy, definition-like lines" 270 ); 271 272 assert_eq!( 273 to_html("- [a]: b\nc"), 274 "<ul>\n<li>c</li>\n</ul>", 275 "should support a definition, followed by a lazy paragraph" 276 ); 277 278 assert_eq!( 279 to_html("- foo\n - bar\n - baz\n - boo"), 280 "<ul>\n<li>foo\n<ul>\n<li>bar\n<ul>\n<li>baz\n<ul>\n<li>boo</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>", 281 "should support sublists w/ enough spaces (1)" 282 ); 283 284 assert_eq!( 285 to_html("- foo\n - bar\n - baz\n - boo"), 286 "<ul>\n<li>foo</li>\n<li>bar</li>\n<li>baz</li>\n<li>boo</li>\n</ul>", 287 "should not support sublists w/ too few spaces" 288 ); 289 290 assert_eq!( 291 to_html("10) foo\n - bar"), 292 "<ol start=\"10\">\n<li>foo\n<ul>\n<li>bar</li>\n</ul>\n</li>\n</ol>", 293 "should support sublists w/ enough spaces (2)" 294 ); 295 296 assert_eq!( 297 to_html("10) foo\n - bar"), 298 "<ol start=\"10\">\n<li>foo</li>\n</ol>\n<ul>\n<li>bar</li>\n</ul>", 299 "should not support sublists w/ too few spaces (2)" 300 ); 301 302 assert_eq!( 303 to_html("- - foo"), 304 "<ul>\n<li>\n<ul>\n<li>foo</li>\n</ul>\n</li>\n</ul>", 305 "should support sublists (1)" 306 ); 307 308 assert_eq!( 309 to_html("1. - 2. foo"), 310 "<ol>\n<li>\n<ul>\n<li>\n<ol start=\"2\">\n<li>foo</li>\n</ol>\n</li>\n</ul>\n</li>\n</ol>", 311 "should support sublists (2)" 312 ); 313 314 assert_eq!( 315 to_html("- # Foo\n- Bar\n ---\n baz"), 316 "<ul>\n<li>\n<h1>Foo</h1>\n</li>\n<li>\n<h2>Bar</h2>\nbaz</li>\n</ul>", 317 "should support headings in list items" 318 ); 319 320 assert_eq!( 321 to_html("- foo\n- bar\n+ baz"), 322 "<ul>\n<li>foo</li>\n<li>bar</li>\n</ul>\n<ul>\n<li>baz</li>\n</ul>", 323 "should support a new list by changing the marker (unordered)" 324 ); 325 326 assert_eq!( 327 to_html("1. foo\n2. bar\n3) baz"), 328 "<ol>\n<li>foo</li>\n<li>bar</li>\n</ol>\n<ol start=\"3\">\n<li>baz</li>\n</ol>", 329 "should support a new list by changing the marker (ordered)" 330 ); 331 332 assert_eq!( 333 to_html("Foo\n- bar\n- baz"), 334 "<p>Foo</p>\n<ul>\n<li>bar</li>\n<li>baz</li>\n</ul>", 335 "should support interrupting a paragraph" 336 ); 337 338 assert_eq!( 339 to_html("a\n2. b"), 340 "<p>a\n2. b</p>", 341 "should not support interrupting a paragraph with a non-1 numbered item" 342 ); 343 344 assert_eq!( 345 to_html("\n2. a"), 346 "<ol start=\"2\">\n<li>a</li>\n</ol>", 347 "should “interrupt” a blank line (1)" 348 ); 349 350 assert_eq!( 351 to_html("a\n\n2. b"), 352 "<p>a</p>\n<ol start=\"2\">\n<li>b</li>\n</ol>", 353 "should “interrupt” a blank line (2)" 354 ); 355 356 assert_eq!( 357 to_html("a\n1. b"), 358 "<p>a</p>\n<ol>\n<li>b</li>\n</ol>", 359 "should support interrupting a paragraph with a 1 numbered item" 360 ); 361 362 assert_eq!( 363 to_html("- foo\n\n- bar\n\n\n- baz"), 364 "<ul>\n<li>\n<p>foo</p>\n</li>\n<li>\n<p>bar</p>\n</li>\n<li>\n<p>baz</p>\n</li>\n</ul>", 365 "should support blank lines between items (1)" 366 ); 367 368 assert_eq!( 369 to_html("- foo\n - bar\n - baz\n\n\n bim"), 370 "<ul>\n<li>foo\n<ul>\n<li>bar\n<ul>\n<li>\n<p>baz</p>\n<p>bim</p>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>", 371 "should support blank lines between items (2)" 372 ); 373 374 assert_eq!( 375 to_html_with_options("- foo\n- bar\n\n<!-- -->\n\n- baz\n- bim", &danger)?, 376 "<ul>\n<li>foo</li>\n<li>bar</li>\n</ul>\n<!-- -->\n<ul>\n<li>baz</li>\n<li>bim</li>\n</ul>", 377 "should support HTML comments between lists" 378 ); 379 380 assert_eq!( 381 to_html_with_options("- foo\n\n notcode\n\n- foo\n\n<!-- -->\n\n code", &danger)?, 382 "<ul>\n<li>\n<p>foo</p>\n<p>notcode</p>\n</li>\n<li>\n<p>foo</p>\n</li>\n</ul>\n<!-- -->\n<pre><code>code\n</code></pre>", 383 "should support HTML comments between lists and indented code" 384 ); 385 386 assert_eq!( 387 to_html("- a\n - b\n - c\n - d\n - e\n - f\n- g"), 388 "<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n<li>d</li>\n<li>e</li>\n<li>f</li>\n<li>g</li>\n</ul>", 389 "should not support lists in lists w/ too few spaces (1)" 390 ); 391 392 assert_eq!( 393 to_html("1. a\n\n 2. b\n\n 3. c"), 394 "<ol>\n<li>\n<p>a</p>\n</li>\n<li>\n<p>b</p>\n</li>\n<li>\n<p>c</p>\n</li>\n</ol>", 395 "should not support lists in lists w/ too few spaces (2)" 396 ); 397 398 assert_eq!( 399 to_html("- a\n - b\n - c\n - d\n - e"), 400 "<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n<li>d\n- e</li>\n</ul>", 401 "should not support lists in lists w/ too few spaces (3)" 402 ); 403 404 assert_eq!( 405 to_html("1. a\n\n 2. b\n\n 3. c"), 406 "<ol>\n<li>\n<p>a</p>\n</li>\n<li>\n<p>b</p>\n</li>\n</ol>\n<pre><code>3. c\n</code></pre>", 407 "should not support lists in lists w/ too few spaces (3)" 408 ); 409 410 assert_eq!( 411 to_html("- a\n- b\n\n- c"), 412 "<ul>\n<li>\n<p>a</p>\n</li>\n<li>\n<p>b</p>\n</li>\n<li>\n<p>c</p>\n</li>\n</ul>", 413 "should support loose lists w/ a blank line between (1)" 414 ); 415 416 assert_eq!( 417 to_html("* a\n*\n\n* c"), 418 "<ul>\n<li>\n<p>a</p>\n</li>\n<li></li>\n<li>\n<p>c</p>\n</li>\n</ul>", 419 "should support loose lists w/ a blank line between (2)" 420 ); 421 422 assert_eq!( 423 to_html("- a\n- b\n\n c\n- d"), 424 "<ul>\n<li>\n<p>a</p>\n</li>\n<li>\n<p>b</p>\n<p>c</p>\n</li>\n<li>\n<p>d</p>\n</li>\n</ul>", 425 "should support loose lists w/ a blank line in an item (1)" 426 ); 427 428 assert_eq!( 429 to_html("- a\n- b\n\n [ref]: /url\n- d"), 430 "<ul>\n<li>\n<p>a</p>\n</li>\n<li>\n<p>b</p>\n</li>\n<li>\n<p>d</p>\n</li>\n</ul>", 431 "should support loose lists w/ a blank line in an item (2)" 432 ); 433 434 assert_eq!( 435 to_html("- a\n- ```\n b\n\n\n ```\n- c"), 436 "<ul>\n<li>a</li>\n<li>\n<pre><code>b\n\n\n</code></pre>\n</li>\n<li>c</li>\n</ul>", 437 "should support tight lists w/ a blank line in fenced code" 438 ); 439 440 assert_eq!( 441 to_html("- a\n - b\n\n c\n- d"), 442 "<ul>\n<li>a\n<ul>\n<li>\n<p>b</p>\n<p>c</p>\n</li>\n</ul>\n</li>\n<li>d</li>\n</ul>", 443 "should support tight lists w/ a blank line in a sublist" 444 ); 445 446 assert_eq!( 447 to_html("* a\n > b\n >\n* c"), 448 "<ul>\n<li>a\n<blockquote>\n<p>b</p>\n</blockquote>\n</li>\n<li>c</li>\n</ul>", 449 "should support tight lists w/ a blank line in a block quote" 450 ); 451 452 assert_eq!( 453 to_html("- a\n > b\n ```\n c\n ```\n- d"), 454 "<ul>\n<li>a\n<blockquote>\n<p>b</p>\n</blockquote>\n<pre><code>c\n</code></pre>\n</li>\n<li>d</li>\n</ul>", 455 "should support tight lists w/ flow w/o blank line" 456 ); 457 458 assert_eq!( 459 to_html("- a"), 460 "<ul>\n<li>a</li>\n</ul>", 461 "should support tight lists w/ a single content" 462 ); 463 464 assert_eq!( 465 to_html("- a\n - b"), 466 "<ul>\n<li>a\n<ul>\n<li>b</li>\n</ul>\n</li>\n</ul>", 467 "should support tight lists w/ a sublist" 468 ); 469 470 assert_eq!( 471 to_html("1. ```\n foo\n ```\n\n bar"), 472 "<ol>\n<li>\n<pre><code>foo\n</code></pre>\n<p>bar</p>\n</li>\n</ol>", 473 "should support loose lists w/ a blank line in an item" 474 ); 475 476 assert_eq!( 477 to_html("* foo\n * bar\n\n baz"), 478 "<ul>\n<li>\n<p>foo</p>\n<ul>\n<li>bar</li>\n</ul>\n<p>baz</p>\n</li>\n</ul>", 479 "should support loose lists w/ tight sublists (1)" 480 ); 481 482 assert_eq!( 483 to_html("- a\n - b\n - c\n\n- d\n - e\n - f"), 484 "<ul>\n<li>\n<p>a</p>\n<ul>\n<li>b</li>\n<li>c</li>\n</ul>\n</li>\n<li>\n<p>d</p>\n<ul>\n<li>e</li>\n<li>f</li>\n</ul>\n</li>\n</ul>", 485 "should support loose lists w/ tight sublists (2)" 486 ); 487 488 // Extra. 489 assert_eq!( 490 to_html("* a\n*\n\n \n\t\n* b"), 491 "<ul>\n<li>\n<p>a</p>\n</li>\n<li></li>\n<li>\n<p>b</p>\n</li>\n</ul>", 492 "should support continued list items after an empty list item w/ many blank lines" 493 ); 494 495 assert_eq!( 496 to_html("*\n ~~~p\n\n ~~~"), 497 "<ul>\n<li>\n<pre><code class=\"language-p\">\n</code></pre>\n</li>\n</ul>", 498 "should support blank lines in code after an initial blank line" 499 ); 500 501 assert_eq!( 502 to_html( 503 "* a tight item that ends with an html element: `x`\n\nParagraph"), 504 "<ul>\n<li>a tight item that ends with an html element: <code>x</code></li>\n</ul>\n<p>Paragraph</p>", 505 "should ignore line endings after tight items ending in tags" 506 ); 507 508 assert_eq!( 509 to_html("* foo\n\n*\n\n* bar"), 510 "<ul>\n<li>\n<p>foo</p>\n</li>\n<li></li>\n<li>\n<p>bar</p>\n</li>\n</ul>", 511 "should support empty items in a spread list" 512 ); 513 514 assert_eq!( 515 to_html("- ```\n\n ```"), 516 "<ul>\n<li>\n<pre><code>\n</code></pre>\n</li>\n</ul>", 517 "should remove indent of code (fenced) in list (0 space)" 518 ); 519 520 assert_eq!( 521 to_html("- ```\n \n ```"), 522 "<ul>\n<li>\n<pre><code>\n</code></pre>\n</li>\n</ul>", 523 "should remove indent of code (fenced) in list (1 space)" 524 ); 525 526 assert_eq!( 527 to_html("- ```\n \n ```"), 528 "<ul>\n<li>\n<pre><code>\n</code></pre>\n</li>\n</ul>", 529 "should remove indent of code (fenced) in list (2 spaces)" 530 ); 531 532 assert_eq!( 533 to_html("- ```\n \n ```"), 534 "<ul>\n<li>\n<pre><code> \n</code></pre>\n</li>\n</ul>", 535 "should remove indent of code (fenced) in list (3 spaces)" 536 ); 537 538 assert_eq!( 539 to_html("- ```\n \n ```"), 540 "<ul>\n<li>\n<pre><code> \n</code></pre>\n</li>\n</ul>", 541 "should remove indent of code (fenced) in list (4 spaces)" 542 ); 543 544 assert_eq!( 545 to_html("- ```\n\t\n ```"), 546 "<ul>\n<li>\n<pre><code> \n</code></pre>\n</li>\n</ul>", 547 "should remove indent of code (fenced) in list (1 tab)" 548 ); 549 550 assert_eq!( 551 to_html("- +\n-"), 552 "<ul>\n<li>\n<ul>\n<li></li>\n</ul>\n</li>\n<li></li>\n</ul>", 553 "should support complex nested and empty lists (1)" 554 ); 555 556 assert_eq!( 557 to_html("- 1.\n-"), 558 "<ul>\n<li>\n<ol>\n<li></li>\n</ol>\n</li>\n<li></li>\n</ul>", 559 "should support complex nested and empty lists (2)" 560 ); 561 562 assert_eq!( 563 to_html("* - +\n* -"), 564 "<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li></li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<ul>\n<li></li>\n</ul>\n</li>\n</ul>", 565 "should support complex nested and empty lists (3)" 566 ); 567 568 assert_eq!( 569 to_html_with_options("* a\n\n<!---->\n\n* b", &danger)?, 570 "<ul>\n<li>a</li>\n</ul>\n<!---->\n<ul>\n<li>b</li>\n</ul>", 571 "should support the common list breaking comment method" 572 ); 573 574 assert_eq!( 575 to_html_with_options( 576 "- one\n\n two", 577 &Options { 578 parse: ParseOptions { 579 constructs: Constructs { 580 list_item: false, 581 ..Default::default() 582 }, 583 ..Default::default() 584 }, 585 ..Default::default() 586 } 587 )?, 588 "<p>- one</p>\n<p>two</p>", 589 "should support turning off lists" 590 ); 591 592 assert_eq!( 593 to_mdast("* a", &Default::default())?, 594 Node::Root(Root { 595 children: vec![Node::List(List { 596 ordered: false, 597 spread: false, 598 start: None, 599 children: vec![Node::ListItem(ListItem { 600 checked: None, 601 spread: false, 602 children: vec![Node::Paragraph(Paragraph { 603 children: vec![Node::Text(Text { 604 value: "a".into(), 605 position: Some(Position::new(1, 3, 2, 1, 4, 3)) 606 }),], 607 position: Some(Position::new(1, 3, 2, 1, 4, 3)) 608 })], 609 position: Some(Position::new(1, 1, 0, 1, 4, 3)) 610 })], 611 position: Some(Position::new(1, 1, 0, 1, 4, 3)) 612 })], 613 position: Some(Position::new(1, 1, 0, 1, 4, 3)) 614 }), 615 "should support lists, list items as `List`, `ListItem`s in mdast" 616 ); 617 618 assert_eq!( 619 to_mdast("3. a\n4. b", &Default::default())?, 620 Node::Root(Root { 621 children: vec![Node::List(List { 622 ordered: true, 623 spread: false, 624 start: Some(3), 625 children: vec![ 626 Node::ListItem(ListItem { 627 checked: None, 628 spread: false, 629 children: vec![Node::Paragraph(Paragraph { 630 children: vec![Node::Text(Text { 631 value: "a".into(), 632 position: Some(Position::new(1, 4, 3, 1, 5, 4)) 633 }),], 634 position: Some(Position::new(1, 4, 3, 1, 5, 4)) 635 })], 636 position: Some(Position::new(1, 1, 0, 1, 5, 4)) 637 }), 638 Node::ListItem(ListItem { 639 checked: None, 640 spread: false, 641 children: vec![Node::Paragraph(Paragraph { 642 children: vec![Node::Text(Text { 643 value: "b".into(), 644 position: Some(Position::new(2, 4, 8, 2, 5, 9)) 645 }),], 646 position: Some(Position::new(2, 4, 8, 2, 5, 9)) 647 })], 648 position: Some(Position::new(2, 1, 5, 2, 5, 9)) 649 }) 650 ], 651 position: Some(Position::new(1, 1, 0, 2, 5, 9)) 652 })], 653 position: Some(Position::new(1, 1, 0, 2, 5, 9)) 654 }), 655 "should support `start` fields on `List` w/ `ordered: true` in mdast" 656 ); 657 658 assert_eq!( 659 to_mdast("* a\n\n b\n* c", &Default::default())?, 660 Node::Root(Root { 661 children: vec![Node::List(List { 662 ordered: false, 663 spread: false, 664 start: None, 665 children: vec![ 666 Node::ListItem(ListItem { 667 checked: None, 668 spread: true, 669 children: vec![ 670 Node::Paragraph(Paragraph { 671 children: vec![Node::Text(Text { 672 value: "a".into(), 673 position: Some(Position::new(1, 3, 2, 1, 4, 3)) 674 }),], 675 position: Some(Position::new(1, 3, 2, 1, 4, 3)) 676 }), 677 Node::Paragraph(Paragraph { 678 children: vec![Node::Text(Text { 679 value: "b".into(), 680 position: Some(Position::new(3, 3, 7, 3, 4, 8)) 681 }),], 682 position: Some(Position::new(3, 3, 7, 3, 4, 8)) 683 }) 684 ], 685 position: Some(Position::new(1, 1, 0, 3, 4, 8)) 686 }), 687 Node::ListItem(ListItem { 688 checked: None, 689 spread: false, 690 children: vec![Node::Paragraph(Paragraph { 691 children: vec![Node::Text(Text { 692 value: "c".into(), 693 position: Some(Position::new(4, 3, 11, 4, 4, 12)) 694 }),], 695 position: Some(Position::new(4, 3, 11, 4, 4, 12)) 696 })], 697 position: Some(Position::new(4, 1, 9, 4, 4, 12)) 698 }) 699 ], 700 position: Some(Position::new(1, 1, 0, 4, 4, 12)) 701 })], 702 position: Some(Position::new(1, 1, 0, 4, 4, 12)) 703 }), 704 "should support `spread` fields on `List`, `ListItem`s in mdast" 705 ); 706 707 Ok(()) 708}