Skip to content

Commit

Permalink
added href_target application option and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Montuori committed Sep 5, 2015
1 parent 8ef862e commit 0142b63
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/markdown.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ m_str1([{{inline, open}, O} | T], R, A) ->
[] -> [];
_ -> " title=\"" ++ Title ++ "\""
end,
Tag = [{tags, "<a href=\"" ++ Url ++ "\""
Tag = [{tags, make_href_open_tag() ++ Url ++ "\""
++ Tit ++ ">"}, Acc,
{tags, "</a>"} | []],
m_str1(Rest, R, [Tag | A]);
Expand All @@ -1090,7 +1090,7 @@ m_str1([{email, Addie} | T], R, A) ->
m_str1(T, R, [{tags, "\" />"}, Addie, {tags, "<a href=\"mailto:"}| A]);
m_str1([{url, Url} | T], R, A) ->
m_str1(T, R, [ {tags, "</a>"}, Url, {tags, "\">"}, Url,
{tags, "<a href=\""} | A]);
{tags, make_href_open_tag()} | A]);
m_str1([{tags, _} = Tag | T], R, A) ->
m_str1(T, R, [Tag | A]);
m_str1([{{{tag, Type}, Tag}, _} | T], R, A) ->
Expand Down Expand Up @@ -1282,10 +1282,29 @@ make_img_tag(Url, Acc, Title) ->
++ " title=\"" ++ Title ++ "\""
++ " />"}.

make_href_open_tag() ->
case application:get_env(markdown, href_target, undefined) of
undefined -> "<a href=\"";
Target -> "<a target=\"" ++ Target ++ "\" href=\""
end.



%%%-------------------------------------------------------------------
%%%
%%% Unit Tests
%%%
%%%-------------------------------------------------------------------

-include("markdown_tests.hrl").
href_no_target_test() ->
MDText = "[quux](http://example.com)",
?assertEqual("<p><a href=\"http://example.com\">quux</a></p>",
conv(MDText)).

href_target_test() ->
application:set_env(markdown, href_target, "_r"),
MDText = "[quux](http://example.com)",
?assertEqual("<p><a target=\"_r\" href=\"http://example.com\">quux</a></p>",
conv(MDText)).

0 comments on commit 0142b63

Please sign in to comment.