Skip to content

Commit 412c063

Browse files
committed
Fix remaining issues with mdx_expression_flow test suite.
1 parent 4b8cb45 commit 412c063

File tree

3 files changed

+353
-136
lines changed

3 files changed

+353
-136
lines changed

apps/markdown/src/mdast/markdown_mdast.erl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,9 +1303,11 @@ exit(CompileContext1 = #markdown_mdast_compile_context{events = Events, index =
13031303
on_exit_data(CompileContext1);
13041304
mdx_jsx_tag_attribute_value_literal_value ->
13051305
on_exit_data(CompileContext1);
1306-
% %% on_exit_drop
1307-
% mdx_jsx_tag_attribute_expression -> on_exit_drop(CompileContext1);
1308-
% mdx_jsx_tag_attribute_value_expression -> on_exit_drop(CompileContext1);
1306+
%% on_exit_drop
1307+
mdx_jsx_tag_attribute_expression ->
1308+
on_exit_drop(CompileContext1);
1309+
mdx_jsx_tag_attribute_value_expression ->
1310+
on_exit_drop(CompileContext1);
13091311
%% on_exit_autolink_protocol
13101312
autolink_protocol ->
13111313
on_exit_autolink_protocol(CompileContext1);
@@ -1695,6 +1697,16 @@ on_exit_data__node_mut_func(
16951697
on_exit_data__node_mut_func(_Node = #markdown_mdast_node{}, {some, _Value}) ->
16961698
?'unreachable!'("expected text on stack", []).
16971699

1700+
%% @private
1701+
-doc """
1702+
Handle [`Exit`][Kind::Exit]:*, by dropping the current buffer.
1703+
""".
1704+
-spec on_exit_drop(CompileContext) -> {ok, CompileContext} when
1705+
CompileContext :: markdown_mdast_compile_context:t().
1706+
on_exit_drop(CompileContext1 = #markdown_mdast_compile_context{}) ->
1707+
{CompileContext2, _Node} = markdown_mdast_compile_context:resume(CompileContext1),
1708+
{ok, CompileContext2}.
1709+
16981710
%% @private
16991711
-doc """
17001712
Handle [`Exit`][Kind::Exit]:[`DefinitionDestinationString`][Name::DefinitionDestinationString].

apps/markdown_test/test/markdown_mdx_expression_flow_SUITE.erl

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%%% % DO NOT EDIT: this file was generated by 'just codegen'
2-
%%% % @generated SignedSource<<d765ec1870e25364c6d9bc74e10939ab>>
2+
%%% % @generated SignedSource<<1be490fcba975f57ac66c486642172f8>>
33
%%%-----------------------------------------------------------------------------
44
%%% %CopyrightBegin%
55
%%%
@@ -74,6 +74,10 @@
7474
test_mdx_expression_flow_case_20/1,
7575
test_mdx_expression_flow_case_21/1,
7676
test_mdx_expression_flow_case_22/1,
77+
test_mdx_expression_flow_case_23/1,
78+
test_mdx_expression_flow_case_24/1,
79+
test_mdx_expression_flow_case_25/1,
80+
test_mdx_expression_flow_case_26/1,
7781
test_mdx_expression_flow_case_27/1
7882
]).
7983

@@ -132,6 +136,10 @@ groups() ->
132136
test_mdx_expression_flow_case_20,
133137
test_mdx_expression_flow_case_21,
134138
test_mdx_expression_flow_case_22,
139+
test_mdx_expression_flow_case_23,
140+
test_mdx_expression_flow_case_24,
141+
test_mdx_expression_flow_case_25,
142+
test_mdx_expression_flow_case_26,
135143
test_mdx_expression_flow_case_27
136144
]}
137145
].
@@ -441,6 +449,175 @@ test_mdx_expression_flow_case_22(_Config) ->
441449
),
442450
ok.
443451

452+
-spec test_mdx_expression_flow_case_23(Config) -> markdown_test:testcase() when
453+
Config :: ct_suite:ct_config().
454+
test_mdx_expression_flow_case_23(_Config) ->
455+
?assertEqual(
456+
{ok,
457+
markdown_mdast_node:root(#markdown_mdast_root{
458+
children = ?'vec!'([
459+
markdown_mdast_node:blockquote(#markdown_mdast_blockquote{
460+
children = ?'vec!'([
461+
markdown_mdast_node:paragraph(#markdown_mdast_paragraph{
462+
children = ?'vec!'([
463+
markdown_mdast_node:text(#markdown_mdast_text{
464+
value = <<"aaa ">>,
465+
position = {some, markdown_unist_position:new(1, 4, 3, 1, 8, 7)}
466+
}),
467+
markdown_mdast_node:mdx_jsx_text_element(#markdown_mdast_mdx_jsx_text_element{
468+
children = ?'vec!'([]),
469+
name = {some, <<"b">>},
470+
attributes = ?'vec!'([
471+
markdown_mdast_attribute_content:property(#markdown_mdast_mdx_jsx_attribute{
472+
name = <<"c">>,
473+
value =
474+
{some,
475+
markdown_mdast_attribute_value:expression(
476+
#markdown_mdast_attribute_value_expression{
477+
value = <<"`\n d\n`">>,
478+
stops = ?'vec!'([
479+
markdown_mdast_stop:new(0, 13),
480+
markdown_mdast_stop:new(1, 14),
481+
markdown_mdast_stop:new(2, 19),
482+
markdown_mdast_stop:new(6, 23),
483+
markdown_mdast_stop:new(7, 27)
484+
])
485+
}
486+
)}
487+
})
488+
]),
489+
position = {some, markdown_unist_position:new(1, 8, 7, 3, 9, 32)}
490+
}),
491+
markdown_mdast_node:text(#markdown_mdast_text{
492+
value = <<" eee">>,
493+
position = {some, markdown_unist_position:new(3, 9, 32, 3, 13, 36)}
494+
})
495+
]),
496+
position = {some, markdown_unist_position:new(1, 3, 2, 3, 13, 36)}
497+
})
498+
]),
499+
position = {some, markdown_unist_position:new(1, 1, 0, 3, 13, 36)}
500+
})
501+
]),
502+
position = {some, markdown_unist_position:new(1, 1, 0, 3, 13, 36)}
503+
})},
504+
markdown:to_mdast(<<"> aaa <b c={`\n> d\n> `} /> eee"/utf8>>, ?swc_parse),
505+
"should support template strings in JSX (text) in block quotes"
506+
),
507+
ok.
508+
509+
-spec test_mdx_expression_flow_case_24(Config) -> markdown_test:testcase() when
510+
Config :: ct_suite:ct_config().
511+
test_mdx_expression_flow_case_24(_Config) ->
512+
?assertEqual(
513+
{ok,
514+
markdown_mdast_node:root(#markdown_mdast_root{
515+
children = ?'vec!'([
516+
markdown_mdast_node:blockquote(#markdown_mdast_blockquote{
517+
children = ?'vec!'([
518+
markdown_mdast_node:paragraph(#markdown_mdast_paragraph{
519+
children = ?'vec!'([
520+
markdown_mdast_node:text(#markdown_mdast_text{
521+
value = <<"ab ">>,
522+
position = {some, markdown_unist_position:new(1, 3, 2, 1, 6, 5)}
523+
}),
524+
markdown_mdast_node:mdx_text_expression(#markdown_mdast_mdx_text_expression{
525+
value = <<"`\n`">>,
526+
stops = ?'vec!'([
527+
markdown_mdast_stop:new(0, 6),
528+
markdown_mdast_stop:new(1, 7),
529+
markdown_mdast_stop:new(2, 10)
530+
]),
531+
position = {some, markdown_unist_position:new(1, 6, 5, 2, 7, 12)}
532+
})
533+
]),
534+
position = {some, markdown_unist_position:new(1, 3, 2, 2, 7, 12)}
535+
})
536+
]),
537+
position = {some, markdown_unist_position:new(1, 1, 0, 2, 7, 12)}
538+
})
539+
]),
540+
position = {some, markdown_unist_position:new(1, 1, 0, 2, 7, 12)}
541+
})},
542+
markdown:to_mdast(<<"> ab {`\n>\t`}"/utf8>>, ?swc_parse),
543+
"should use correct positional when there are virtual spaces due to a block quote"
544+
),
545+
ok.
546+
547+
-spec test_mdx_expression_flow_case_25(Config) -> markdown_test:testcase() when
548+
Config :: ct_suite:ct_config().
549+
test_mdx_expression_flow_case_25(_Config) ->
550+
?assertEqual(
551+
{ok,
552+
markdown_mdast_node:root(#markdown_mdast_root{
553+
children = ?'vec!'([
554+
markdown_mdast_node:blockquote(#markdown_mdast_blockquote{
555+
children = ?'vec!'([
556+
markdown_mdast_node:mdx_flow_expression(#markdown_mdast_mdx_flow_expression{
557+
value = <<"`\nalpha\nbravo\ncharlie\n delta\n`">>,
558+
position = {some, markdown_unist_position:new(1, 3, 2, 6, 5, 49)},
559+
stops = ?'vec!'([
560+
markdown_mdast_stop:new(0, 3),
561+
markdown_mdast_stop:new(1, 4),
562+
markdown_mdast_stop:new(2, 7),
563+
markdown_mdast_stop:new(7, 12),
564+
markdown_mdast_stop:new(8, 16),
565+
markdown_mdast_stop:new(13, 21),
566+
markdown_mdast_stop:new(14, 26),
567+
markdown_mdast_stop:new(21, 33),
568+
markdown_mdast_stop:new(22, 38),
569+
markdown_mdast_stop:new(28, 44),
570+
markdown_mdast_stop:new(29, 47)
571+
])
572+
})
573+
]),
574+
position = {some, markdown_unist_position:new(1, 1, 0, 6, 5, 49)}
575+
})
576+
]),
577+
position = {some, markdown_unist_position:new(1, 1, 0, 6, 5, 49)}
578+
})},
579+
markdown:to_mdast(<<"> {`\n> alpha\n> bravo\n> charlie\n> delta\n> `}"/utf8>>, ?swc_parse),
580+
"should keep the correct number of spaces in a blockquote (flow)"
581+
),
582+
ok.
583+
584+
-spec test_mdx_expression_flow_case_26(Config) -> markdown_test:testcase() when
585+
Config :: ct_suite:ct_config().
586+
test_mdx_expression_flow_case_26(_Config) ->
587+
?assertEqual(
588+
{ok,
589+
markdown_mdast_node:root(#markdown_mdast_root{
590+
children = ?'vec!'([
591+
markdown_mdast_node:blockquote(#markdown_mdast_blockquote{
592+
children = ?'vec!'([
593+
markdown_mdast_node:mdx_flow_expression(#markdown_mdast_mdx_flow_expression{
594+
value = <<"`\nalpha\nbravo\ncharlie\n delta\n`">>,
595+
position = {some, markdown_unist_position:new(1, 3, 2, 6, 5, 49)},
596+
stops = ?'vec!'([
597+
markdown_mdast_stop:new(0, 3),
598+
markdown_mdast_stop:new(1, 4),
599+
markdown_mdast_stop:new(2, 7),
600+
markdown_mdast_stop:new(7, 12),
601+
markdown_mdast_stop:new(8, 16),
602+
markdown_mdast_stop:new(13, 21),
603+
markdown_mdast_stop:new(14, 26),
604+
markdown_mdast_stop:new(21, 33),
605+
markdown_mdast_stop:new(22, 38),
606+
markdown_mdast_stop:new(28, 44),
607+
markdown_mdast_stop:new(29, 47)
608+
])
609+
})
610+
]),
611+
position = {some, markdown_unist_position:new(1, 1, 0, 6, 5, 49)}
612+
})
613+
]),
614+
position = {some, markdown_unist_position:new(1, 1, 0, 6, 5, 49)}
615+
})},
616+
markdown:to_mdast(<<"> {`\n> alpha\n> bravo\n> charlie\n> delta\n> `}"/utf8>>, ?swc_parse),
617+
"should keep the correct number of spaces in a blockquote (flow)"
618+
),
619+
ok.
620+
444621
-spec test_mdx_expression_flow_case_27(Config) -> markdown_test:testcase() when
445622
Config :: ct_suite:ct_config().
446623
test_mdx_expression_flow_case_27(_Config) ->

0 commit comments

Comments
 (0)