https://github.com/fuelen/html2text
HTML to text via Rust NIF
https://github.com/fuelen/html2text
converter html nif text
Last synced: 3 months ago
JSON representation
HTML to text via Rust NIF
- Host: GitHub
- URL: https://github.com/fuelen/html2text
- Owner: fuelen
- License: mit
- Created: 2025-06-12T21:04:26.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-06-24T19:34:00.000Z (4 months ago)
- Last Synced: 2025-06-27T11:56:50.704Z (3 months ago)
- Topics: converter, html, nif, text
- Language: Elixir
- Homepage:
- Size: 25.4 KB
- Stars: 24
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# HTML2Text
[](https://hex.pm/packages/html2text)A high-performance Elixir library for converting HTML documents to plain text format using Rust NIFs (Native Implemented Functions).
## Overview
HTML2Text provides a simple and efficient way to extract readable plain text from HTML content. It leverages the power of Rust's [html2text](https://crates.io/crates/html2text) crate to deliver fast HTML parsing and text extraction while maintaining the logical structure and readability of the content.
## Installation
Add `html2text` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:html2text, "~> 0.2"}
]
end
```Then run:
```bash
mix deps.get
```## Usage
```elixir
# Convert with specific line width
html = "Welcome
This is a sample paragraph with some content.
"
text = HTML2Text.convert!(html, width: 30)
IO.puts(text)# Output:
# # Welcome
#
# This is a sample paragraph
# with some content.html = """
Article Title
Introduction: This article covers important topics.
Section 1
Content with emphasis and links.
- Point one
- Point two
Section 2: Simple Table
Key metrics overview:
Metric
Value
Change
Users
15,300
+12%
Sessions
48,500
-5%
Conclusion
This article provided an overview of important web technologies and some key statistics.
"""
text = HTML2Text.convert!(html)
IO.puts(text)
# Output:
# # Article Title
#
# **Introduction:** This article covers important topics.
#
# ## Section 1
#
# Content with *emphasis* and [links][1].
# * Point one
# * Point two
#
# ## Section 2: Simple Table
#
# Key metrics overview:
#
# ────────┬──────┬──────
# Metric │Value │Change
# ────────┼──────┼──────
# Users │15,300│+12%
# ────────┼──────┼──────
# Sessions│48,500│-5%
# ────────┴──────┴──────
#
# ## Conclusion
#
# This article provided an overview of important web technologies and some key
# statistics.
#
# [1]: http://example.com
```