Module e2h

HTML generator for Erlang ecosystem.

Authors: bunopnu.

Description

HTML generator for Erlang ecosystem.

e2h is an Erlang module designed to generate HTML within the Erlang ecosystem, allowing Erlang developers to efficiently create HTML documents and elements from structured data.

Data Types

attributes()

attributes() = [{binary(), binary()} | binary()]

Represents a list of HTML attribute-value pairs.

Example

  Attributes = [{<<"type">>, <<"password">>}, {<<"id">>, <<"my-element">>}, <<"disabled">>].
  % Represents attributes like: type="password" id="my-element" disabled

elements()

elements() = [{binary(), attributes(), elements()} | {binary(), attributes()} | binary()]

Represents structured HTML elements or raw content.

Example

  Elements = [
   {<<"div">>, [{<<"class">>, <<"container">>}], [
     {<<"p">>, [], [<<"This is a paragraph.">>]},
     {<<"a">>, [{<<"href">>, <<"#">>}], [<<"Click me">>]},
     {<<"img">>, [{<<"src">>, <<"https://example.com/image.png">>}]}
   ]}
  ].

Function Index

escape/1Escapes dangerous HTML characters within a binary data input.
render_fragment/1Renders a list of structure into a binary representation of an HTML document.
render_html/1Similar to render_fragment/1, with a DOCTYPE declaration.

Function Details

escape/1

escape(Data::binary()) -> binary()

Escapes dangerous HTML characters within a binary data input.

Parameters

Data - The binary data to be escaped.

Returns

The escaped binary data.

Example

  Unescaped = <<"Suspicious <script>alert(1)</script> document!">>,
  Escaped = e2h:escape(Unescaped).
  % <<"Suspicious &lt;script&gt;alert(1)&lt;/script&gt; document!">>

render_fragment/1

render_fragment(Elements::elements()) -> binary()

Renders a list of structure into a binary representation of an HTML document.

Parameters

Elements - A list of structure, conforming to the elements() type.

Returns

A binary representation of the HTML document.

render_html/1

render_html(Elements::elements()) -> binary()

Similar to render_fragment/1, with a DOCTYPE declaration.


Generated by EDoc