extern crate markdown; use markdown::{ mdast::{List, ListItem, MdxJsxFlowElement, Node, Paragraph, Root, Text}, to_html_with_options, to_mdast, unist::Position, Constructs, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn mdx_jsx_flow_agnostic() -> Result<(), String> { let mdx = Options { parse: ParseOptions { constructs: Constructs::mdx(), ..ParseOptions::default() }, ..Options::default() }; assert_eq!( to_html_with_options("", &mdx)?, "", "should support a self-closing element" ); // Note: in MDX, indented code is turned off: assert_eq!( to_html_with_options( " ", &Options { parse: ParseOptions { constructs: Constructs { mdx_jsx_flow: true, ..Constructs::default() }, ..ParseOptions::default() }, ..Options::default() } )?, "
<a />\n
",
"should prefer indented code over jsx if it’s enabled"
);
assert_eq!(
to_html_with_options("", &mdx)?,
"",
"should support a closed element"
);
assert_eq!(
to_html_with_options("\nb\n", &mdx)?,
"b
\n", "should support an element w/ content" ); assert_eq!( to_html_with_options("\n- b\n", &mdx)?, "b
\n", "should support a dangling `>` in a tag (not a block quote)" ); assert_eq!( to_html_with_options(" \nb\n ", &mdx)?, "b
\n", "should support trailing initial and final whitespace around tags" ); assert_eq!( to_html_with_options(" \t\nc\n ", &mdx)?, "c
\n", "should support tags after tags" ); // This is to make sure `document` passes errors through properly. assert_eq!( to_html_with_options("* \n1. b", &mdx) .err() .unwrap(), "1:4: Unexpected character `!` (U+0021) before name, expected a character that can start a name, such as a letter, `$`, or `_` (note: to create a comment in MDX, use `{/* text */}`)", "should handle crash in containers gracefully" ); assert_eq!( to_html_with_options(">\n\n", "should not support lazy flow (8)" ); assert_eq!( to_mdast("<>\n * a\n>", &mdx.parse)?, Node::Root(Root { children: vec![Node::MdxJsxFlowElement(MdxJsxFlowElement { name: None, attributes: vec![], children: vec![Node::List(List { ordered: false, spread: false, start: None, children: vec![Node::ListItem(ListItem { checked: None, spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { value: "a".into(), position: Some(Position::new(2, 5, 7, 2, 6, 8)) }),], position: Some(Position::new(2, 5, 7, 2, 6, 8)) })], position: Some(Position::new(2, 1, 3, 2, 6, 8)) })], position: Some(Position::new(2, 1, 3, 2, 6, 8)) })], position: Some(Position::new(1, 1, 0, 3, 4, 12)) })], position: Some(Position::new(1, 1, 0, 3, 4, 12)) }), "should support mdx jsx (flow) as `MdxJsxFlowElement`s in mdast" ); Ok(()) }a
\n