Skip to content

Commit df32dce

Browse files
committed
Add html_flow test suite.
1 parent 6458ccd commit df32dce

File tree

3 files changed

+3382
-9
lines changed

3 files changed

+3382
-9
lines changed

apps/markdown/src/mdast/markdown_mdast.erl

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,11 @@ enter(CompileContext1 = #markdown_mdast_compile_context{events = Events, index =
300300
on_enter_heading(CompileContext1);
301301
heading_setext ->
302302
on_enter_heading(CompileContext1);
303-
% %% on_enter_html
304-
% html_flow -> on_enter_html(CompileContext1);
305-
% html_text -> on_enter_html(CompileContext1);
303+
%% on_enter_html
304+
html_flow ->
305+
on_enter_html(CompileContext1);
306+
html_text ->
307+
on_enter_html(CompileContext1);
306308
%% on_enter_image
307309
image ->
308310
on_enter_image(CompileContext1);
@@ -717,6 +719,24 @@ on_enter_heading(CompileContext1 = #markdown_mdast_compile_context{}) ->
717719
),
718720
{ok, CompileContext2}.
719721

722+
%% @private
723+
-doc """
724+
Handle [`Enter`][Kind::Enter]:{[`HtmlFlow`][Name::HtmlFlow],[`HtmlText`][Name::HtmlText]}.
725+
""".
726+
-spec on_enter_html(CompileContext) -> {ok, CompileContext} when
727+
CompileContext :: markdown_mdast_compile_context:t().
728+
on_enter_html(CompileContext1 = #markdown_mdast_compile_context{}) ->
729+
CompileContext2 =
730+
markdown_mdast_compile_context:tail_push(
731+
CompileContext1,
732+
markdown_mdast_node:html(#markdown_mdast_html{
733+
value = <<>>,
734+
position = none
735+
})
736+
),
737+
CompileContext3 = markdown_mdast_compile_context:buffer(CompileContext2),
738+
{ok, CompileContext3}.
739+
720740
%% @private
721741
-doc """
722742
Handle [`Enter`][Kind::Enter]:[`Image`][Name::Image].
@@ -1351,9 +1371,11 @@ exit(CompileContext1 = #markdown_mdast_compile_context{events = Events, index =
13511371
%% on_exit_gfm_table
13521372
gfm_table ->
13531373
on_exit_gfm_table(CompileContext1);
1354-
% %% on_exit_gfm_task_list_item_value
1355-
% gfm_task_list_item_value_unchecked -> on_exit_gfm_task_list_item_value(CompileContext1);
1356-
% gfm_task_list_item_value_checked -> on_exit_gfm_task_list_item_value(CompileContext1);
1374+
%% on_exit_gfm_task_list_item_value
1375+
gfm_task_list_item_value_unchecked ->
1376+
on_exit_gfm_task_list_item_value(CompileContext1);
1377+
gfm_task_list_item_value_checked ->
1378+
on_exit_gfm_task_list_item_value(CompileContext1);
13571379
%% on_exit_hard_break
13581380
hard_break_escape ->
13591381
on_exit_hard_break(CompileContext1);
@@ -1371,9 +1393,11 @@ exit(CompileContext1 = #markdown_mdast_compile_context{events = Events, index =
13711393
%% on_exit_heading_setext_text
13721394
heading_setext_text ->
13731395
on_exit_heading_setext_text(CompileContext1);
1374-
% %% on_exit_html
1375-
% html_flow -> on_exit_html(CompileContext1);
1376-
% html_text -> on_exit_html(CompileContext1);
1396+
%% on_exit_html
1397+
html_flow ->
1398+
on_exit_html(CompileContext1);
1399+
html_text ->
1400+
on_exit_html(CompileContext1);
13771401
%% on_exit_label_text
13781402
label_text ->
13791403
on_exit_label_text(CompileContext1);
@@ -1851,6 +1875,33 @@ on_exit_gfm_table(CompileContext1 = #markdown_mdast_compile_context{}) ->
18511875
{ok, CompileContext3}
18521876
end.
18531877

1878+
%% @private
1879+
-doc """
1880+
Handle [`Exit`][Kind::Exit]:{[`GfmTaskListItemValueChecked`][Name::GfmTaskListItemValueChecked],[`GfmTaskListItemValueUnchecked`][Name::GfmTaskListItemValueUnchecked]}.
1881+
""".
1882+
-spec on_exit_gfm_task_list_item_value(CompileContext) -> {ok, CompileContext} when
1883+
CompileContext :: markdown_mdast_compile_context:t().
1884+
on_exit_gfm_task_list_item_value(CompileContext1 = #markdown_mdast_compile_context{events = Events, index = Index}) ->
1885+
Event = markdown_vec:get(Events, Index),
1886+
Checked = Event#markdown_event.name =:= gfm_task_list_item_value_checked,
1887+
NodeMutFunc = fun on_exit_gfm_task_list_item_value__node_mut_func/2,
1888+
{CompileContext2, none} = markdown_mdast_compile_context:tail_penultimate_mut(
1889+
CompileContext1, {some, Checked}, NodeMutFunc
1890+
),
1891+
{ok, CompileContext2}.
1892+
1893+
%% @private
1894+
-spec on_exit_gfm_task_list_item_value__node_mut_func(Node, OptionChecked) -> {Node, OptionChecked} when
1895+
Node :: markdown_mdast_node:t(), OptionChecked :: markdown_option:t(Checked), Checked :: boolean().
1896+
on_exit_gfm_task_list_item_value__node_mut_func(
1897+
Node1 = #markdown_mdast_node{inner = ListItem1 = #markdown_mdast_list_item{}}, {some, Checked}
1898+
) ->
1899+
ListItem2 = ListItem1#markdown_mdast_list_item{checked = {some, Checked}},
1900+
Node2 = Node1#markdown_mdast_node{inner = ListItem2},
1901+
{Node2, none};
1902+
on_exit_gfm_task_list_item_value__node_mut_func(_Node, {some, _Checked}) ->
1903+
?'unreachable!'("expected list item on stack", []).
1904+
18541905
%% @private
18551906
-doc """
18561907
Handle [`Exit`][Kind::Exit]:{[`HardBreakEscape`][Name::HardBreakEscape],[`HardBreakTrailing`][Name::HardBreakTrailing]}.
@@ -1953,6 +2004,29 @@ on_exit_heading_setext_underline_sequence__node_mut_func(
19532004
on_exit_heading_setext_underline_sequence__node_mut_func(_Node = #markdown_mdast_node{}, {some, _Depth}) ->
19542005
?'unreachable!'("expected heading on stack", []).
19552006

2007+
%% @private
2008+
-doc """
2009+
Handle [`Exit`][Kind::Exit]:{[`HtmlFlow`][Name::HtmlFlow],[`HtmlText`][Name::HtmlText]}.
2010+
""".
2011+
-spec on_exit_html(CompileContext) -> {ok, CompileContext} | {error, Message} when
2012+
CompileContext :: markdown_mdast_compile_context:t(), Message :: markdown_message:t().
2013+
on_exit_html(CompileContext1 = #markdown_mdast_compile_context{}) ->
2014+
{CompileContext2, Node} = markdown_mdast_compile_context:resume(CompileContext1),
2015+
Value = markdown_mdast_node:to_string(Node),
2016+
NodeMutFunc = fun on_exit_html__node_mut_func/2,
2017+
{CompileContext3, none} = markdown_mdast_compile_context:tail_mut(CompileContext2, {some, Value}, NodeMutFunc),
2018+
on_exit(CompileContext3).
2019+
2020+
%% @private
2021+
-spec on_exit_html__node_mut_func(Node, OptionValue) -> {Node, OptionValue} when
2022+
Node :: markdown_mdast_node:t(), OptionValue :: markdown_option:t(Value), Value :: unicode:unicode_binary().
2023+
on_exit_html__node_mut_func(Node1 = #markdown_mdast_node{inner = Html1 = #markdown_mdast_html{}}, {some, Value}) ->
2024+
Html2 = Html1#markdown_mdast_html{value = Value},
2025+
Node2 = Node1#markdown_mdast_node{inner = Html2},
2026+
{Node2, none};
2027+
on_exit_html__node_mut_func(_Node = #markdown_mdast_node{}, {some, _Value}) ->
2028+
?'unreachable!'("expected html on stack for value", []).
2029+
19562030
%% @private
19572031
-doc """
19582032
Handle [`Exit`][Kind::Exit]:[`LabelText`][Name::LabelText].

0 commit comments

Comments
 (0)