GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - k3a/html2text: Simple Go package to convert HTML to plain text

BranchesTags
Open more actions menu

Latest commit

 

History

75 Commits
75 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
entity.go
entity.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
html2text.go
html2text.go
 
 
html2text_test.go
html2text_test.go
 
 

Repository files navigation

Go Reference test coverage

html2text

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:

  • Strips out the section, along with <style> and <script> tags.
  • Converts HTML tags to plain text and parses HTML entities into the characters they represent.
  • Converts links into their href attribute, or to the 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.

Install

go get github.com/k3a/html2text

Usage

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.

Alternatives

  • https://github.com/jaytaylor/html2text (heavier, with more features, uses golang.org/x/net/html parser)

License

MIT

About

Simple Go package to convert HTML to plain text

Topics

gogolanghtmlpackageplaintext

Resources

Readme
MIT license
Activity

Stars

192 stars

Watchers

4 watching

Forks

26 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.