0
<p style="text-align: right;">
   <p style="text-align: center;">
      <p style="text-align: left;">
         <p style="text-align:center;">
            leave this content
         </p>
      </p>
   </p>
</p>
<br>

save the content and the last paragraph with the style that has been applied, which is

<p style="text-align: right;">

mpalencia
  • 5,481
  • 4
  • 45
  • 59
topC
  • 7
  • 2

3 Answers3

0

For the concrete case that you provided try this simple code:

var elementToKeep = $('selectorToParagraph');

elementToKeep.html(elementToKeep.text());

For more universal cases you'll have to use an HTML parser.

micnic
  • 10,915
  • 5
  • 44
  • 55
  • ok, and how should I keep that content wrapped with last paragraph – topC Nov 13 '14 at 09:52
  • the problem is that rich editor reads wrong the styles of nested paragraph. Especially if it is wrapped with other html tags – topC Nov 13 '14 at 09:53
0

Regex is

<p style="(.*?)">(.*?)<\/p>

then try this

content = content.replace("<p style="(.*?)">(.*?)<\/p>","<p style="$1">$2</p>");
Rolwin Crasta
  • 4,219
  • 3
  • 35
  • 45
0

I try this

<p(?: [^>]+)?>((?:(?!<\/?p[ >]).)*)<\/p>

change the style as right for para. This only possible in regex.

SEE DEMO: http://regex101.com/r/dJ5nB1/1

depsai
  • 405
  • 2
  • 14