From d47159d47b6a5709a6ab0ba2af0186155847f799 Mon Sep 17 00:00:00 2001 From: Lawrence Elitzer <5624305+elitzer2@users.noreply.github.com> Date: Sun, 30 Aug 2020 23:43:59 -0500 Subject: [PATCH] Update API call to remove premailer --- server/routes/rest/editors.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/server/routes/rest/editors.js b/server/routes/rest/editors.js index 0fc5bdb3..fbdef77b 100644 --- a/server/routes/rest/editors.js +++ b/server/routes/rest/editors.js @@ -3,23 +3,14 @@ const passport = require('../../lib/passport'); const bluebird = require('bluebird'); -const premailerApi = require('premailer-api'); -const premailerPrepareAsync = bluebird.promisify(premailerApi.prepare.bind(premailerApi)); +const htmlToText = require('html-to-text'); const router = require('../../lib/router-async').create(); router.postAsync('/html-to-text', passport.loggedIn, passport.csrfProtection, async (req, res) => { - if (!req.body.html) { - return res.json({text: ''}); // Premailer crashes very hard when html is empty - } - - const email = await premailerPrepareAsync({ - html: req.body.html, - fetchHTML: false - }); - - res.json({text: email.text.replace(/%5B/g, '[').replace(/%5D/g, ']')}); + const email = htmlToText.fromString(req.body.html, {wordwrap: 130}); + res.json({text: email}); }); module.exports = router;