highlightjs_assets <- function(theme = "default") {
tagList(
htmlDependency(
name = "highlight.js",
version = "11.2.0",
src = c(
href = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/"
),
script = "highlight.min.js",
stylesheet = glue("styles/{theme}.min.css"),
head = c("<script>hljs.highlightAll();</script>")
)
)
}
highlight_code_block <- function(..., language = "r") {
tags$pre(
style = css(display = "grid"),
class = "px-0 py-0",
tags$code(class = glue("language-{language}"), ...)
) %>%
add_class("highlight_code_block")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.