$part =~ s/^\s+|\s+\z//g; # avoid spurious leading/trailing <p>
$part =~ s!(\n([ \r]*\n)*)!$1 eq "\n" ? "<br />\n" : "</p>\n<p>"!eg;
$part = "<p>$part</p>";
- 1 while $part =~ s/<p>(<div(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</div></p>!</p></div>!g;
- 1 while $part =~ s/<p>(<address(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</address></p>!</p></address>!g;
- 1 while $part =~ s/<p>(<blockquote(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</blockquote></p>!</p></blockquote>!g;
- 1 while $part =~ s/<p>(<article(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</article></p>!</p></article>!g;
- 1 while $part =~ s/<p>(<section(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</section></p>!</p></section>!g;
- 1 while $part =~ s/<p>(<header(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</header></p>!</p></header>!g;
- 1 while $part =~ s/<p>(<footer(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</footer></p>!</p></footer>!g;
- 1 while $part =~ s/<p>(<aside(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</aside></p>!</p></aside>!g;
- 1 while $part =~ s/<p>(<nav(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</nav></p>!</p></nav>!g;
- 1 while $part =~ s/<p>(<figure(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</figure></p>!</p></figure>!g;
- 1 while $part =~ s/<p>(<figcaption(?: [^>]*)?>)/$1<p>/g;
- 1 while $part =~ s!</figcaption></p>!</p></figcaption>!g;
+ 1 while $part =~ s/<p>(<div(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</div></p>!</p>\n</div>!g;
+ 1 while $part =~ s/<p>(<address(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</address></p>!</p>\n</address>!g;
+ 1 while $part =~ s/<p>(<blockquote(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</blockquote></p>!</p>\n</blockquote>!g;
+ 1 while $part =~ s/<p>(<article(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</article></p>!</p>\n</article>!g;
+ 1 while $part =~ s/<p>(<section(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</section></p>!</p>\n</section>!g;
+ 1 while $part =~ s/<p>(<header(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</header></p>!</p>\n</header>!g;
+ 1 while $part =~ s/<p>(<footer(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</footer></p>!</p>\n</footer>!g;
+ 1 while $part =~ s/<p>(<aside(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</aside></p>!</p>\n</aside>!g;
+ 1 while $part =~ s/<p>(<nav(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</nav></p>!</p>\n</nav>!g;
+ 1 while $part =~ s/<p>(<figure(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</figure></p>!</p>\n</figure>!g;
+ 1 while $part =~ s/<p>(<figcaption(?: [^>]*)?>)/$1\n<p>/g;
+ 1 while $part =~ s!</figcaption></p>!</p>\n</figcaption>!g;
1 while $part =~ s!<p>(<a\s[^>]+>)</p>!$1!g;
1 while $part =~ s!<p></a></p>!</a>!g;
1 while $part =~ s! ?(<a\s[^>]+>)</p>!</p>\n$1!g;