Handling Empty Paragraphs from R Markdown

[This article was first published on R - datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

To leave a comment for the author, please follow the link and comment on their blog: R - datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)