You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

textversionjs

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

textversionjs

A tool for generating the text version of an html email.

1.1.3
latest
Source
npm
Version published
Weekly downloads
3.9K
-39.85%
Maintainers
2
Weekly downloads
 
Created
Source

textversionjs

Generate the text version of your HTML email in a second.

This tool is an open source project. Feel free to use it any time in your projects!

htmlToPlainText

The function that generates plain text from email htmls.

Params

ParamTypeRequiredDefault valueDescription
htmlTextstringYesThe html version of the email
styleConfigjsonNoOptions for converting

styleConfig

ParamTypeRequiredDefault valueDescription
linkProcessfunctionNoCallback function to customize links appearance
imgProcessfunctionNoCallback function to customize image appearance
headingStylestringNo"underline"Define heading appearance, options: "underline", "linebreak", "hashify"
listStylestringNo"indention"Define list appearance, options: "indention", "linebreak"
uIndentionCharstringNo"-"If listStyle is indention, uIndentionChar is the character that fills the indention for unordered lists
oIndentionCharstringNo"-"If listStyle is indention, oIndentionChar is the character that fills the indention for ordered lists after the heading number
listIndentionTabsintNo3If listStyle is indention, listIndentionTabs is the width of the indention
keepNbspsbooleanNofalseDefine the behaviour of the non-braking spaces. If set to true, nbsps are not collapsed to single space.

linkProcess

ParamTypeRequiredDefault valueDescription
hrefstringYesThe destination (href property) of the link
linkTextstringYesThe text of the link

imgProcess

ParamTypeRequiredDefault valueDescription
srcstringYesThe source (src property) of the image
altstringYesThe alternative text (alt property) of the image

Examples

Simple conversion with default style

var textVersion = require("textversionjs");
var htmlText = "<html>" +
					"<body>" +
						"Lorem ipsum <a href=\"http://foo.foo\">dolor</a> sic <strong>amet</strong><br />" +
						"Lorem ipsum <img src=\"http://foo.jpg\" alt=\"foo\" /> sic <pre>amet</pre>" +
						"<p>Lorem ipsum dolor <br /> sic amet</p>" +
						"<script>" +
							"alert(\"nothing\");" +
						"</script>" +
					"</body>" +
				"</html>";

var plainText = textVersion(htmlText);
// returns
// "Lorem ipsum [dolor] (http://foo.foo) sic amet
// Lorem ipsum ![foo] (http://foo.jpg) sic amet
// Lorem ipsum dolor
// sic amet"

var textVersion = require("textversionjs");
var htmlText = "<p>Lorem <a href=\"http://foo.foo\">ipsum</a> dolor sic amet</p>";

var styleConfig: {
	linkStyle: function(href, linkText){
		return linkText + " " + "(" + href + ")";
	}
};

var plainText = textVersion(htmlText, styleConfig);
// returns "Lorem ipsum (http://foo.foo) dolor sic amet"

Customize headings

var textVersion = require("textversionjs");

var htmlText = "<h1>Lorem ipsum</h1>" +
				"<p>Lorem ipsum dolor sic amet</p>";

var styleConfig: {
	headingStyle: "hashify"
};

var plainText = textVersion(htmlText, styleConfig);
// returns
// "# Lorem ipsum
//
// Lorem ipsum dolor sic amet"

Customize lists

var textVersion = require("textversionjs");
var htmlText = "<ul>" +
					"<li>Lorem</li>" +
					"<li>ipsum</li>" +
				"</ul>" +
				"<ol>" +
					"<li start=\"3\">Lorem</li>" +
					"<li>ipsum</li>" +
				"</ol>";

var styleConfig: {
	headingStyle: "indention",
	uIndentionChar: ".";
	listIndentionTabs: 2;
};

var plainText = textVersion(htmlText, styleConfig);
// returns "
// ..Lorem
// ..ipsum
// 3.Lorem
// 4.ipsum"

Try it online in our Demo page!

Don't forget to check out our other open source projects at EDMdesigner.

Follow us on github and twitter!

Keywords

email

FAQs

Package last updated on 20 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts