term2html

View Source

Generate HTML from Ehtml terms (a simple format used by Yaws).

Erlang CI Hex.pm Version License OTP Version

Installation

Add term2html to your rebar.config dependencies:

{deps, [{term2html, "1.1.0"}]}.

then fetch and compile:

rebar3 compile --deps_only

Example

A simple example:

term2html:expand({'div', [], "hello world!"}).
% Result: <div>hello world!</div>

A more complexe example:

Ehtml = {'div', [{class, toto}],
 [{p, [], <<"hëllo world"/utf8>>},
  {img, [{src, <<"https://eptwalabha.com/taco.png">>},
         {alt, <<"a taco">>}]},
  {br},
  <<"cool eh?">>]}.
term2html:expand(Ehtml).

will produce the following html:

<div class="toto"><p>hëllo world</p><img src="https://eptwalabha.com/taco.png" alt="a taco"><br>cool eh?</div>

ehtml Format

The ehtml term structure comes from Yaws' ehtml format:

{TagName}                           % Self-closing tag with no attributes
{TagName, Attributes}               % Tag with attributes, no content
{TagName, Attributes, Content}      % Complete tag (most common)
[Ehtml]                             % A list of any of all above

Where:

  • TagName: Atom representing the HTML tag (e.g., div, p, …)
  • Attributes: List of {Key, Value} tuples or bare atoms (e.g., disabled)
  • Content: String, binary, number, or nested ehtml terms