Handling Empty Paragraphs from R Markdown

From time to time I find empty paragraph tags (<p></p>) inserted into my HTML when knitting an R Markdown document.

Beyond being an affront to my OCD, these empty tags are mostly just an irritation. But if I’m trying to produce a very specific layout, then the extra space allocated to them can become a real annoyance.

These tags seem to occur when I have a particular configuration of native HTML tags in the .Rmd file. I did try to understand precisely what was causing them, but lost patience. It turns out that it’s easier to simply accept them, rendering them invisible with the following neat CSS rule.

p:empty
{
  display: none;
}

That will identify all empty paragraph tags using the :empty pseudo-class, then hide them by setting display to none.