aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asciideck_parser.erl27
-rw-r--r--src/asciideck_to_manpage.erl9
2 files changed, 30 insertions, 6 deletions
diff --git a/src/asciideck_parser.erl b/src/asciideck_parser.erl
index 7b2ee76..f7a61d7 100644
--- a/src/asciideck_parser.erl
+++ b/src/asciideck_parser.erl
@@ -180,16 +180,35 @@ p1_li_glob([{LN, <<"+">>}|Tail], Acc) ->
p1_li_glob([Line|Tail], Acc) ->
p1_li_glob(Tail, [Line|Acc]).
+%% Skip initial empty lines and then glob like normal lists.
+p1_ll_glob(Lines=[{_, Line}|Tail]) ->
+io:format("line ~s~n", [Line]),
+ case trim_ws(Line) of
+ <<>> -> p1_ll_glob(Tail);
+ _ -> p1_ll_glob(Lines, [])
+ end.
+
+%% Glob everything until empty line.
+%% @todo Detect next list.
+p1_ll_glob(Tail = [{LN, <<>>}|_], Acc) ->
+ {Tail, lists:reverse([{LN, <<>>}|Acc])};
+p1_ll_glob([{LN, <<"+">>}|Tail], Acc) ->
+ p1_ll_glob(Tail, [{LN, <<>>}|Acc]);
+p1_ll_glob([Line|Tail], Acc) ->
+ p1_ll_glob(Tail, [Line|Acc]).
+
p1_text(Lines=[{LN, Line}|Tail], AST, St) ->
case binary:split(<< Line/binary, $\s >>, <<":: ">>) of
%% Nothing else on the line.
[Label, <<>>] ->
- p1(Tail, [{label, Label, ann(LN, St)}|AST], St);
+ {Tail1, Glob} = p1_ll_glob(Tail),
+ p1(Tail1, [{label, Label, p1(Glob, [], St), ann(LN, St)}|AST], St);
%% Text on the same line.
[Label, Text0] ->
Size = byte_size(Text0) - 1,
<< Text:Size/binary, _ >> = Text0,
- p1([{LN, Text}|Tail], [{label, Label, ann(LN, St)}|AST], St);
+ {Tail1, Glob} = p1_ll_glob([{LN, Text}|Tail]),
+ p1(Tail1, [{label, Label, p1(Glob, [], St), ann(LN, St)}|AST], St);
%% Not a labeled list.
_ ->
p1_maybe_p(Lines, AST, St)
@@ -274,9 +293,9 @@ format(<< C, Rest/bits >>, LN, St, Acc, BinAcc, _) ->
p2([], Acc) ->
lists:reverse(Acc);
-p2([{label, Label, Ann}, Item|Tail], Acc) ->
+p2([{label, Label, Item, Ann}|Tail], Acc) ->
%% @todo Handle this like other lists.
- p2(Tail, [ll([li([Item], #{label => Label}, Ann)], #{}, Ann)|Acc]);
+ p2(Tail, [ll([li(Item, #{label => Label}, Ann)], #{}, Ann)|Acc]);
p2(Tail0=[{uli1, _, UlAnn}|_], Acc) ->
{LIs0, Tail} = lists:splitwith(fun({uli1, _, _}) -> true; (_) -> false end, Tail0),
LIs = [li(I, LiAnn) || {uli1, I, LiAnn} <- LIs0],
diff --git a/src/asciideck_to_manpage.erl b/src/asciideck_to_manpage.erl
index fffd250..33187ea 100644
--- a/src/asciideck_to_manpage.erl
+++ b/src/asciideck_to_manpage.erl
@@ -111,15 +111,20 @@ man([_Ignore|Tail], Acc) ->
man_ll([], Acc) ->
Acc;
-man_ll([{li, #{label := Label}, [{p, _PAttrs, Text, _PAnn}], _LiAnn}|Tail], Acc0) ->
+man_ll([{li, #{label := Label}, Item, _LiAnn}|Tail], Acc0) ->
Acc = [[
".PP\n"
"\\fB", Label, "\\fR\n",
".RS 4\n",
- man_format(Text), "\n"
+ man_ll_item(Item),
".RE\n"]|Acc0],
man_ll(Tail, Acc).
+man_ll_item([{p, _PAttrs, Text, _PAnn}]) ->
+ [man_format(Text), "\n"];
+man_ll_item([{p, _PAttrs, Text, _PAnn}|Tail]) ->
+ [man_format(Text), "\n\n", man_ll_item(Tail)].
+
man_ul([], Acc) ->
Acc;
man_ul([{li, _LiAttrs, [{p, _PAttrs, Text, _PAnn}], _LiAnn}|Tail], Acc0) ->