3.7 Markdown document

In some cases, you might want to produce plain Markdown output from R Markdown (e.g., to create a document for a system that accepts Markdown input like Stack Overflow).

To create a Markdown document from R Markdown, you specify the md_document output format in the front-matter of your document:

---
title: "Habits"
author: John Doe
date: March 22, 2005
output: md_document
---

3.7.1 Markdown variants

By default, the md_document format produces “strict” Markdown (i.e., conforming to the original Markdown specification with no extensions). You can generate a different flavor of Markdown using the variant option. For example:

---
output:
  md_document:
    variant: markdown_github
---

Valid values are:

  • markdown (Full Pandoc Markdown)
  • markdown_strict (Original Markdown specification; the default)
  • markdown_github (GitHub Flavored Markdown)
  • markdown_mmd (MultiMarkdown)
  • markdown_phpextra (PHP Markdown extra)

You can also compose custom Markdown variants. For example:

---
output:
  md_document:
    variant: markdown_strict+backtick_code_blocks+autolink_bare_uris
---

See Pandoc’s Manual for all of the Markdown extensions and their names to be used in composing custom variants.

3.7.1.1 Publishing formats

Many popular publishing systems now accept Markdown as input. Table 3.5 shows the correct Markdown variants to use for some popular systems.

TABLE 3.5: Markdown variants for some popular publishing systems.
System Markdown Variant
GitHub Wikis markdown_github
Drupal markdown_phpextra
WordPress.com markdown_phpextra+backtick_code_blocks
StackOverflow markdown_strict+autolink_bare_uris

In many cases, you can simply copy and paste the Markdown generated by rmarkdown::render() into the editing interface of the system you are targeting. Note, however, that if you have embedded plots or other images, you will need to upload them separately and fix up their URLs to point to the uploaded location. If you intend to build websites based on R Markdown, we recommend that you use the more straightforward solutions such as blogdown (Xie, Hill, and Thomas 2017; Xie 2020a) as introduced in Section 10 instead of manually copying the Markdown content.

3.7.2 Other features

Refer to Section 3.1 for the documentation of other features of Markdown documents, including table of contents (Section 3.1.1), figure options (Section 3.1.5), header and before/after body inclusions (Section 3.1.10.2), Pandoc arguments (Section 3.1.10.5), and shared options (Section 3.1.11).

References

Xie, Yihui. 2020a. Blogdown: Create Blogs and Websites with R Markdown. https://github.com/rstudio/blogdown.

Xie, Yihui, Alison Presmanes Hill, and Amber Thomas. 2017. Blogdown: Creating Websites with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/blogdown.