Expand my Community achievements bar.

SOLVED

rte remove tag p

Avatar

Level 4

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?
1 Accepted Solution

Avatar

Correct answer by
Level 10

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....

}

View solution in original post

9 Replies

Avatar

Administrator

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

Avatar

Level 4

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?

Avatar

Correct answer by
Level 10

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....

}

Avatar

Level 3

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

Avatar

Level 2

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

Any solution?

Avatar

Community Advisor

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-...

 

Avatar

Level 2

Hi Brian Thanks for your response

I am able to remove <p> tags by adding removeSingleParagraphContainer property to rte field. Here my problem is when I add removeSingleParagraphContainer property then spell check plugin is not working

 

Thanks in advance

Avatar

Community Advisor

removeSingleParagraphContainer will not work for touchUI rte, as this was a flagged used in the classicUI world.