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 likeStack Overflow).

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

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

3.7.1 Markdown variants

By default, themd_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 thevariant 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. Table3.5 shows the correct Markdown variants to use for some popular systems.

TABLE 3.5: Markdown variants for some popular publishing systems.
SystemMarkdown Variant
GitHub Wikismarkdown_github
Drupalmarkdown_phpextra
WordPress.commarkdown_phpextra+backtick_code_blocks
StackOverflowmarkdown_strict+autolink_bare_uris

In many cases, you can simply copy and paste the Markdown generated byrmarkdown::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 asblogdown(Xie, Hill, and Thomas 2017;Xie, Dervieux, and Presmanes Hill 2023) as introduced in Section10 instead of manually copying the Markdown content.

3.7.2 Other features

Refer to Section3.1 for the documentation of other features of Markdown documents, including table of contents (Section3.1.1), figure options (Section3.1.5), header and before/after body inclusions (Section3.1.10.2), Pandoc arguments (Section3.1.10.5), and shared options (Section3.1.11).

References

Xie, Yihui, Christophe Dervieux, and Alison Presmanes Hill. 2023.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 withR Markdown. Boca Raton, Florida: Chapman; Hall/CRC.https://github.com/rstudio/blogdown.