All Projects → jaytaylor → Html2text

jaytaylor / Html2text

Licence: mit
Golang HTML to plaintext conversion library

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Html2text

Orger
Tool to convert data into searchable and interactive org-mode views
Stars: ✭ 192 (-43.36%)
Mutual labels:  plaintext
jot
Command-line note-taking for minimalists
Stars: ✭ 24 (-92.92%)
Mutual labels:  plaintext
Mak
A universal notepad. (WIP)
Stars: ✭ 270 (-20.35%)
Mutual labels:  plaintext
telegram-backup-to-txt
Tool to dump telegram into text files for quick search (e.g. with grep)
Stars: ✭ 22 (-93.51%)
Mutual labels:  plaintext
hyperdraft
Turn your notes into a website.
Stars: ✭ 59 (-82.6%)
Mutual labels:  plaintext
plaintext-everything
📝 A list of tools and articles helpful for keeping everything under plaintext.
Stars: ✭ 100 (-70.5%)
Mutual labels:  plaintext
Plainbudget
Minimalist Plain Text Budgeting
Stars: ✭ 167 (-50.74%)
Mutual labels:  plaintext
Hashes
Magic hashes – PHP hash "collisions"
Stars: ✭ 278 (-17.99%)
Mutual labels:  plaintext
rss-to-email
Generate HTML emails from your RSS feeds.
Stars: ✭ 92 (-72.86%)
Mutual labels:  html-emails
striprtf
Stripping rtf to plain old text
Stars: ✭ 56 (-83.48%)
Mutual labels:  plaintext
plain
network .md into .html with plaintext files
Stars: ✭ 70 (-79.35%)
Mutual labels:  plaintext
responsive-html-email-templates
Collection of Free responsive HTML templates for Startups
Stars: ✭ 187 (-44.84%)
Mutual labels:  html-emails
shadowsocks-libev-nocrypto
libev port of shadowsocks. In this fork, encryption is optional!
Stars: ✭ 24 (-92.92%)
Mutual labels:  plaintext
Klog
A plain-text file format and command line tool for time tracking
Stars: ✭ 222 (-34.51%)
Mutual labels:  plaintext
Ledger
Command line double-entry accounting program
Stars: ✭ 272 (-19.76%)
Mutual labels:  plaintext
Slideshow
slideshow gems - write your slides / talks / presentations in plain text with markdown formatting conventions
Stars: ✭ 173 (-48.97%)
Mutual labels:  plaintext
leaf
Lightweight, self-hosted task tracking
Stars: ✭ 42 (-87.61%)
Mutual labels:  plaintext
Email Bugs
Email quirks and bugs
Stars: ✭ 306 (-9.73%)
Mutual labels:  html-emails
Textbeat
🎹 plaintext music sequencer and midi shell, with vim playback 🥁
Stars: ✭ 274 (-19.17%)
Mutual labels:  plaintext
doi2bib
📝 Easily convert Digital Object Identifier (DOI) and Uniform Resource Locator (URL) to BibTeX and DOI to plain text.
Stars: ✭ 28 (-91.74%)
Mutual labels:  plaintext

html2text

Documentation Build Status Report Card

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

go get jaytaylor.com/html2text

Example usage

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   |
+-------------+-------------+

Unit-tests

Running the unit-tests is straightforward and standard:

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

Alternatives

https://github.com/k3a/html2text - Lightweight

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].