'headings in HTML render incorrectly from R script using `rmarkdown::render`

When I render an HTML directly from an R script using rmarkdown::renderfunction, the headings do not render as headings, if some text (but not code) is present in between two headings.

Specifically, using file test.R, containing the following code:

#' ---
#' title: "Test"
#' author: "Tester"
#' date: "`r Sys.time()`"
#' output: 
#' html_document
#' ---

#+ r setup, include=FALSE 
knitr::opts_chunk$set(message = FALSE, warning = FALSE, cache = FALSE)

#'***  

#' # Heading TEST 1
#' Just some text.

#'***

#' # Heading TEST 2  
#' Just some text.    

#' # Heading TEST 3
#' ````
#' Just some code   
#' ```` 

#'***

#' # Heading TEST 4  

#' # Heading TEST 5
#'***

and running

require(rmarkdown)
rmarkdown::render('test.R)

gives:

Rendered HTML output

Any ideas how to fix this?



Solution 1:[1]

Adding an empty line below the text part using '# fixes the issue.

#' # Heading TEST 1
#' Just some text.
#' 

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Bulla