Skip to content

sftse/rust-html2text

This branch is 431 commits behind jugglerchris/rust-html2text:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a852fe0 · Nov 6, 2022
Oct 16, 2022
Oct 28, 2021
Jun 19, 2020
Sep 15, 2021
Nov 6, 2022
Sep 8, 2016
Oct 16, 2022
Oct 16, 2022
Dec 21, 2016
Mar 6, 2022
Oct 28, 2021

Repository files navigation

jugglerchris

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.

About

Rust library to render HTML as text.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%