rte remove tag p | Community
Skip to main content
Level 4
March 23, 2016
Solved

rte remove tag p

  • March 23, 2016
  • 4 replies
  • 13760 views

Hi,

I need to remove all the tags that are automatically inserted inside a richtext.
The default use case converts a string X to <p>X</p> and sometimes to <p>X</p><p></p>
First of all anyone can explain me in which case the X is converted to <p>X</p><p></p> ? I have only one row, not two rows...

removeSingleParagraphContainer
True if the paragraph element of texts that consist only of a single paragraph should be removed on getValue/syncValue (defaults to false). For example, if a text is <p>Single paragraph text</p>, the surrounding "p" tag would get removed if this option was set to true. This option is mainly for backward compatibility with CQ 5.1, where container tags had not yet been available. Hence texts that were created by a CQ 5.1 instance will be surrounded by a single "p" element before they are edited in a CQ 5.2 instance. By setting this option to true, this automatically added "p" tag will get removed before the text is saved, at least if no other paragraphs or containers were added.
 
With this variable set to true the result becomes X<br> and if i write 2 rows (enter command) the result becomes <p>firstrow</p><p>secondrow</p>
 
singleParagraphContainerReplacement
Specifies the name of the tag that has to be used if a paragraph container cannot be simply removed because it carries additional info (for example, alignment and/or CSS classes; defaults to "div"). Note that this setting only takes effect if removeSingleParagraphContainer is set to true.
 
This parameter is completely useless...
 
I'm not able to find anything else to remove the unwanted tags, the only way is to delete the occurrencies when the variable is read.
The problem of this approach is how to differentiate the default tags to the tags inserted by the user. 
 
How this issue is managed inside the other projects?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by edubey

Hi Samuel,

That is the default behavior of AEM RTE. Two things I could here to solve:

1. Overide OOTB rte and customize it ( might be time consuming )

2. While taking RTE content from dialog, put that content in 'div' tag with and 'id' attribute and then modify the CSS to remove the effect of p tag in 'id'

Example:

<div id = "rtecontent">

Your RTE content goes here...

</div>

 

CSS

#rtecontent p {

Your css to remove the effect which is causing UI issue goes here....

}

4 replies

kautuk_sahni
Community Manager
Community Manager
March 23, 2016

Not sure if this helps, but please have a look at these community articles:

Link:- http://stackoverflow.com/questions/17965276/disable-auto-adding-of-p-tagLink:- http://blogs.adobe.com/contentmanagement/tag/richtext/

Link:-https://mkbansal.wordpress.com/2016/01/02/aem-rte-remove-p-tag/

Link:- blogs.adobe.com/contentmanagement/tag/richtext/

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
Level 4
March 23, 2016

Thanks.

If i create the component and insert only the letter X inside the rte, the assigned variable stores <p>X</p><p></p>

Why?

edubey
edubeyAccepted solution
Level 10
March 23, 2016

Hi Samuel,

That is the default behavior of AEM RTE. Two things I could here to solve:

1. Overide OOTB rte and customize it ( might be time consuming )

2. While taking RTE content from dialog, put that content in 'div' tag with and 'id' attribute and then modify the CSS to remove the effect of p tag in 'id'

Example:

<div id = "rtecontent">

Your RTE content goes here...

</div>

 

CSS

#rtecontent p {

Your css to remove the effect which is causing UI issue goes here....

}

Level 3
April 30, 2018

Hi,

We have tried the above thing in one of the RTE component  but it's breaking the Spellcheck Plugin .If we remove this html rules working fine.Is there any fix for this? This is happening for OOTB component?

We are using AEM 6.3 and service pack cp2

Thanks,

Vasu

Level 2
January 5, 2022

same is happening in AEM 6.5 sp 6.5.10
When add removeSingleParagraphContainer property to richtext spellcheck plugin is not working

Any solution?

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
January 10, 2022

Utilising the miscTools feature that the RTE provides, and along with the AEM Sling Model backend, removing the P tags can be done without a problem, 

 

Refer to this blog article for a full tutorial.

https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-removesingleparagraphcontainer-for-touch-ui