Categorygithub.com/mailproto/textplain
modulepackage
0.2.9
Repository: https://github.com/mailproto/textplain.git
Documentation: pkg.go.dev

# README

Textplain

This project began as a port of the html_to_plaintext logic from github.com/premailer/premailer and applies the same basic set of rules for generating a text/plain copy of an email, given the text/html version

Usage

myHTML := `<html><body>Hello World</body></html>`
myPlaintext := textplain.Convert(myHTML, textplain.DefaultLineLength)

By default it applies a word wrapping algorithm that is also supplied standalone.

wrapped := textplain.WordWrap("hello world, here is some text", 15)

Options

Two plaintexters are supplied:

converter := textplain.NewTreeConverter()

Uses the x/net/html package to parse the supplied html into a tree, and performs a single-pass conversion to plaintext. This is the best performing option, and recommended for general usage.

The library still includes the older converter option

converter := textplain.NewRegexpConverter()

is the most "true to premailer" implementation, and uses regular expressions, which is largely problematic as it needs to both compile those regexps and regular expressions in the Go world use mutexes which limit concurrency

# Functions

Convert is a convenience method so the library can be used without initializing a converter because this library relies heavily on regexp objects, it may act as a bottlneck to concurrency due to thread-safety mutexes in *regexp.Regexp internals.
No description provided by the author
New textplain converter object.
No description provided by the author
WordWrap searches for logical breakpoints in each line (whitespace) and tries to trim each line to the specified length Note: this diverges from the regex approach in premailer, which I found to be significantly slower in cases with long unbroken lines https://github.com/premailer/premailer/blob/7c94e7a/lib/premailer/html_to_plain_text.rb#L116.

# Constants

# Variables

Well-defined errors.

# Structs

No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author