diff --git a/src/construct/mdx_expression_flow.rs b/src/construct/mdx_expression_flow.rs index 32403c9a..5d4591b5 100644 --- a/src/construct/mdx_expression_flow.rs +++ b/src/construct/mdx_expression_flow.rs @@ -150,9 +150,10 @@ pub fn end(tokenizer: &mut Tokenizer) -> State { Some(b'<') if tokenizer.parse_state.options.constructs.mdx_jsx_flow => { // We can’t just say: fine. // Lines of blocks have to be parsed until an eol/eof. + tokenizer.tokenize_state.token_1 = Name::MdxJsxFlowTag; tokenizer.attempt( - State::Next(StateName::MdxExpressionFlowAfter), - State::Next(StateName::MdxExpressionFlowNok), + State::Next(StateName::MdxJsxFlowAfter), + State::Next(StateName::MdxJsxFlowNok), ); State::Retry(StateName::MdxJsxStart) } @@ -171,17 +172,6 @@ pub fn end(tokenizer: &mut Tokenizer) -> State { } } -/// At something that wasn’t an MDX expression (flow). -/// -/// ```markdown -/// > | {A} x -/// ^ -/// ``` -pub fn nok(tokenizer: &mut Tokenizer) -> State { - reset(tokenizer); - State::Nok -} - /// Reset state. fn reset(tokenizer: &mut Tokenizer) { tokenizer.concrete = false; diff --git a/src/state.rs b/src/state.rs index 84c963b5..cb32ea8a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -357,7 +357,6 @@ pub enum Name { MdxExpressionFlowBefore, MdxExpressionFlowAfter, MdxExpressionFlowEnd, - MdxExpressionFlowNok, MdxExpressionStart, MdxExpressionBefore, @@ -844,7 +843,6 @@ pub fn call(tokenizer: &mut Tokenizer, name: Name) -> State { Name::MdxExpressionFlowBefore => construct::mdx_expression_flow::before, Name::MdxExpressionFlowAfter => construct::mdx_expression_flow::after, Name::MdxExpressionFlowEnd => construct::mdx_expression_flow::end, - Name::MdxExpressionFlowNok => construct::mdx_expression_flow::nok, Name::MdxExpressionTextStart => construct::mdx_expression_text::start, Name::MdxExpressionTextAfter => construct::mdx_expression_text::after, diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs index c05bd5b9..d4733bf2 100644 --- a/tests/mdx_jsx_text.rs +++ b/tests/mdx_jsx_text.rs @@ -1,8 +1,8 @@ mod test_utils; use markdown::{ mdast::{ - AttributeContent, AttributeValue, AttributeValueExpression, Emphasis, MdxJsxAttribute, - MdxJsxTextElement, Node, Paragraph, Root, Text, + AttributeContent, AttributeValue, AttributeValueExpression, Emphasis, MdxFlowExpression, + MdxJsxAttribute, MdxJsxFlowElement, MdxJsxTextElement, Node, Paragraph, Root, Text, }, message, to_html_with_options, to_mdast, unist::Position, @@ -48,6 +48,45 @@ fn mdx_jsx_text_core() -> Result<(), message::Message> { "should support markdown inside elements" ); + assert_eq!( + to_mdast("{1}", &mdx.parse)?, + Node::Root(Root { + children: vec![ + Node::MdxFlowExpression(MdxFlowExpression { + value: "1".into(), + position: Some(Position::new(1, 1, 0, 1, 4, 3)), + stops: vec![(0, 1)] + }), + Node::MdxJsxFlowElement(MdxJsxFlowElement { + name: Some("a".into()), + attributes: vec![], + children: vec![], + position: Some(Position::new(1, 4, 3, 1, 8, 7)) + }) + ], + position: Some(Position::new(1, 1, 0, 1, 8, 7)) + }), + "should support mdx jsx (text) with expression child" + ); + + assert_eq!( + to_mdast("{1}", &mdx.parse)?, + Node::Root(Root { + children: vec![Node::MdxJsxFlowElement(MdxJsxFlowElement { + name: Some("a".into()), + attributes: vec![], + children: vec![Node::MdxFlowExpression(MdxFlowExpression { + value: "1".into(), + position: Some(Position::new(1, 4, 3, 1, 7, 6)), + stops: vec![(0, 4)] + })], + position: Some(Position::new(1, 1, 0, 1, 11, 10)) + }),], + position: Some(Position::new(1, 1, 0, 1, 11, 10)) + }), + "should support mdx jsx (text) with expression child" + ); + assert_eq!( to_mdast("a c.", &mdx.parse)?, Node::Root(Root {