Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove blank paragraph tags - TinyMCE

I am trying to remove blank paragraphs generated by TinyMCE. I want to use a RegEx because the set of HTML tags is finite in my universe but I am not sure how to go about it.

For this purpose my definition of blank is anything that does not have text. Here are some blank tag paragraphs I am getting from TinyMCE:

<p><strong><br></strong></p>
<p><br></p>
<p>&nbsp;</p>
<p></p>

Basically if no text is going to show up inside the paragraph tags, I want to remove it.. any ideas?

like image 857
zgirod Avatar asked Feb 20 '26 13:02

zgirod


1 Answers

Give the Html Agility Pack a try, it'll parse your HTML fragment into a DOM which can be traversed to strip any <p> tags that meet your criteria. This'll be much easier and more robust that using a regex.

like image 156
Chris Fulstow Avatar answered Feb 23 '26 02:02

Chris Fulstow