https://github.com/k3a/html2text
Simple Go package to convert HTML to plain text
https://github.com/k3a/html2text
go golang html package plain text
Last synced: 5 months ago
JSON representation
Simple Go package to convert HTML to plain text
- Host: GitHub
- URL: https://github.com/k3a/html2text
- Owner: k3a
- License: mit
- Created: 2017-05-05T17:24:38.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2026-01-09T16:07:46.000Z (6 months ago)
- Last Synced: 2026-01-11T11:32:03.501Z (6 months ago)
- Topics: go, golang, html, package, plain, text
- Language: Go
- Size: 65.4 KB
- Stars: 160
- Watchers: 4
- Forks: 23
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/k3a/html2text)
[](https://github.com/k3a/html2text/actions/workflows/test.yml)
[](https://github.com/k3a/html2text/tree/badges)
[](https://goreportcard.com/report/github.com/k3a/html2text)
# html2text
A simple Golang package to convert HTML to plain text (without non-standard dependencies).
It converts HTML tags to text and also parses HTML entities into characters they represent.
A `` section of the HTML document, as well as most other tags are stripped out but
links are properly converted into their href attribute.
It can be used for converting HTML emails into text.
Some tests are installed as well.
Uses semantic versioning and no breaking changes are planned.
Fell free to publish a pull request if you have suggestions for improvement but please note that the library can now be considered feature-complete and API stable. If you need more than this basic conversion, please use an alternative mentioned at the bottom.
## Install
```bash
go get github.com/k3a/html2text
```
## Usage
```go
package main
import (
"fmt"
"github.com/k3a/html2text"
)
func main() {
html := `Goodclean text`
plain := html2text.HTML2Text(html)
fmt.Println(plain)
}
/* Outputs:
clean text
*/
```
To see all features, please look info `html2text_test.go`.
## Alternatives
- https://github.com/jaytaylor/html2text (heavier, with more features)
- https://git.sr.ht/~aw/nanohtml2text (rewrite of this module in Rust)
## License
MIT