{"id":13688508,"url":"https://github.com/jugglerchris/rust-html2text","last_synced_at":"2025-05-14T19:04:47.239Z","repository":{"id":14784909,"uuid":"77090471","full_name":"jugglerchris/rust-html2text","owner":"jugglerchris","description":"Rust library to render HTML as text.","archived":false,"fork":false,"pushed_at":"2025-04-12T08:31:11.000Z","size":2013,"stargazers_count":188,"open_issues_count":10,"forks_count":31,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T09:24:39.756Z","etag":null,"topics":["hacktoberfest","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jugglerchris.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-21T22:25:51.000Z","updated_at":"2025-04-12T08:30:35.000Z","dependencies_parsed_at":"2024-02-10T10:26:54.090Z","dependency_job_id":"f78797e9-1891-45a9-90f3-195d529ab5f1","html_url":"https://github.com/jugglerchris/rust-html2text","commit_stats":{"total_commits":305,"total_committers":15,"mean_commits":"20.333333333333332","dds":"0.12786885245901636","last_synced_commit":"103b78be597ac42c47876315769f9f4db3328ac1"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jugglerchris%2Frust-html2text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jugglerchris%2Frust-html2text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jugglerchris%2Frust-html2text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jugglerchris%2Frust-html2text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jugglerchris","download_url":"https://codeload.github.com/jugglerchris/rust-html2text/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248545599,"owners_count":21122170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","rust"],"created_at":"2024-08-02T15:01:15.596Z","updated_at":"2025-05-14T19:04:47.226Z","avatar_url":"https://github.com/jugglerchris.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"[![jugglerchris](https://circleci.com/gh/jugglerchris/rust-html2text.svg?branch=master\u0026style=svg)](https://app.circleci.com/pipelines/github/jugglerchris/rust-html2text?filter=all)\n\n# html2text\n\nhtml2text is a [Rust](http://www.rust-lang.org/) crate which converts HTML to\nplain text (as in Rust `String`) or text spans with annotations like colours,\ne.g. optionally using CSS.  See [the online demo](https://jugglerchris.github.io/rust-html2text/)\nfor examples of the output.\n\nIt makes use of the [Servo project](https://github.com/servo/servo)'s HTML\nparser, [html5ever](https://github.com/servo/html5ever/), using the DOM to\ngenerate text (which can optionally include annotations for some features such\nas hyperlinks).\n\nThe project aims to do a reasonable job of rendering reasonable HTML in a\nterminal or other places where HTML needs to be converted to text (for\nexample the text/plain fallback in HTML e-mails).\n\nWith features (see below) some CSS/colour support is available.\n\n## Examples\n\nThe simple functions like `from_read()` return formatted text (in various\nformats including plain text).\n\n```rust\nuse html2text::from_read;\nlet html = b\"\n       \u003cul\u003e\n         \u003cli\u003eItem one\u003c/li\u003e\n         \u003cli\u003eItem two\u003c/li\u003e\n         \u003cli\u003eItem three\u003c/li\u003e\n       \u003c/ul\u003e\";\nassert_eq!(from_read(\u0026html[..], 20).unwrap(),\n           \"\\\n* Item one\n* Item two\n* Item three\n\");\n```\n\nA lower level API gives a bit more control.  This give the same result (except for\nreturning errors as Result instead of panicking):\n\n```rust\nuse html2text::config;\n\nlet html = b\"\n       \u003cul\u003e\n         \u003cli\u003eItem one\u003c/li\u003e\n         \u003cli\u003eItem two\u003c/li\u003e\n         \u003cli\u003eItem three\u003c/li\u003e\n       \u003c/ul\u003e\";\n\nassert_eq!(\n    config::plain()\n           .string_from_read(\u0026html[..], 20)\n           .unwrap(),\n    \"\\\n* Item one\n* Item two\n* Item three\n\");\n```\n\nA couple of simple demonstration programs are included as examples:\n\n### html2text\n\nThe simplest example uses `from_read` to convert HTML on stdin into plain\ntext:\n\n```sh\n$ cargo run --example html2text \u003c foo.html\n[...]\n```\n\n### html2term\n\nA very simple example of using the rich interface (`from_read_rich`) for a\nslightly interactive console HTML viewer is provided as `html2term`.\n\n```sh\n$ cargo run --example html2term foo.html\n[...]\n```\n\nNote that this example takes the HTML file as a parameter so that it can\nread keys from stdin.\n\n## Cargo Features\n\n|Feature| Description|\n|-------|------------|\n|css    | Limited handling of CSS, adding Coloured nodes to the render tree. |\n|html\\_trace| Add verbose internal logging (not recommended) |\n|html\\_trace\\_bt| Add backtraces to the verbose internal logging |\n\n### CSS support\n\nWhen the `css` feature is enabled, some simple CSS handling is available.\n\nStyle rules are taken from:\n* If `Config::use_doc_css()` is called, then style from the document:\n  * `\u003cstyle\u003e` elements\n  * Inline `style` attributes (`\u003cdiv style=\"...\"\u003e`)\n  * `\u003cfont color=...\u003e`\n* Independently of `use_doc_css`, extra rules can be added with `Config::add_css(...)`\n\nThe following CSS features are implemented:\n* Basic selector matching (including child and descendents, classes and element\n  types).\n* CSS colors (`color`/`background-color`) will add\n  `Coloured(...)`/`BgColoured(...)` nodes to the render tree.\n* Rules with `display: none` will cause matching elements to be removed from\n  the render tree.\n\nThe CSS handling is expected to improve in future (PRs welcome), but not to a full-\nblown browser style system, which would be overkill for terminal output.\n\nThere are two ways to make use of the colours:\n* Use `from_read_rich()` or one of its variants.  One of the annotations you may get\n  back is `Colour(..)`.\n* Use `from_read_coloured()`.  This is similar to `from_read()`, but you provide\n  a function to add terminal colours (or other styling) based on the same\n  RichAnnotations.  See examples/html2text.rs for an example using termion.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjugglerchris%2Frust-html2text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjugglerchris%2Frust-html2text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjugglerchris%2Frust-html2text/lists"}