As I’m moving this blog from wordpress to blogdown (also see the book about blogdown) I was wonderung how I can get some nice syntax highlighting of the embedded R-code.

The first impression was quite sobering. I used the default .Rmd page type and I got not much highlighting. It was better than that I got at Medium with base functionality. But it’s not quite what I wanted.

But there are two other file types in blogdown.

Blogdown file types

.md is for simple markdown-pages without any R-code. But the other one .Rmarkdown seems to be more promising.

.Rmarkdown pages are compiled by Hugo instead of pandoc (see https://bookdown.org/yihui/blogdown/output-format.html for details.)

So the result is quite pretty.

1
2
3
4
5
6
7
suppressMessages(library(tidyverse)); 
options(dplyr.summarise.inform = FALSE)

ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Species)) +
  geom_point() +
  labs(title = "Simple Plot") +
  NULL

But there was one thing I had to enable in the Hugo-theme I’m using:

I had to enable a functionality in the file config.toml:

1
2
[markup.goldmark.renderer]
  unsafe= true