An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# HTML2Text
[![Hex.pm](https://img.shields.io/hexpm/v/html2text.svg)](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
```