Skip to content

Commit

Permalink
add render_html/1
Browse files Browse the repository at this point in the history
  • Loading branch information
bunopnu committed Sep 27, 2023
1 parent 7c36768 commit fc9eca2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/e2h.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%%%-----------------------------------------------------------------------------
-module(e2h).

-export([render/1, escape/1]).
-export([render_html/1, render/1, escape/1]).
-export_type([key/0, attributes/0, elements/0]).

%%%=============================================================================
Expand Down Expand Up @@ -50,6 +50,14 @@
%%% Public functions
%%%=============================================================================

%%------------------------------------------------------------------------------
%% @doc Similar to {@link render/1}, with a DOCTYPE declaration.
%% @end
%%------------------------------------------------------------------------------
-spec render_html(elements()) -> binary().
render_html(Elements) when is_list(Elements) ->
encode_elements(Elements, <<"<!DOCTYPE html>\n">>).

%%------------------------------------------------------------------------------
%% @doc Renders a list of structure into a binary representation of an
%% HTML document.
Expand All @@ -64,7 +72,7 @@
%%------------------------------------------------------------------------------
-spec render(elements()) -> binary().
render(Elements) when is_list(Elements) ->
encode_elements(Elements, <<"<!DOCTYPE html>\n">>).
encode_elements(Elements, <<>>).

%%------------------------------------------------------------------------------
%% @doc Escapes dangerous HTML characters within a binary data input.
Expand Down
2 changes: 1 addition & 1 deletion test/e2h_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ simple_render_test() ->

Rendered = e2h:render(Elements),
Expected =
<<"<!DOCTYPE html>\n<div class=\"test\"><h1>Hello, World!</h1><img src=\"https://example.com/image.png\" /></div>">>,
<<"<div class=\"test\"><h1>Hello, World!</h1><img src=\"https://example.com/image.png\" /></div>">>,
?assertEqual(Expected, Rendered).

0 comments on commit fc9eca2

Please # to comment.