Skip to content

Commit bb15e69

Browse files
committed
Add gfm_task_list_item test suite.
1 parent b4b7516 commit bb15e69

File tree

4 files changed

+779
-10
lines changed

4 files changed

+779
-10
lines changed

apps/markdown/src/html/markdown_html.erl

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ enter(CompileContext1 = #markdown_html_compile_context{events = Events, index =
601601
gfm_table_cell -> on_enter_gfm_table_cell(CompileContext1);
602602
gfm_table_head -> on_enter_gfm_table_head(CompileContext1);
603603
gfm_table_row -> on_enter_gfm_table_row(CompileContext1);
604-
% gfm_task_list_item_check -> on_enter_gfm_task_list_item_check(CompileContext1);
604+
gfm_task_list_item_check -> on_enter_gfm_task_list_item_check(CompileContext1);
605605
html_flow -> on_enter_html_flow(CompileContext1);
606606
html_text -> on_enter_html_text(CompileContext1);
607607
image -> on_enter_image(CompileContext1);
@@ -811,6 +811,25 @@ on_enter_gfm_table_row(CompileContext1 = #markdown_html_compile_context{}) ->
811811
CompileContext3 = markdown_html_compile_context:push(CompileContext2, <<"<tr>"/utf8>>),
812812
CompileContext3.
813813

814+
%% @private
815+
-doc """
816+
Handle [`Enter`][Kind::Enter]:[`GfmTaskListItemCheck`][Name::GfmTaskListItemCheck].
817+
""".
818+
-spec on_enter_gfm_task_list_item_check(CompileContext) -> CompileContext when
819+
CompileContext :: markdown_html_compile_context:t().
820+
on_enter_gfm_task_list_item_check(CompileContext1 = #markdown_html_compile_context{image_alt_inside = false}) ->
821+
CompileContext2 = markdown_html_compile_context:push(CompileContext1, <<"<input type=\"checkbox\" "/utf8>>),
822+
CompileContext3 =
823+
case CompileContext2#markdown_html_compile_context.options of
824+
#markdown_compile_options{gfm_task_list_item_checkable = false} ->
825+
markdown_html_compile_context:push(CompileContext2, <<"disabled=\"\" "/utf8>>);
826+
_ ->
827+
CompileContext2
828+
end,
829+
CompileContext3;
830+
on_enter_gfm_task_list_item_check(CompileContext1 = #markdown_html_compile_context{}) ->
831+
CompileContext1.
832+
814833
%% @private
815834
-doc """
816835
Handle [`Enter`][Kind::Enter]:[`HtmlFlow`][Name::HtmlFlow].
@@ -1085,8 +1104,8 @@ exit(CompileContext1 = #markdown_html_compile_context{events = Events, index = I
10851104
gfm_table_cell -> on_exit_gfm_table_cell(CompileContext1);
10861105
gfm_table_head -> on_exit_gfm_table_head(CompileContext1);
10871106
gfm_table_row -> on_exit_gfm_table_row(CompileContext1);
1088-
% gfm_task_list_item_check -> on_exit_gfm_task_list_item_check(CompileContext1);
1089-
% gfm_task_list_item_value_checked -> on_exit_gfm_task_list_item_value_checked(CompileContext1);
1107+
gfm_task_list_item_check -> on_exit_gfm_task_list_item_check(CompileContext1);
1108+
gfm_task_list_item_value_checked -> on_exit_gfm_task_list_item_value_checked(CompileContext1);
10901109
hard_break_escape -> on_exit_break(CompileContext1);
10911110
hard_break_trailing -> on_exit_break(CompileContext1);
10921111
heading_atx -> on_exit_heading_atx(CompileContext1);
@@ -1734,6 +1753,30 @@ on_exit_gfm_table_row__phantom_cells(CompileContext1 = #markdown_html_compile_co
17341753
on_exit_gfm_table_row__phantom_cells(CompileContext, _Column, _Len) ->
17351754
CompileContext.
17361755

1756+
%% @private
1757+
-doc """
1758+
Handle [`Exit`][Kind::Exit]:[`GfmTaskListItemCheck`][Name::GfmTaskListItemCheck].
1759+
""".
1760+
-spec on_exit_gfm_task_list_item_check(CompileContext) -> CompileContext when
1761+
CompileContext :: markdown_html_compile_context:t().
1762+
on_exit_gfm_task_list_item_check(CompileContext1 = #markdown_html_compile_context{image_alt_inside = false}) ->
1763+
CompileContext2 = markdown_html_compile_context:push(CompileContext1, <<"/>"/utf8>>),
1764+
CompileContext2;
1765+
on_exit_gfm_task_list_item_check(CompileContext1 = #markdown_html_compile_context{}) ->
1766+
CompileContext1.
1767+
1768+
%% @private
1769+
-doc """
1770+
Handle [`Exit`][Kind::Exit]:[`GfmTaskListItemValueChecked`][Name::GfmTaskListItemValueChecked].
1771+
""".
1772+
-spec on_exit_gfm_task_list_item_value_checked(CompileContext) -> CompileContext when
1773+
CompileContext :: markdown_html_compile_context:t().
1774+
on_exit_gfm_task_list_item_value_checked(CompileContext1 = #markdown_html_compile_context{image_alt_inside = false}) ->
1775+
CompileContext2 = markdown_html_compile_context:push(CompileContext1, <<"checked=\"\" "/utf8>>),
1776+
CompileContext2;
1777+
on_exit_gfm_task_list_item_value_checked(CompileContext1 = #markdown_html_compile_context{}) ->
1778+
CompileContext1.
1779+
17371780
%% @private
17381781
-doc """
17391782
Handle [`Exit`][Kind::Exit]:[`HeadingAtx`][Name::HeadingAtx].

apps/markdown/src/mdast/markdown_mdast.erl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ on_exit_list_item__move_past_eol(Bytes = <<Byte1:8, _/bytes>>, Point1 = #markdow
22052205
->
22062206
Point2 = Point1#markdown_unist_point{
22072207
offset = Point1#markdown_unist_point.offset + 1,
2208-
column = Point1#markdown_unist_point.column + 1,
2208+
column = 1,
22092209
line = Point1#markdown_unist_point.line + 1
22102210
},
22112211
Start2 = Start1 + 1,
@@ -2235,13 +2235,14 @@ on_exit_list_item__node_mut_func(
22352235
ParagraphNode1 = #markdown_mdast_node{
22362236
inner = Paragraph1 = #markdown_mdast_paragraph{position = {some, ParagraphPosition1}}
22372237
}} ->
2238-
ParagraphChildren1 = ParagraphNode1#markdown_mdast_paragraph.children,
2238+
ParagraphChildren1 = Paragraph1#markdown_mdast_paragraph.children,
22392239
case markdown_vec:first_option(ParagraphChildren1) of
22402240
{some,
22412241
TextNode1 = #markdown_mdast_node{
22422242
inner =
22432243
Text1 = #markdown_mdast_text{
2244-
position = {some, #markdown_unist_position{start = Point1}}, value = Bytes
2244+
position = {some, TextPosition1 = #markdown_unist_position{start = Point1}},
2245+
value = Bytes
22452246
}
22462247
}} ->
22472248
Start1 = 0,
@@ -2256,17 +2257,16 @@ on_exit_list_item__node_mut_func(
22562257
Paragraph1#markdown_mdast_paragraph{
22572258
children = ParagraphChildren2, position = {some, ParagraphPosition2}
22582259
};
2259-
_ ->
2260-
<<TextValue1:Start2/bytes, _/bytes>> = Bytes,
2260+
Len ->
2261+
TextValue1 = binary:part(Bytes, Start2, Len - Start2),
22612262
TextValue2 = markdown_types:unicode_binary(TextValue1),
2262-
{some, TextPosition1} = Text1#markdown_mdast_text.position,
22632263
TextPosition2 = TextPosition1#markdown_unist_position{start = Point2},
22642264
Text2 = Text1#markdown_mdast_text{
22652265
value = TextValue2,
22662266
position = {some, TextPosition2}
22672267
},
22682268
TextNode2 = TextNode1#markdown_mdast_node{inner = Text2},
2269-
ParagraphChildren2 = markdown_vec:set(ParagraphPosition1, 0, TextNode2),
2269+
ParagraphChildren2 = markdown_vec:set(ParagraphChildren1, 0, TextNode2),
22702270
ParagraphPosition2 = ParagraphPosition1#markdown_unist_position{start = Point2},
22712271
Paragraph1#markdown_mdast_paragraph{
22722272
children = ParagraphChildren2, position = {some, ParagraphPosition2}

0 commit comments

Comments
 (0)