use markdown::{ mdast::{Emphasis, List, ListItem, Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn gfm_task_list_item() -> Result<(), String> { assert_eq!( to_html("* [x] y."), "", "should ignore task list item checks by default" ); assert_eq!( to_html_with_options("* [x] y.", &Options::gfm())?, "", "should support task list item checks" ); assert_eq!( to_html_with_options("* [ ] z.", &Options::gfm())?, "", "should support unchecked task list item checks" ); assert_eq!( to_html_with_options("*\n [x]", &Options::gfm())?, "", "should not support laziness (1)" ); assert_eq!( to_html_with_options("*\n[x]", &Options::gfm())?, "\n

[x]

", "should not support laziness (2)" ); assert_eq!( to_html_with_options( &r###" * [ ] foo * [x] bar - [x] foo - [ ] bar - [x] baz - [ ] bim + [ ] Unchecked? * [x] Checked? + [y] What is this even? - [n]: # [ ] After a definition + [ ] In a setext heading ======================= * In the… [ ] Second paragraph - [ ] With a tab + [X] With an upper case `x` * [ ] In a lazy line - [ ] With two spaces + [x] Two spaces indent * [x] Three spaces indent - [x] Four spaces indent + [x] Five spaces indent [ ] here? * > [ ] here? - [ ]No space? Empty? + [ ] Space after: + [ ]␠ * [ ]␠Text. Tab after: + [ ]␉ * [ ]␉Text. EOL after: + [ ] * [ ] Text. - [ ] after blank? + # [ ] ATX Heading > * [x] In a list in a block quote "### .replace('␠', " ") .replace('␉', "\t"), &Options::gfm() )?, r###"

[ ] here?

Empty?

Space after:

Tab after:

EOL after:

"###, "should handle things like GitHub" ); assert_eq!( to_mdast("* [x] a\n* [ ] b\n* c", &ParseOptions::gfm())?, Node::Root(Root { children: vec![Node::List(List { ordered: false, spread: false, start: None, children: vec![ Node::ListItem(ListItem { checked: Some(true), spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { value: "a".into(), position: Some(Position::new(1, 7, 6, 1, 8, 7)) }),], position: Some(Position::new(1, 7, 6, 1, 8, 7)) })], position: Some(Position::new(1, 1, 0, 1, 8, 7)) }), Node::ListItem(ListItem { checked: Some(false), spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { value: "b".into(), position: Some(Position::new(2, 7, 14, 2, 8, 15)) }),], position: Some(Position::new(2, 7, 14, 2, 8, 15)) })], position: Some(Position::new(2, 1, 8, 2, 8, 15)) }), Node::ListItem(ListItem { checked: None, spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { value: "c".into(), position: Some(Position::new(3, 3, 18, 3, 4, 19)) }),], position: Some(Position::new(3, 3, 18, 3, 4, 19)) })], position: Some(Position::new(3, 1, 16, 3, 4, 19)) }), ], position: Some(Position::new(1, 1, 0, 3, 4, 19)) })], position: Some(Position::new(1, 1, 0, 3, 4, 19)) }), "should support task list items as `checked` fields on `ListItem`s in mdast" ); assert_eq!( to_mdast( "* [x]\r\n a\n* [ ] b\n* [x]\t \r*c*", &ParseOptions::gfm() )?, Node::Root(Root { children: vec![Node::List(List { ordered: false, spread: false, start: None, children: vec![ Node::ListItem(ListItem { checked: Some(true), spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { value: "a".into(), position: Some(Position::new(2, 1, 7, 2, 4, 10)) }),], position: Some(Position::new(2, 1, 7, 2, 4, 10)) })], position: Some(Position::new(1, 1, 0, 2, 4, 10)) }), Node::ListItem(ListItem { checked: Some(false), spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { value: " b".into(), position: Some(Position::new(3, 7, 17, 3, 10, 20)) }),], position: Some(Position::new(3, 7, 17, 3, 10, 20)) })], position: Some(Position::new(3, 1, 11, 3, 10, 20)) }), Node::ListItem(ListItem { checked: Some(true), spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Emphasis(Emphasis { children: vec![Node::Text(Text { value: "c".into(), position: Some(Position::new(5, 2, 30, 5, 3, 31)) }),], position: Some(Position::new(5, 1, 29, 5, 4, 32)) })], position: Some(Position::new(5, 1, 29, 5, 4, 32)) })], position: Some(Position::new(4, 1, 21, 5, 4, 32)) }), ], position: Some(Position::new(1, 1, 0, 5, 4, 32)) })], position: Some(Position::new(1, 1, 0, 5, 4, 32)) }), "should handle lots of whitespace after checkbox, and non-text" ); Ok(()) }