aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-06-12 07:45:29 +0200
committerLoïc Hoguin <[email protected]>2018-06-12 18:35:54 +0200
commit9224a497d79acbb8ce5690bf8dd9e19855e50586 (patch)
treee6a188f6e58aa421efc60bf73fda02d1cdbf0cce
parentff3a48cd25a671f456614e79f1c05d77f4ca08ff (diff)
downloadasciideck-9224a497d79acbb8ce5690bf8dd9e19855e50586.tar.gz
asciideck-9224a497d79acbb8ce5690bf8dd9e19855e50586.tar.bz2
asciideck-9224a497d79acbb8ce5690bf8dd9e19855e50586.zip
Fix table cells containing blocks
-rw-r--r--src/asciideck_tables_pass.erl48
-rw-r--r--src/asciideck_to_html.erl17
-rw-r--r--test/parser_SUITE.erl19
3 files changed, 46 insertions, 38 deletions
diff --git a/src/asciideck_tables_pass.erl b/src/asciideck_tables_pass.erl
index fdda6ef..c0740cc 100644
--- a/src/asciideck_tables_pass.erl
+++ b/src/asciideck_tables_pass.erl
@@ -40,19 +40,19 @@ table({table, Attrs, Contents, Ann}) ->
table_test() ->
{table, _, [
{row, _, [
- {cell, _, <<"1">>, _},
- {cell, _, <<"2">>, _},
- {cell, _, <<"A">>, _}
+ {cell, _, [{paragraph, _, <<"1">>, _}], _},
+ {cell, _, [{paragraph, _, <<"2">>, _}], _},
+ {cell, _, [{paragraph, _, <<"A">>, _}], _}
], _},
{row, _, [
- {cell, _, <<"3">>, _},
- {cell, _, <<"4">>, _},
- {cell, _, <<"B">>, _}
+ {cell, _, [{paragraph, _, <<"3">>, _}], _},
+ {cell, _, [{paragraph, _, <<"4">>, _}], _},
+ {cell, _, [{paragraph, _, <<"B">>, _}], _}
], _},
{row, _, [
- {cell, _, <<"5">>, _},
- {cell, _, <<"6">>, _},
- {cell, _, <<"C">>, _}
+ {cell, _, [{paragraph, _, <<"5">>, _}], _},
+ {cell, _, [{paragraph, _, <<"6">>, _}], _},
+ {cell, _, [{paragraph, _, <<"C">>, _}], _}
], _}
], _} = table({table, #{}, <<
"|1 |2 |A\n"
@@ -112,7 +112,7 @@ do_parse_cells([Contents], Acc) ->
lists:reverse([{cell, #{specifiers => <<>>}, Contents, #{}}|Acc]);
%% Last cell. There are no further cell specifiers.
do_parse_cells([Specs, Contents0], Acc) ->
- Contents = asciideck_block_parser:trim(Contents0, both),
+ Contents = asciideck_block_parser:parse(Contents0),
%% @todo Annotations.
Cell = {cell, #{specifiers => Specs}, Contents, #{}},
lists:reverse([Cell|Acc]);
@@ -123,7 +123,7 @@ do_parse_cells([Specs, Contents0|Tail], Acc) ->
NextSpecs = <<>>, %% @todo find_r(Contents0, <<>>),
Len = byte_size(Contents0) - byte_size(NextSpecs),
<<Contents1:Len/binary, _/bits>> = Contents0,
- Contents = asciideck_block_parser:trim(Contents1, both),
+ Contents = asciideck_block_parser:parse(Contents1),
%% @todo Annotations.
Cell = {cell, #{specifiers => Specs}, Contents, #{}},
do_parse_cells([NextSpecs|Tail], [Cell|Acc]).
@@ -141,15 +141,15 @@ do_parse_cells([Specs, Contents0|Tail], Acc) ->
-ifdef(TEST).
parse_table_test() ->
{[
- {cell, _, <<"1">>, _},
- {cell, _, <<"2">>, _},
- {cell, _, <<"A">>, _},
- {cell, _, <<"3">>, _},
- {cell, _, <<"4">>, _},
- {cell, _, <<"B">>, _},
- {cell, _, <<"5">>, _},
- {cell, _, <<"6">>, _},
- {cell, _, <<"C">>, _}
+ {cell, _, [{paragraph, _, <<"1">>, _}], _},
+ {cell, _, [{paragraph, _, <<"2">>, _}], _},
+ {cell, _, [{paragraph, _, <<"A">>, _}], _},
+ {cell, _, [{paragraph, _, <<"3">>, _}], _},
+ {cell, _, [{paragraph, _, <<"4">>, _}], _},
+ {cell, _, [{paragraph, _, <<"B">>, _}], _},
+ {cell, _, [{paragraph, _, <<"5">>, _}], _},
+ {cell, _, [{paragraph, _, <<"6">>, _}], _},
+ {cell, _, [{paragraph, _, <<"C">>, _}], _}
], 3} = parse_table(<<
"|1 |2 |A\n"
"|3 |4 |B\n"
@@ -158,10 +158,10 @@ parse_table_test() ->
parse_table_escape_pipe_test() ->
{[
- {cell, _, <<"1">>, _},
- {cell, _, <<"2">>, _},
- {cell, _, <<"3 |4">>, _},
- {cell, _, <<"5">>, _}
+ {cell, _, [{paragraph, _, <<"1">>, _}], _},
+ {cell, _, [{paragraph, _, <<"2">>, _}], _},
+ {cell, _, [{paragraph, _, <<"3 |4">>, _}], _},
+ {cell, _, [{paragraph, _, <<"5">>, _}], _}
], 2} = parse_table(<<
"|1 |2\n"
"|3 \\|4 |5">>, #{}),
diff --git a/src/asciideck_to_html.erl b/src/asciideck_to_html.erl
index 6f8a393..ab0aa98 100644
--- a/src/asciideck_to_html.erl
+++ b/src/asciideck_to_html.erl
@@ -169,16 +169,25 @@ table({table, _, [{row, _, Head, _}|Rows], _}) ->
].
table_head(Cells) ->
- [["<th>", inline(Text), "</th>\n"]
- || {cell, _, Text, _} <- Cells].
+ [["<th>", table_cell(AST), "</th>\n"]
+ || {cell, _, AST, _} <- Cells].
table_body(Rows) ->
[["<tr>", table_body_cells(Cells), "</tr>\n"]
|| {row, _, Cells, _} <- Rows].
table_body_cells(Cells) ->
- [["<td>", inline(Text), "</td>\n"]
- || {cell, _, Text, _} <- Cells].
+ [["<td>", table_cell(AST), "</td>\n"]
+ || {cell, _, AST, _} <- Cells].
+
+table_cell(AST0) ->
+ AST = [Node || Node={Type, _, _, _} <- AST0, Type =/= comment_line],
+ case AST of
+ [{paragraph, _, Text, _}] ->
+ inline(Text);
+ _ ->
+ ast(AST)
+ end.
%% Block macros.
diff --git a/test/parser_SUITE.erl b/test/parser_SUITE.erl
index e5eda88..f3b4b27 100644
--- a/test/parser_SUITE.erl
+++ b/test/parser_SUITE.erl
@@ -404,22 +404,21 @@ comment_line(_) ->
%% Tables. (23)
table(_) ->
- %% @todo I think I read somewhere that paragraphs are not allowed in cells... Double check.
[{table, _, [
{row, _, [
- {cell, _, <<"1">>, _},
- {cell, _, <<"2">>, _},
- {cell, _, <<"A">>, _}
+ {cell, _, [{paragraph, _, <<"1">>, _}], _},
+ {cell, _, [{paragraph, _, <<"2">>, _}], _},
+ {cell, _, [{paragraph, _, <<"A">>, _}], _}
], _},
{row, _, [
- {cell, _, <<"3">>, _},
- {cell, _, <<"4">>, _},
- {cell, _, <<"B">>, _}
+ {cell, _, [{paragraph, _, <<"3">>, _}], _},
+ {cell, _, [{paragraph, _, <<"4">>, _}], _},
+ {cell, _, [{paragraph, _, <<"B">>, _}], _}
], _},
{row, _, [
- {cell, _, <<"5">>, _},
- {cell, _, <<"6">>, _},
- {cell, _, <<"C">>, _}
+ {cell, _, [{paragraph, _, <<"5">>, _}], _},
+ {cell, _, [{paragraph, _, <<"6">>, _}], _},
+ {cell, _, [{paragraph, _, <<"C">>, _}], _}
], _}
], _}]= parse(
"|=======\n"