Skip to content

Instantly share code, notes, and snippets.

@zackslash
Last active December 12, 2019 11:29
Show Gist options
  • Save zackslash/1998e5e6027280b1b09271fe8562a0eb to your computer and use it in GitHub Desktop.
Save zackslash/1998e5e6027280b1b09271fe8562a0eb to your computer and use it in GitHub Desktop.
HTML-To-Text in browser
/*
* Description: Small wapper to expose HTML-To-Text (https://www.npmjs.com/package/html-to-text) functionality to browser
*
* package.json == {"dependencies": {"html-to-text": "*"}}
*
* $ browserify --standalone convertHTMLToString wrap.js -o clientHtmlToText.js
*
* convertHTMLToString('<h1>test</h1>',{wordwrap: 130});
*
* Note: Resulting file needs to be placed before 'requirejs' dependency if present.
*/
function convertHTMLToString(input, options) {
var htmlToText = require('html-to-text');
var text = htmlToText.fromString(input,options);
return text;
}
module.exports = convertHTMLToString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment