Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards
SOLVED

Rich Text Editor created extra unwanted HTML tags

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi @Cl4ud,

Unfortunately, there isn’t a direct configuration in Adobe Campaign Classic v7 (or v8) to prevent the DCE from adding these tags when text is entered in the visual mode. This behavior is baked into how the editor processes content—it assumes you’re creating a complete HTML document. However, here are some potential workarounds to minimize or avoid this:

  • Encourage Source Code Usage: Train users to always use the "source code" mode when entering text. In this mode, the editor respects the raw input and doesn’t add extra tags unless explicitly included by the user. While this isn’t a technical fix, it’s a practical solution if user behavior can be controlled.
  • Use a Plain Text Field Instead: If the content doesn’t require rich formatting (e.g., bold, italics, links), consider replacing the RTE with a plain text input field in the form. You can then wrap it in <p> tags manually in the template if needed. This avoids the DCE entirely.
  • Post-Process the Output: Since preventing the tags at the source isn’t natively supported, you’re already on the right track by trying to strip them out after the fact (as you’ve done with your function). This is the most common approach when the full HTML structure isn’t desired.


Your formatRichTextFields function looks conceptually sound—it uses regular expressions to strip out unwanted tags—but there could be several reasons it’s not working as expected.

Ensure the function is being called correctly. Your template snippet <p><%= formatRichTextFields(block.@main) %></p> assumes block.@main contains the RTE content. Verify that block.@main indeed holds the full HTML string (e.g., <!DOCTYPE html><html>…).

Here’s an improved version of your function with debugging and broader matching:

 

function formatRichTextFields(sContentArg) {
  var sContent = String(sContentArg || ""); // Handle null/undefined
  logInfo("Before: " + sContent); // Debug raw input
  sContent = sContent.replace(/<!DOCTYPE[^>]*>/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, '');
  logInfo("After: " + sContent); // Debug cleaned output
  return sContent.trim(); // Remove extra whitespace
}​

Use it in your template:

<p><%= formatRichTextFields(block.@main) %></p>

 


Then:

  1. Check the Campaign logs (web.log or workflow logs) for the logInfo output to confirm what’s being processed.
  2. Verify the library loads correctly and the function is available.
If you’re still stuck, let me know what the logs show or share more details about block.@main and your library setup! I’d be happy to dig deeper.

Thanks



View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

Hi @Cl4ud,

Unfortunately, there isn’t a direct configuration in Adobe Campaign Classic v7 (or v8) to prevent the DCE from adding these tags when text is entered in the visual mode. This behavior is baked into how the editor processes content—it assumes you’re creating a complete HTML document. However, here are some potential workarounds to minimize or avoid this:

  • Encourage Source Code Usage: Train users to always use the "source code" mode when entering text. In this mode, the editor respects the raw input and doesn’t add extra tags unless explicitly included by the user. While this isn’t a technical fix, it’s a practical solution if user behavior can be controlled.
  • Use a Plain Text Field Instead: If the content doesn’t require rich formatting (e.g., bold, italics, links), consider replacing the RTE with a plain text input field in the form. You can then wrap it in <p> tags manually in the template if needed. This avoids the DCE entirely.
  • Post-Process the Output: Since preventing the tags at the source isn’t natively supported, you’re already on the right track by trying to strip them out after the fact (as you’ve done with your function). This is the most common approach when the full HTML structure isn’t desired.


Your formatRichTextFields function looks conceptually sound—it uses regular expressions to strip out unwanted tags—but there could be several reasons it’s not working as expected.

Ensure the function is being called correctly. Your template snippet <p><%= formatRichTextFields(block.@main) %></p> assumes block.@main contains the RTE content. Verify that block.@main indeed holds the full HTML string (e.g., <!DOCTYPE html><html>…).

Here’s an improved version of your function with debugging and broader matching:

 

function formatRichTextFields(sContentArg) {
  var sContent = String(sContentArg || ""); // Handle null/undefined
  logInfo("Before: " + sContent); // Debug raw input
  sContent = sContent.replace(/<!DOCTYPE[^>]*>/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, '');
  logInfo("After: " + sContent); // Debug cleaned output
  return sContent.trim(); // Remove extra whitespace
}​

Use it in your template:

<p><%= formatRichTextFields(block.@main) %></p>

 


Then:

  1. Check the Campaign logs (web.log or workflow logs) for the logInfo output to confirm what’s being processed.
  2. Verify the library loads correctly and the function is available.
If you’re still stuck, let me know what the logs show or share more details about block.@main and your library setup! I’d be happy to dig deeper.

Thanks



Avatar

Level 2

Thank you very much for ur contribution Sushant

 

I have decided to make it easy for me and convince the marketers populating the deliveries with content to only use source code mode when adding text. i will remind them several time during the next month or so until this becomes a routine for them.

 

Thank you again and we can close this