Markdown users may be surprised to realize that whitespaces (including line breaks) are usually meaningless unless they are used in a verbatim environment (code blocks). Two or more spaces are the same as one space, and a line break is the same as a space. If you have used LaTeX or HTML before, you may not be surprised because the rule is the same in these languages.

In Markdown, we often use a blank line to separate elements such as paragraphs. To break a line without introducing a new paragraph, you have to use two trailing spaces. Sometimes you may want to break the lines many times, especially when you write or quote poems or lyrics. Adding two spaces after each line manually is a tedious task. The function blogdown:::quote_poem() can do this task automatically, e.g.,

  1. blogdown:::quote_poem(c("This line", "should be", "broken."))
  2. ## [1] "> This line \n> should be \n> broken."

If you use the RStudio IDE and have installed the package blogdown (Xie, Dervieux, and Presmanes Hill 2024), you can select the text in which you want to preserve the line breaks, and click the RStudio addin “Quote Poem” in the drop-down menu “Addins” on the toolbar. For example, the text below (in a fenced code block) does not contain trailing spaces:

  1. Like Barley Bending
  2. Like barley bending
  3.  In low fields by the sea,
  4. Singing in hard wind
  5.  Ceaselessly;
  6. Like barley bending
  7.  And rising again,
  8. So would I, unbroken,
  9.  Rise from pain;
  10. So would I softly,
  11.  Day long, night long,
  12. Change my sorrow
  13.  Into song.
  14. --- Sara Teasdale

After we select the above poem and click the RStudio addin “Quote Poem,” the output will be:

Like Barley Bending

Like barley bending
 In low fields by the sea,
Singing in hard wind
 Ceaselessly;

Like barley bending
 And rising again,
So would I, unbroken,
 Rise from pain;

So would I softly,
 Day long, night long,
Change my sorrow
 Into song.

— Sara Teasdale

Some users may ask, “Since the fenced code block preserves whitespaces, why not put poems in code blocks?” Code could be poetic, but poems are not code. Please do not be too addicted to coding…

References

Xie, Yihui, Christophe Dervieux, and Alison Presmanes Hill. 2024. Blogdown: Create Blogs and Websites with r Markdown. https://github.com/rstudio/blogdown.