11 releases

✓ Uses Rust 2018 edition

new 0.1.10 Feb 9, 2020
0.1.9 Feb 9, 2020
0.1.8 Jul 22, 2018
0.1.7 Feb 13, 2018
0.1.3 Dec 31, 2016

#19 in Template engine

Download history 29/week @ 2019-11-01 28/week @ 2019-11-08 63/week @ 2019-11-15 42/week @ 2019-11-22 127/week @ 2019-11-29 310/week @ 2019-12-06 269/week @ 2019-12-13 10/week @ 2019-12-20 46/week @ 2019-12-27 99/week @ 2020-01-03 258/week @ 2020-01-10 172/week @ 2020-01-17 141/week @ 2020-01-24 340/week @ 2020-01-31 291/week @ 2020-02-07

644 downloads per month
Used in 7 crates (3 directly)

MIT license

115KB
3K SLoC

Build Status Build status

html2text

html2text is a Rust crate which converts HTML to plain text.

It makes use of the Servo project's HTML parser, html5ever, using the DOM to generate text (which can optionally include annotations for some features such as hyperlinks).

The project aims to do a reasonable job of rendering reasonable HTML in a terminal or other places where HTML needs to be converted to text (for example the text/plain fallback in HTML e-mails).

Examples

use html2text::from_read;
let html = b"
       <ul>
         <li>Item one</li>
         <li>Item two</li>
         <li>Item three</li>
       </ul>";
assert_eq!(from_read(&html[..], 20),
           "\
* Item one
* Item two
* Item three
");

A couple of simple demonstration programs are included as examples:

html2text

The simplest example uses from_read to convert HTML on stdin into plain text:

$ cargo run --example html2text < foo.html
[...]

html2term

A very simple example of using the rich interface (from_read_rich) for a slightly interactive console HTML viewer is provided as html2term.

$ cargo run --example html2term foo.html
[...]

Note that this example takes the HTML file as a parameter so that it can read keys from stdin.

Dependencies

~1–1.4MB
~30K SLoC