To create an 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 ---
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)
markdown_github(GitHub flavored markdown)
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 ---
The pandoc markdown specification defines all of the markdown extensions and their name to be used in composing custom variants.
Many popular publishing systems now accept markdown as input. Here are the correct markdown variants to use for some popular systems:
In many cases you can simply copy and paste the markdown generated by
render into the editing interface of the system you are targeting. Note however that if you have embedded plots or other images you’ll need to upload them separately and fixup their URLs to point to the uploaded location.
You can add a table of contents using the
toc option and specify the depth of headers that it applies to using the
toc_depth option. For example:
--- title: "Habits" output: md_document: toc: true toc_depth: 2 ---
If the table of contents depth isn’t explicitly specified then it defaults to 3 (meaning that all level 1, 2, and 3 headers will be included in the table of contents).
There are a number of options that affect the output of figures within HTML documents:
fig_height can be used to control the default figure width and height (7x5 is used by default)
fig_retina specifies the scaling to perform for retina displays (defaults to
null which prevents retina scaling). Retina scaling is generally not useful for markdown output since rendering retina images requires explicit use of HTML
img tags rather than native markdown image syntax.
dev controls the graphics device used to render figures (defaults to png)
--- title: "Habits" output: md_document: fig_width: 7 fig_height: 6 ---
You can do more advanced customization of output by including additional content. To include content in the document header or before/after the document body you use the
includes option as follows:
--- title: "Habits" output: md_document: includes: in_header: header.md before_body: doc_prefix.md after_body: doc_suffix.md ---
If there are pandoc features you want to use that lack equivilants in the YAML options described above you can still use them by passing custom
pandoc_args. For example:
--- title: "Habits" output: md_document: pandoc_args: [ "--csl", "/var/csl/acs-nano.csl" ] ---
Documentation on all available pandoc arguments can be found in the pandoc user guide.