39 | 39 |
table_test() ->
|
40 | 40 |
{table, _, [
|
41 | 41 |
{row, _, [
|
42 | |
{cell, _, <<"1">>, _},
|
43 | |
{cell, _, <<"2">>, _},
|
44 | |
{cell, _, <<"A">>, _}
|
|
42 |
{cell, _, [{paragraph, _, <<"1">>, _}], _},
|
|
43 |
{cell, _, [{paragraph, _, <<"2">>, _}], _},
|
|
44 |
{cell, _, [{paragraph, _, <<"A">>, _}], _}
|
45 | 45 |
], _},
|
46 | 46 |
{row, _, [
|
47 | |
{cell, _, <<"3">>, _},
|
48 | |
{cell, _, <<"4">>, _},
|
49 | |
{cell, _, <<"B">>, _}
|
|
47 |
{cell, _, [{paragraph, _, <<"3">>, _}], _},
|
|
48 |
{cell, _, [{paragraph, _, <<"4">>, _}], _},
|
|
49 |
{cell, _, [{paragraph, _, <<"B">>, _}], _}
|
50 | 50 |
], _},
|
51 | 51 |
{row, _, [
|
52 | |
{cell, _, <<"5">>, _},
|
53 | |
{cell, _, <<"6">>, _},
|
54 | |
{cell, _, <<"C">>, _}
|
|
52 |
{cell, _, [{paragraph, _, <<"5">>, _}], _},
|
|
53 |
{cell, _, [{paragraph, _, <<"6">>, _}], _},
|
|
54 |
{cell, _, [{paragraph, _, <<"C">>, _}], _}
|
55 | 55 |
], _}
|
56 | 56 |
], _} = table({table, #{}, <<
|
57 | 57 |
"|1 |2 |A\n"
|
|
111 | 111 |
lists:reverse([{cell, #{specifiers => <<>>}, Contents, #{}}|Acc]);
|
112 | 112 |
%% Last cell. There are no further cell specifiers.
|
113 | 113 |
do_parse_cells([Specs, Contents0], Acc) ->
|
114 | |
Contents = asciideck_block_parser:trim(Contents0, both),
|
|
114 |
Contents = asciideck_block_parser:parse(Contents0),
|
115 | 115 |
%% @todo Annotations.
|
116 | 116 |
Cell = {cell, #{specifiers => Specs}, Contents, #{}},
|
117 | 117 |
lists:reverse([Cell|Acc]);
|
|
122 | 122 |
NextSpecs = <<>>, %% @todo find_r(Contents0, <<>>),
|
123 | 123 |
Len = byte_size(Contents0) - byte_size(NextSpecs),
|
124 | 124 |
<<Contents1:Len/binary, _/bits>> = Contents0,
|
125 | |
Contents = asciideck_block_parser:trim(Contents1, both),
|
|
125 |
Contents = asciideck_block_parser:parse(Contents1),
|
126 | 126 |
%% @todo Annotations.
|
127 | 127 |
Cell = {cell, #{specifiers => Specs}, Contents, #{}},
|
128 | 128 |
do_parse_cells([NextSpecs|Tail], [Cell|Acc]).
|
|
140 | 140 |
-ifdef(TEST).
|
141 | 141 |
parse_table_test() ->
|
142 | 142 |
{[
|
143 | |
{cell, _, <<"1">>, _},
|
144 | |
{cell, _, <<"2">>, _},
|
145 | |
{cell, _, <<"A">>, _},
|
146 | |
{cell, _, <<"3">>, _},
|
147 | |
{cell, _, <<"4">>, _},
|
148 | |
{cell, _, <<"B">>, _},
|
149 | |
{cell, _, <<"5">>, _},
|
150 | |
{cell, _, <<"6">>, _},
|
151 | |
{cell, _, <<"C">>, _}
|
|
143 |
{cell, _, [{paragraph, _, <<"1">>, _}], _},
|
|
144 |
{cell, _, [{paragraph, _, <<"2">>, _}], _},
|
|
145 |
{cell, _, [{paragraph, _, <<"A">>, _}], _},
|
|
146 |
{cell, _, [{paragraph, _, <<"3">>, _}], _},
|
|
147 |
{cell, _, [{paragraph, _, <<"4">>, _}], _},
|
|
148 |
{cell, _, [{paragraph, _, <<"B">>, _}], _},
|
|
149 |
{cell, _, [{paragraph, _, <<"5">>, _}], _},
|
|
150 |
{cell, _, [{paragraph, _, <<"6">>, _}], _},
|
|
151 |
{cell, _, [{paragraph, _, <<"C">>, _}], _}
|
152 | 152 |
], 3} = parse_table(<<
|
153 | 153 |
"|1 |2 |A\n"
|
154 | 154 |
"|3 |4 |B\n"
|
|
157 | 157 |
|
158 | 158 |
parse_table_escape_pipe_test() ->
|
159 | 159 |
{[
|
160 | |
{cell, _, <<"1">>, _},
|
161 | |
{cell, _, <<"2">>, _},
|
162 | |
{cell, _, <<"3 |4">>, _},
|
163 | |
{cell, _, <<"5">>, _}
|
|
160 |
{cell, _, [{paragraph, _, <<"1">>, _}], _},
|
|
161 |
{cell, _, [{paragraph, _, <<"2">>, _}], _},
|
|
162 |
{cell, _, [{paragraph, _, <<"3 |4">>, _}], _},
|
|
163 |
{cell, _, [{paragraph, _, <<"5">>, _}], _}
|
164 | 164 |
], 2} = parse_table(<<
|
165 | 165 |
"|1 |2\n"
|
166 | 166 |
"|3 \\|4 |5">>, #{}),
|