From b75d7976cfe8db43783b930c1f4774f2ad4936f5 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 6 Oct 2022 11:43:26 +0200 Subject: Add support for HTML 4 character references in JSX attributes --- tests/mdx_jsx_text.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'tests') diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs index ea3502f..0a27bb2 100644 --- a/tests/mdx_jsx_text.rs +++ b/tests/mdx_jsx_text.rs @@ -250,6 +250,97 @@ fn mdx_jsx_text_core() -> Result<(), String> { "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (attribute values)" ); + assert_eq!( + micromark_to_mdast(".", &mdx)?, + Node::Root(Root { + children: vec![Node::Paragraph(Paragraph { + children: vec![ + Node::MdxJsxTextElement(MdxJsxTextElement { + name: Some("a".to_string()), + attributes: vec![ + AttributeContent::Property(MdxJsxAttribute { + name: "b".to_string(), + value: Some(AttributeValue::Literal("\u{a0} & © Æ Ď ¾ ℋ ⅆ ∲ ≧̸".into())), + }), + ], + children: vec![], + position: Some(Position::new(1, 1, 0, 1, 120, 119)) + }), + Node::Text(Text { + value: ".".to_string(), + position: Some(Position::new(1, 120, 119, 1, 121, 120)) + }) + ], + position: Some(Position::new(1, 1, 0, 1, 121, 120)) + })], + position: Some(Position::new(1, 1, 0, 1, 121, 120)) + }), + "should support character references (HTML 4, named) in JSX attribute values" + ); + + assert_eq!( + micromark_to_mdast( + ".", + &mdx + )?, + Node::Root(Root { + children: vec![Node::Paragraph(Paragraph { + children: vec![ + Node::MdxJsxTextElement(MdxJsxTextElement { + name: Some("a".to_string()), + attributes: vec![ + AttributeContent::Property(MdxJsxAttribute { + name: "b".to_string(), + value: Some(AttributeValue::Literal("# Ӓ Ϡ �".into())), + }), + AttributeContent::Property(MdxJsxAttribute { + name: "c".to_string(), + value: Some(AttributeValue::Literal("\" ആ ಫ".into())), + }), + ], + children: vec![], + position: Some(Position::new(1, 1, 0, 1, 63, 62)) + }), + Node::Text(Text { + value: ".".to_string(), + position: Some(Position::new(1, 63, 62, 1, 64, 63)) + }) + ], + position: Some(Position::new(1, 1, 0, 1, 64, 63)) + })], + position: Some(Position::new(1, 1, 0, 1, 64, 63)) + }), + "should support character references (numeric) in JSX attribute values" + ); + + assert_eq!( + micromark_to_mdast(".", &mdx)?, + Node::Root(Root { + children: vec![Node::Paragraph(Paragraph { + children: vec![ + Node::MdxJsxTextElement(MdxJsxTextElement { + name: Some("a".to_string()), + attributes: vec![ + AttributeContent::Property(MdxJsxAttribute { + name: "b".to_string(), + value: Some(AttributeValue::Literal("  &x; &#; &#x; � &#abcdef0; &ThisIsNotDefined; &hi?;".into())), + }) + ], + children: vec![], + position: Some(Position::new(1, 1, 0, 1, 78, 77)) + }), + Node::Text(Text { + value: ".".to_string(), + position: Some(Position::new(1, 78, 77, 1, 79, 78)) + }) + ], + position: Some(Position::new(1, 1, 0, 1, 79, 78)) + })], + position: Some(Position::new(1, 1, 0, 1, 79, 78)) + }), + "should not support things that look like character references but aren’t" + ); + assert_eq!( micromark_to_mdast("a c", &mdx) .err() -- cgit