Tree @HEAD (Download .tar.gz)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | # 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 main import ( "fmt" "jaytaylor.com/html2text" ) func main() { inputHTML := ` <html> <head> <title>My Mega Service</title> <link rel=\"stylesheet\" href=\"main.css\"> <style type=\"text/css\">body { color: #fff; }</style> </head> <body> <div class="logo"> <a href="http://jaytaylor.com/"><img src="/logo-image.jpg" alt="Mega Service"/></a> </div> <h1>Welcome to your new account on my service!</h1> <p> Here is some more information: <ul> <li>Link 1: <a href="https://example.com">Example.com</a></li> <li>Link 2: <a href="https://example2.com">Example2.com</a></li> <li>Something else</li> </ul> </p> <table> <thead> <tr><th>Header 1</th><th>Header 2</th></tr> </thead> <tfoot> <tr><td>Footer 1</td><td>Footer 2</td></tr> </tfoot> <tbody> <tr><td>Row 1 Col 1</td><td>Row 1 Col 2</td></tr> <tr><td>Row 2 Col 1</td><td>Row 2 Col 2</td></tr> </tbody> </table> </body> </html>` 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 '<div>hi</div>' | html2text ``` ## 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 |
Commit History @HEAD
0
»»
- Release 0.0~git20200412.3577fbd-2 Aloïs Micard 3 years ago
- Remove executable bit from test files Aloïs Micard 3 years ago
- s/UNRELEASED/unstable/ Alexandre Viau 3 years ago
- New upstream version Aloïs Micard 3 years ago
- Update upstream source from tag 'upstream/0.0_git20200412.3577fbd' Aloïs Micard 3 years ago
- New upstream version 0.0~git20200412.3577fbd Aloïs Micard 3 years ago
- Fix packaging Aloïs Micard 3 years ago
- Fix Debian QA group name. Jelmer Vernooij 5 years ago
- update debian/gitlab-ci.yml (using salsa.debian.org/go-team/ci/cmd/ci) Michael Stapelberg 6 years ago
- point Vcs-* urls to salsa.debian.org aviau 6 years ago
- Update changelog for 0.0~git20170918.0.0ee88d3-4 release Michael Stapelberg 6 years ago
- Drop incorrect 0001-update-test-fixture-paths.patch Michael Stapelberg 6 years ago
- Remove Michael Lustfield from Uploaders list. Michael Lustfield 6 years ago
- Finalizing d/changelog for release. Michael Lustfield 6 years ago
- Orphaning dependency of gitea; no longer maintaining gitea. Michael Lustfield 6 years ago
- Finalize d/changelog for upload. Michael Lustfield 6 years ago
- New upstream build. Michael Lustfield 6 years ago
- Updated version 0.0~git20170918.0.0ee88d3 from 'upstream/0.0_git20170918.0.0ee88d3' Michael Lustfield 6 years ago
- New upstream version 0.0~git20170918.0.0ee88d3 Michael Lustfield 6 years ago
- Packaging clean-up and maintenance. Michael Lustfield 6 years ago
- Finalizing d/changelog for upload. Michael Lustfield 6 years ago
- Added patch to support test data. Michael Lustfield 6 years ago
- Added new build dependencies. Michael Lustfield 6 years ago
- New upstream build Michael Lustfield 6 years ago
- New upstream version 0.0~git20170530.0.7c7a33a Michael Lustfield 6 years ago
- Merge tag 'upstream/0.0_git20170530.0.7c7a33a' Michael Lustfield 6 years ago
- Finalize d/changelog for release Michael Lustfield 7 years ago
- Initial packaging Michael Lustfield 7 years ago
- New upstream version 0.0~git20170217.0.24f9b0f Michael Lustfield 7 years ago
- Ignore quilt dir .pc via .gitignore Michael Lustfield 7 years ago
0
»»