A simple Golang package to convert HTML to plain text, with no external dependencies. It processes input character-by-character in a single pass, with occasional forward lookups (e.g., for HTML entities).
The conversion:
inner text <link> format when the WithLinksInnerText option is enabled.The primary use case is converting HTML emails into plain text.
The package includes a comprehensive test suite in html2text_test.go. It follows semantic versioning, and no breaking changes are planned.
Feel free to submit a pull request with suggestions for improvement. However, please note that the library is now considered feature-complete and API‑stable. If you require more advanced functionality or need to regularly process malformed HTML input, you should consider using an alternative package listed below.
go get github.com/k3a/html2text
package main
import (
"fmt"
"github.com/k3a/html2text"
)
func main() {
html := `<html><head><title>Good</title></head><body><strong>clean</strong> text</body>`
plain := html2text.HTML2Text(html)
fmt.Println(plain)
}
/* Outputs:
clean text
*/
Note: The output is plain text, do not embed the result back into HTML without escaping.
To see all features in action, take a look at html2text_test.go.
MIT
185 followers · starred May 2023
88 followers · starred May 2024
98 followers · starred Oct 2020
6 followers · starred May 2026
A simple Golang package to convert HTML to plain text, with no external dependencies. It processes input character-by-character in a single pass, with occasional forward lookups (e.g., for HTML entities).
The conversion:
inner text <link> format when the WithLinksInnerText option is enabled.The primary use case is converting HTML emails into plain text.
The package includes a comprehensive test suite in html2text_test.go. It follows semantic versioning, and no breaking changes are planned.
Feel free to submit a pull request with suggestions for improvement. However, please note that the library is now considered feature-complete and API‑stable. If you require more advanced functionality or need to regularly process malformed HTML input, you should consider using an alternative package listed below.
go get github.com/k3a/html2text
package main
import (
"fmt"
"github.com/k3a/html2text"
)
func main() {
html := `<html><head><title>Good</title></head><body><strong>clean</strong> text</body>`
plain := html2text.HTML2Text(html)
fmt.Println(plain)
}
/* Outputs:
clean text
*/
Note: The output is plain text, do not embed the result back into HTML without escaping.
To see all features in action, take a look at html2text_test.go.
MIT
185 followers · starred May 2023
88 followers · starred May 2024
98 followers · starred Oct 2020
6 followers · starred May 2026