From 3e29ee974ebbb8774ddf9ebba4582ff465e1a087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 12 Jun 2018 18:30:45 +0200 Subject: Parse table cols specs and add caption if any --- src/asciideck_tables_pass.erl | 135 +++++++++++++++++++++++++++++++++++++++++- src/asciideck_to_html.erl | 9 ++- 2 files changed, 139 insertions(+), 5 deletions(-) diff --git a/src/asciideck_tables_pass.erl b/src/asciideck_tables_pass.erl index c0740cc..1adcd1e 100644 --- a/src/asciideck_tables_pass.erl +++ b/src/asciideck_tables_pass.erl @@ -81,10 +81,139 @@ parse_table(Contents, _) -> {Cells, length(Cells0)} end. +%% @todo Don't discard Specs. num_cols(Cols) -> - %% @todo Handle column specifiers. - Specs = binary:split(Cols, <<$,>>, [global]), - length(Specs). + try binary_to_integer(Cols) of + Int -> Int + catch _:_ -> + Specs0 = binary:split(Cols, <<$,>>, [global]), + Specs = [parse_specs(Spec) || Spec <- Specs0], + lists:sum([M || #{multiplier := M} <- Specs]) + end. + +-ifdef(TEST). +num_cols_test_() -> + Tests = [ + {<<"4">>, 4}, + {<<">s,^m,e">>, 3}, + {<<"3,^2,^2,10">>, 4}, + {<<"^1,4*2">>, 5}, + {<<"e,m,^,>s">>, 4}, + {<<"2">>, 5}, + {<<"4*<">>, 4}, + {<<"3*.^">>, 3}, + {<<"2*,.>">>, 3}, + {<<".<,.^,.>">>, 3}, + {<<".<,.^,^.>">>, 3} + ], + [{V, fun() -> R = num_cols(V) end} || {V, R} <- Tests]. +-endif. + +%% Asciidoc User Guide 23.4 +%% +%% [*][][.][][