vec_fmt_markdown: Format a vector containing Markdown text

View source: R/format_vec.R

vec_fmt_markdownR Documentation

Format a vector containing Markdown text


Any Markdown-formatted text in the input vector will be transformed to the appropriate output type.


  md_engine = c("markdown", "commonmark"),
  output = c("auto", "plain", "html", "latex", "rtf", "word")



The input vector

vector(numeric|integer) // required

This is the input vector that will undergo transformation to a character vector of the same length. Values within the vector will be formatted.


Choice of Markdown engine

⁠singl-kw:[markdown|commonmark]⁠ // default: "markdown"

The engine preference for Markdown rendering. By default, this is set to "markdown" where gt will use the markdown package for Markdown conversion to HTML and LaTeX. The other option is "commonmark" and with that the commonmark package will be used.


Output format

⁠singl-kw:[auto|plain|html|latex|rtf|word]⁠ // default: "auto"

The output style of the resulting character vector. This can either be "auto" (the default), "plain", "html", "latex", "rtf", or "word". In knitr rendering (i.e., Quarto or R Markdown), the "auto" option will choose the correct output value


A character vector.


Create a vector of Markdown-based text snippets.

text_vec <-
    "This **is** *Markdown*.",
    "Info on Markdown syntax can be found
    "The **gt** package has these datasets:
- `countrypops`
- `sza`
- `gtcars`
- `sp500`
- `pizzaplace`
- `exibble`"

With vec_fmt_markdown() we can easily convert these to different output types, like HTML

vec_fmt_markdown(text_vec, output = "html")
#> [1] "<p>This <strong>is</strong> <em>Markdown</em>.</p>"                                                                                                                                                                                                               
#> [2] "<p>Info on Markdown syntax can be found\n<a href=\"\">here</a>.</p>"                                                                                                                                                 
#> [3] "<p>The <strong>gt</strong> package has these datasets:</p>\n<ul>\n<li><code>countrypops</code></li>\n<li><code>sza</code></li>\n<li><code>gtcars</code></li>\n<li><code>sp500</code></li>\n<li><code>pizzaplace</code></li>\n<li><code>exibble</code></li>\n</ul>"

or LaTeX

vec_fmt_markdown(text_vec, output = "latex")
#> [1] "This \\textbf{is} \\emph{Markdown}."                                                                                                                                                                                                                     
#> [2] "Info on Markdown syntax can be found\n\\href{}{here}."                                                                                                                                                      
#> [3] "The \\textbf{gt} package has these datasets:\n\n\\begin{itemize}\n\\item \\texttt{countrypops}\n\n\\item \\texttt{sza}\n\n\\item \\texttt{gtcars}\n\n\\item \\texttt{sp500}\n\n\\item \\texttt{pizzaplace}\n\n\\item \\texttt{exibble}\n\n\\end{itemize}"

Function ID


Function Introduced

v0.7.0 (Aug 25, 2022)

See Also

The variant function intended for formatting gt table data: fmt_markdown().

Other vector formatting functions: vec_fmt_bytes(), vec_fmt_currency(), vec_fmt_datetime(), vec_fmt_date(), vec_fmt_duration(), vec_fmt_engineering(), vec_fmt_fraction(), vec_fmt_index(), vec_fmt_integer(), vec_fmt_number(), vec_fmt_partsper(), vec_fmt_percent(), vec_fmt_roman(), vec_fmt_scientific(), vec_fmt_spelled_num(), vec_fmt_time()

gt documentation built on June 22, 2024, 11:11 a.m.