html2text API demo
An online demonstration of the
html2text
Rust crate. Edit
the HTML below and see how html2text
converts it for text or terminal
display.
This demo uses html2text
compiled to WASM, which can run in any modern
browser, with ratzilla for the web-based
terminal output.
Output
The html2text output is updated here:
Input HTML
Edit the HTML here - the output will update live.
Configuration
The following are the configuration settings (accessible via html2text::config
).
Use Rich output | The rich mode returns spans with attributes (like hyperlinks, emphasis, or colours). When disabled (plain ), the output is a plain String (possibly with formatting depending on other settings, e.g. table borders or **markdown-style** characters added). Rich output adds extra information (annotations) to allow, for example, using terminal colours and other features for a nicer TUI. |
use_doc_css | Parse CSS from the HTML document (css) |
User CSS | Add user stylesheet rules (css) |
Agent CSS | Add browser stylesheet rules (css) |
Pad block width | Pad blocks to the width with spaces |
Text wrap width | Wrap text to this width even if overall width is wider |
Allow width overflow | Allow text to be too wide in extreme cases instead of returning an error |
Minimum wrap width | Set the minimum number of columns to use for text blocks. |
Raw mode | Render contents of tables as if they were just text. Implies no_table_borders |
Don’t render table borders | Tables are shown without borders |
Don’t wrap URLs at the end | Some terminals handle long URLs better if not pre-wrapped |
Use Unicode combining characters for strikeout | This allows crossed out text without terminal codes, but some environments don’t render them correctly (e.g. offset). |
Add markdown-like decoration | Add characters, e.g. * around <em> text even with plain decorators. |
URL footnotes | Add numbered list of URLs at the end of the output |
Rust API configuration
The code below shows how to use the currently selected settings in the Rust API.