diff --git a/js/mzta-utils.js b/js/mzta-utils.js index 15993985..ddfc2fbf 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -199,6 +199,19 @@ export function stripHtmlKeepLines(htmlString) { .trim(); // removes leading/trailing whitespace } +export function htmlBodyToPlainText(html) { + return html + .replace(/
/gi, '') // remove and its content + .replace(//gi, '') // remove
tag
+ .replace(/<[^>]*>/g, ' ') // remove any other HTML tags
+ .replace(/[ \t]+\n/g, '\n') // remove spaces before newline
+ .replace(/\n{2,}/g, '\n') // compress multiple newlines into one
+ .replace(/\s+/g, ' ') // normalize spaces inside lines
+ .trim(); // trim spaces at start and end
+}
+
export function convertNewlinesToBr(text) {
return text.replace(/\n/g, '
');
}