Rich Text Editor created extra unwanted HTML tags
- March 12, 2025
- 1 reply
- 733 views
Hello,
I, ve been dealing with this issue and i can't seem to solve it on my own. In our email template we have a module where the user can write long text and for that i ve created a rich text editor in the form. The problem is that if the user writes text without first opening "source code" mode, the text gets wrapped with following tags: <!DOCTYPE html> <html> <head> </head> <body> <p>test</p> </body> </html> (see picture attached). How can i prevent the rich text editor from doing it?
I have also tried to prevent this by using a function written a in a library which is referenced to at the beginning of the javascript template file
<%
loadLibrary("lf:queryJS");
eval(xtk.javascript.get("lf:newsletter_libclaudiotest").data);
%>
and then used the function where the text editor is used <p><%= formatRichTextFields(block.@main) %></p>
here is the function itself:
function formatRichTextFields(sContentArg) {
var sContent = "" + sContentArg;
// Remove <html>, <head>, and <body> tags
sContent = sContent.replace(/<!DOCTYPE html>/ig, '');
sContent = sContent.replace(/<html[^>]*>/ig, '').replace(/<\/html>/ig, '');
sContent = sContent.replace(/<head[^>]*>/ig, '').replace(/<\/head>/ig, '');
sContent = sContent.replace(/<body[^>]*>/ig, '').replace(/<\/body>/ig, '');
return sContent;
}
My questions are:
1) is there a way to prevent rich text editor from creating these HTML tags?
2) if not, why isn't my function doing its job?
Cheers