Highlight lines within code chunks


I would like to highligh certain lines of code chunk of a Rmarkdown document. I have discovered the "xaringa" which uses a particular template (different from Rmarkdown) to generate HTML only slides. Following, there is a minimal example:


title: "Presentation Ninja"
      highlightLines: true

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

# Some Tips

An example of using the trailing comment `#<<` to highlight lines:

```{r tidy=FALSE, eval=FALSE}
ggplot(mtcars) + 
  aes(mpg, disp) + 
  geom_point() +   #<<
  geom_smooth()    #<<

end example

The problem is that I would like to compile it both as PDF slides and HTML slides, preferible with standard Rmarkdown templates.



I'm not sure it is a supported workflow since xaringa is based on JavaScript, so all of the highlighting is done there. Not sure, if it is transferable to PDF.


The xaringan wiki has a page on exporting to PDF (using the webshot package):