4.12 Preserve a large number of line breaks
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.,
:::quote_poem(c("This line", "should be", "broken."))
blogdown## [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:
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
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…