diff options
author | Loïc Hoguin <[email protected]> | 2018-06-13 08:19:49 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-06-13 08:19:49 +0200 |
commit | d65f9d77c2eb178b90dec869c5fecf87921378a3 (patch) | |
tree | e4d195430437e3eb30dda36de360a537064ebbce | |
parent | 4ec11af08a901592867eb510296f9729590793b3 (diff) | |
download | asciideck-d65f9d77c2eb178b90dec869c5fecf87921378a3.tar.gz asciideck-d65f9d77c2eb178b90dec869c5fecf87921378a3.tar.bz2 asciideck-d65f9d77c2eb178b90dec869c5fecf87921378a3.zip |
Add mailto links
-rw-r--r-- | src/asciideck_inline_pass.erl | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/asciideck_inline_pass.erl b/src/asciideck_inline_pass.erl index 4bc4017..e14f31e 100644 --- a/src/asciideck_inline_pass.erl +++ b/src/asciideck_inline_pass.erl @@ -63,6 +63,7 @@ inline(Data, BinAcc, Acc) -> fun link/2, fun http_link/2, fun https_link/2, + fun mailto_link/2, %% Quoted text. fun emphasized_single_quote/2, fun emphasized_underline/2, @@ -163,7 +164,7 @@ link_test() -> ok. -endif. -%% Asciidoc User Guide 21.1.3 +%% Asciidoc User Guide 21.1.1 http_link(<<"http:", Rest/bits>>, Prev) when ?IS_BOUNDARY(Prev) -> direct_link(Rest, <<"http:">>). @@ -185,9 +186,16 @@ direct_link(Data, Prefix) -> C =/= $] end, Caption0), Caption = trim(Caption1), - {ok, {link, #{ - target => Target - }, Caption, inline}, Rest}; + case Caption of + <<>> -> + {ok, {link, #{ + target => Target + }, Target, inline}, Rest}; + _ -> + {ok, {link, #{ + target => Target + }, Caption, inline}, Rest} + end; _ -> {ok, {link, #{ target => Target @@ -227,7 +235,7 @@ http_link_test() -> ok. -endif. -%% Asciidoc User Guide 21.1.3 +%% Asciidoc User Guide 21.1.1 https_link(<<"https:", Rest/bits>>, Prev) when ?IS_BOUNDARY(Prev) -> direct_link(Rest, <<"https:">>). @@ -264,6 +272,30 @@ https_link_test() -> ok. -endif. +%% Asciidoc User Guide 21.1.1 +mailto_link(<<"mailto:", Rest0/bits>>, Prev) when ?IS_BOUNDARY(Prev) -> + {ok, {link, Attrs, Caption0, Ann}, Rest} = direct_link(Rest0, <<"mailto:">>), + Caption = case Caption0 of + <<"mailto:", Caption1/bits>> -> Caption1; + _ -> Caption0 + end, + {ok, {link, Attrs, Caption, Ann}, Rest}. + +-ifdef(TEST). +mailto_link_test() -> + [ + {link, #{ + target := <<"mailto:[email protected]">> + }, <<"email Joe Bloggs">>, _} + ] = inline(<<"mailto:[email protected][email Joe Bloggs]">>), + [ + {link, #{ + target := <<"mailto:[email protected]">> + }, <<"[email protected]">>, _} + ] = inline(<<"mailto:[email protected][]">>), + ok. +-endif. + %% Asciidoc User Guide 10.1 %% @todo <<"\\**" %% @todo <<"\\*" |