Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaytaylor/html2text
Golang HTML to plaintext conversion library
https://github.com/jaytaylor/html2text
go golang html-emails html2text plaintext
Last synced: 30 days ago
JSON representation
Golang HTML to plaintext conversion library
- Host: GitHub
- URL: https://github.com/jaytaylor/html2text
- Owner: jaytaylor
- License: mit
- Created: 2015-04-06T23:46:15.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-02T07:14:15.000Z (about 1 year ago)
- Last Synced: 2024-02-21T15:37:20.798Z (10 months ago)
- Topics: go, golang, html-emails, html2text, plaintext
- Language: Go
- Homepage: https://jaytaylor.com/html2text
- Size: 56.6 KB
- Stars: 506
- Watchers: 13
- Forks: 177
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - html2text - HTML to text (Open source library / Word Processing)
README
# html2text
[![Documentation](https://godoc.org/github.com/jaytaylor/html2text?status.svg)](https://godoc.org/github.com/jaytaylor/html2text)
[![Build Status](https://travis-ci.org/jaytaylor/html2text.svg?branch=master)](https://travis-ci.org/jaytaylor/html2text)
[![Report Card](https://goreportcard.com/badge/github.com/jaytaylor/html2text)](https://goreportcard.com/report/github.com/jaytaylor/html2text)### Converts HTML into text of the markdown-flavored variety
## Introduction
Ensure your emails are readable by all!
Turns HTML into raw text, useful for sending fancy HTML emails with an equivalently nicely formatted TXT document as a fallback (e.g. for people who don't allow HTML emails or have other display issues).
html2text is a simple golang package for rendering HTML into plaintext.
There are still lots of improvements to be had, but FWIW this has worked fine for my [basic] HTML-2-text needs.
It requires go 1.x or newer ;)
## Download the package
```bash
go get jaytaylor.com/html2text
```## Example usage
### Library
```go
package mainimport (
"fmt""jaytaylor.com/html2text"
)func main() {
inputHTML := `
My Mega Service
body { color: #fff; }
Welcome to your new account on my service!
Here is some more information:
- Link 1: Example.com
- Link 2: Example2.com
- Something else
Header 1Header 2
Footer 1Footer 2
Row 1 Col 1Row 1 Col 2
Row 2 Col 1Row 2 Col 2
`
text, err := html2text.FromString(inputHTML, html2text.Options{PrettyTables: true})
if err != nil {
panic(err)
}
fmt.Println(text)
}
```
Output:
```
Mega Service ( http://jaytaylor.com/ )
******************************************
Welcome to your new account on my service!
******************************************
Here is some more information:
* Link 1: Example.com ( https://example.com )
* Link 2: Example2.com ( https://example2.com )
* Something else
+-------------+-------------+
| HEADER 1 | HEADER 2 |
+-------------+-------------+
| Row 1 Col 1 | Row 1 Col 2 |
| Row 2 Col 1 | Row 2 Col 2 |
+-------------+-------------+
| FOOTER 1 | FOOTER 2 |
+-------------+-------------+
```
### Command line
```
echo '
```
## Unit-tests
Running the unit-tests is straightforward and standard:
```bash
go test
```
# License
Permissive MIT license.
## Contact
You are more than welcome to open issues and send pull requests if you find a bug or want a new feature.
If you appreciate this library please feel free to drop me a line and tell me! It's always nice to hear from people who have benefitted from my work.
Email: jay at (my github username).com
Twitter: [@jtaylor](https://twitter.com/jtaylor)
# Alternatives
https://github.com/k3a/html2text - Lightweight