use markdown::{ mdast::{InlineCode, Node, Paragraph, Root, Text}, message, to_html, to_html_with_options, to_mdast, unist::Position, CompileOptions, Constructs, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn code_text() -> Result<(), message::Message> { let danger = Options { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, ..Default::default() }, ..Default::default() }; assert_eq!( to_html("`foo`"), "
foo
foo ` bar
``
``
a
\u{a0}b\u{a0}
\n
foo bar baz
foo
foo bar baz
foo\\bar`
foo`bar
foo `` bar
*foo*
[not a link](/foo)
<a href="">`
<http://foo.bar.baz>`
```foo``
", "should not support more accents before a fence" ); assert_eq!( to_html("`foo"), "`foo
", "should not support no closing fence (1)" ); assert_eq!( to_html("`foo``bar``"), "`foobar
foo\t\tbar
`x
`a`
", "should support turning off code (text)" ); assert_eq!( to_mdast("a `alpha` b.", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::InlineCode(InlineCode { value: "alpha".into(), position: Some(Position::new(1, 3, 2, 1, 10, 9)) }), Node::Text(Text { value: " b.".into(), position: Some(Position::new(1, 10, 9, 1, 13, 12)) }) ], position: Some(Position::new(1, 1, 0, 1, 13, 12)) })], position: Some(Position::new(1, 1, 0, 1, 13, 12)) }), "should support code (text) as `InlineCode`s in mdast" ); assert_eq!( to_mdast("` alpha `", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![Node::InlineCode(InlineCode { value: " alpha".into(), position: Some(Position::new(1, 1, 0, 1, 11, 10)) }),], position: Some(Position::new(1, 1, 0, 1, 11, 10)) })], position: Some(Position::new(1, 1, 0, 1, 11, 10)) }), "should strip one space from each side of `InlineCode` if the value starts and ends with space" ); assert_eq!( to_mdast("` `", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![Node::InlineCode(InlineCode { value: " ".into(), position: Some(Position::new(1, 1, 0, 1, 6, 5)) }),], position: Some(Position::new(1, 1, 0, 1, 6, 5)) })], position: Some(Position::new(1, 1, 0, 1, 6, 5)) }), "should not strip any whitespace if `InlineCode` is all whitespace" ); Ok(()) }