A container for HTML content with rich terminal inspection.
Stores raw HTML and renders it as formatted text with ANSI styles when inspected in IEx. Useful for working with data that contains HTML — instead of seeing raw tags, you see readable formatted text with bold, italic, colours, clickable links, and other styles applied.
to_string/1 returns the original HTML unchanged.
Usage
Wrap any HTML string to make it inspectable:
html = HTML2Text.HTML.new("<p>Hello <strong>world</strong></p>")
#=> #HTML2Text.HTML<Hello **world**>Works naturally inside data structures:
# In an Ecto schema or any map
%{subject: "Alert", body: HTML2Text.HTML.new(email_html)}
# In IEx you see formatted text instead of raw HTML tags:
# %{subject: "Alert", body: #HTML2Text.HTML<
# Dear customer,
#
# Your order has been **shipped**.
# Track it here: https://example.com/track
# >}Supported styles
The following HTML elements are rendered with ANSI terminal styles:
| HTML | Terminal style |
|---|---|
<strong>, <b> | Bold |
<em>, <i> | Italic |
<code> | Cyan |
<s>, <del> | Strikeout |
<a href="..."> | Blue underline, clickable (OSC 8) |
<img> | Yellow |
<pre> | Faint |
CSS color | True color (24-bit RGB) |
CSS background-color | True color (24-bit RGB) |
CSS colours are extracted when the HTML contains <style> tags or inline styles.
Examples
iex> html = HTML2Text.HTML.new("<p>Hello <strong>world</strong></p>")
iex> to_string(html)
"<p>Hello <strong>world</strong></p>"
Summary
Functions
Creates a new HTML container from a source string.
Types
@type t() :: %HTML2Text.HTML{source: String.t()}