extern crate markdown; use markdown::{ mdast::{Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, CompileOptions, Constructs, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn character_reference() -> Result<(), String> { assert_eq!( to_html( " & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸" ), "
\u{a0} & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸
", "should support named character references" ); assert_eq!( to_html("# Ӓ Ϡ "), "# Ӓ Ϡ �
", "should support decimal character references" ); assert_eq!( to_html("" ആ ಫ"), "" ആ ಫ
", "should support hexadecimal character references" ); assert_eq!( to_html( "  &x; \n\nabcdef0;\n&ThisIsNotDefined; &hi?;"), "  &x; &#; &#x;\n�\n&#abcdef0;\n&ThisIsNotDefined; &hi?;
", "should not support other things that look like character references" ); assert_eq!( to_html("©"), "©
", "should not support character references w/o semicolon" ); assert_eq!( to_html("&MadeUpEntity;"), "&MadeUpEntity;
", "should not support unknown named character references" ); assert_eq!( to_html_with_options( "", &Options { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, ..CompileOptions::default() }, ..Options::default() } )?, "", "should not care about character references in html" ); assert_eq!( to_html("[foo](/föö \"föö\")"), "", "should support character references in resource URLs and titles" ); assert_eq!( to_html("[foo]: /föö \"föö\"\n\n[foo]"), "", "should support character references in definition URLs and titles" ); assert_eq!( to_html("``` föö\nfoo\n```"), "foo\n
",
"should support character references in code language"
);
assert_eq!(
to_html("`föö`"),
"föö
föfö\n
",
"should not support character references in indented code"
);
assert_eq!(
to_html("*foo*\n*foo*"),
"*foo*\nfoo
", "should not support character references as construct markers (1)" ); assert_eq!( to_html("* foo\n\n* foo"), "* foo
\n[a](url "tit")
", "should not support character references as construct markers (3)" ); assert_eq!( to_html("foo bar"), "foo\n\nbar
", "should not support character references as whitespace (1)" ); assert_eq!( to_html(" foo"), "\tfoo
", "should not support character references as whitespace (2)" ); // Extra: assert_eq!( to_html("∳"), "∳
", "should support the longest possible named character reference" ); assert_eq!( to_html(""), "�
", "should “support” a longest possible hexadecimal character reference" ); assert_eq!( to_html(""), "�
", "should “support” a longest possible decimal character reference" ); assert_eq!( to_html("&CounterClockwiseContourIntegrali;"), "&CounterClockwiseContourIntegrali;
", "should not support the longest possible named character reference" ); assert_eq!( to_html(""), "�
", "should not support a longest possible hexadecimal character reference" ); assert_eq!( to_html(""), "�
", "should not support a longest possible decimal character reference" ); assert_eq!( to_html("&-;"), "&-;
", "should not support the other characters after `&`" ); assert_eq!( to_html("-;"), "&#-;
", "should not support the other characters after `#`" ); assert_eq!( to_html("-;"), "&#x-;
", "should not support the other characters after `#x`" ); assert_eq!( to_html("<-;"), "<-;
", "should not support the other characters inside a name" ); assert_eq!( to_html(" -;"), "	-;
", "should not support the other characters inside a demical" ); assert_eq!( to_html(" -;"), "	-;
", "should not support the other characters inside a hexademical" ); assert_eq!( to_html_with_options( "&", &Options { parse: ParseOptions { constructs: Constructs { character_reference: false, ..Constructs::default() }, ..ParseOptions::default() }, ..Options::default() } )?, "&
", "should support turning off character references" ); assert_eq!( to_mdast(" & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸\n# Ӓ Ϡ \n" ആ ಫ", &ParseOptions::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { value: "\u{a0} & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸\n# Ӓ Ϡ �\n\" ആ ಫ".into(), position: Some(Position::new(1, 1, 0, 5, 23, 158)) }),], position: Some(Position::new(1, 1, 0, 5, 23, 158)) })], position: Some(Position::new(1, 1, 0, 5, 23, 158)) }), "should support character references as `Text`s in mdast" ); Ok(()) }