Learn R Programming

blogdown (version 0.0.68)

shortcode: Helper functions to write Hugo shortcodes using the R syntax

Description

These functions return Hugo shortcodes with the shortcode name and arguments you specify. The closing shortcode will be added only if the inner content is not empty. The function shortcode_html() is essentially shortcode(.type = 'html').

Usage

shortcode(.name, ..., .content = NULL, .type = "markdown")

shortcode_html(...)

Arguments

.name

The name of the shortcode.

...

All arguments of the shortcode (either all named, or all unnamed). The ... argument of shortcode_html() is passed to shortcode().

.content

The inner content for the shortcode.

.type

The type of the shortcode: markdown or html.

Value

A character string wrapped in htmltools::HTML(); shortcode() returns a string of the form {{% name args %}}, and shortcode_html() returns {{< name args >}}.

Details

These functions can be used in either knitr inline R expressions or code chunks. The returned character string is wrapped in htmltools::HTML(), so rmarkdown will protect it from the Pandoc conversion. You cannot simply write {{< shortcode >}} in R Markdown, because Pandoc is not aware of Hugo shortcodes, and may convert special characters so that Hugo can no longer recognize the shortcodes (e.g. < will be converted to &lt;).

If your document is pure Markdown, you can use the Hugo syntax to write shortcodes, and there is no need to call these R functions.

References

https://gohugo.io/extras/shortcodes/

Examples

Run this code
# NOT RUN {
library(blogdown)

shortcode("tweet", "1234567")
shortcode("figure", src = "/images/foo.png", alt = "A nice figure")
shortcode("highlight", "bash", .content = "echo hello world;")

shortcode_html("myshortcode", .content = "My <strong>shortcode</strong>.")
# }

Run the code above in your browser using DataLab