From 8223f4ef4f94f5b852db277593cd945ff153a4e8 Mon Sep 17 00:00:00 2001 From: mic Date: Tue, 19 Aug 2025 16:24:17 +0200 Subject: [PATCH] Add htmlBodyToPlainText function to sanitize HTML content. see #470 --- js/mzta-utils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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, '\n') // replace
with newline + .replace(/<\/p\s*>/gi, '\n') // replace

with newline + .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, '
'); }