Rust Html2text

screenshot of Rust Html2text

Rust library to render HTML as text.

Overview

The jugglerchrishtml2texthtml2text Rust crate is an impressive tool designed to convert HTML content into plain text. Its functionality is particularly useful in scenarios where displaying HTML isn't feasible, such as in terminal applications or when dealing with text/plain email fallbacks. Utilizing the Servo project’s robust HTML parser, html5ever, this crate not only extracts text but can also incorporate CSS-based color annotations, enhancing the output in a simple yet effective manner.

This utility provides both straightforward and advanced options for users. The simple API makes it easy to quickly transform HTML from standard input into text, while a more sophisticated interface offers additional control over the conversion process. Overall, it serves a specific yet valuable niche for those needing reliable HTML to text conversion in Rust environments.

Features

  • CSS Support: Limited handling of CSS that allows colors to be added to the rendered text, enhancing visibility.

  • Simple API: Functions like from_read() quickly convert HTML input into formatted plain text, perfect for straightforward use cases.

  • Rich API: A lower-level API provides more granular control over the conversion process, useful for advanced users needing specific results.

  • Interactive Console Viewer: Includes a demonstration program (html2term) that functions as a basic interactive console HTML viewer, allowing for real-time rendering.

  • Annotation Support: Capable of outputting text spans with annotations such as hyperlinks, adding depth to the plain text output.

  • Verbose Logging Options: Features like html_trace offer detailed internal logging for debugging purposes, although not recommended for regular use.

  • Custom CSS Integration: Users can add their own CSS rules independently for enhanced customization of rendered outputs.

  • Continuous Improvement: The CSS handling is expected to improve over time, encouraging contributions for further enhancements.