fuelen

fuelen

HTML2Text - extract readable plain text from HTML using Rust NIF

HTML2Text provides a simple and efficient way to extract readable plain text from HTML content. It leverages the power of Rust’s html2text crate to deliver fast HTML parsing and text extraction while maintaining the logical structure and readability of the content.

https://github.com/fuelen/html2text

Most Liked

fuelen

fuelen

v0.3.0 is out with two major additions: annotated rich text output and an inspectable HTML container.

Rich text (convert_rich/2)

Returns structured {text, [annotation]} tuples instead of formatted strings, so you can build your own renderer (Slack, Discord, email, etc.):

HTML2Text.convert_rich("<p>Hello <strong>world</strong></p>")
#=> {:ok, [[{"Hello ", []}, {"world", [:strong]}]]}

HTML2Text.convert_rich(~s(<a href="https://example.com"><em>click</em></a>))
#=> {:ok, [[{"click", [{:link, "https://example.com"}, :emphasis]}]]}

Annotations: :strong, :emphasis, :strikeout, :code, {:link, url}, {:image, src}, {:preformat, bool}, {:colour, {r, g, b}}, {:bg_colour, {r, g, b}}.

CSS colour extraction is supported via use_doc_css: true (parses <style> tags and inline styles).

HTML container (HTML2Text.HTML)

A struct that renders HTML as formatted text when inspected in IEx — bold, italic, clickable links (OSC 8), CSS true color, and more:

%{subject: "Alert", body: HTML2Text.HTML.new(email_html)}

# In IEx you see formatted text instead of raw tags:
# %{subject: "Alert", body: #HTML2Text.HTML<
#     Dear customer,
#     Your order has been shipped.
#   >}

Short content stays inline: #HTML2Text.HTML<bold>. to_string/1 returns the original HTML.

Other changes

  • empty_img_mode option: :ignore (default), {:replace, text}, or :filename
  • Updated html2text Rust crate from 0.15.1 to 0.16.7 (rowspan support, bug fixes)
  • HTML2Text.Error custom exception for bang functions
fuelen

fuelen

html2text v0.2.0 released — breaking changes and a cleaner API!

This version introduces a new, more consistent API with proper error handling and an optional keyword list for configuration.


What changed

Before (v0.1.x):

HTML2Text.convert(html, width)
# => returns plain string
  • The second argument was required and only accepted a width (integer or :infinity)
  • Errors (like width too narrow) would raise directly

Now (v0.2.0):

HTML2Text.convert(html, opts)
# => {:ok, result} | {:error, reason}

HTML2Text.convert!(html, opts)
# => result (raises on error)
  • convert/2 now returns {:ok, text} or {:error, reason}
  • convert!/2 is a new function that raises on error (for convenience)
  • The second parameter is now an optional keyword list of options

Where Next?

Popular in Announcing Top

Crowdhailer
Experimenting with this code. OK.try do user &lt;- fetch_user(1) cart &lt;- fetch_cart(1) order = checkout(cart, user) save_orde...
New
mspanc
I am pleased to announce an initial release of the Membrane Framework - an Elixir-based framework with special focus on processing multim...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
kip
ex_cldr provides localisation and internationalisation support based upon the data from the Unicode CLDR project. Unicode released CLDR ...
407 13366 120
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
zoltanszogyenyi
Hey everyone :waving_hand: Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-s...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement