30  Markdown

Author

Jarad Niemi

R Code Button

From daringfireball:

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

There many version of Markdown and we will focus on Pandoc markdown as that is what we will use for Rmarkdown and Quarto documents.

For this class, we will look at the Markdown code for this page.

30.1 Syntax

30.1.1 Headings

# Heading 1

## Heading 2

### Heading 3

30.1.2 Block quotes

The Markdown definition above uses a block quote.

> This is a block quote

30.1.3 Lists

We can easily construct unordered lists

  • item 1
  • item 2
  • item 3

and ordered lists

  1. item 1
  2. item 2
  3. item 3

and checklists

30.1.4 Text Formatting

Markdown allows you to quickly create a variety of different text formats

  • italics, bold, bold italics
  • superscript2 / subscript2
  • strikethrough
  • verbatim code

30.1.6 Math

We can include math inline \(1+1=2\) or as display math

\[ Y \sim Bin(n,\theta). \]

30.2 YAML Metadata

Metadata can be included in a Markdown file using a YAML format. Originally YAML meant Yet Another Markup Language, but now is said to mean YAML Ain’t Markup Language. Include YAML metadata at the begining of the file and distinguish it using --- before and after.

---
title:  "Markdown"
author: "Jarad Niemi"
date:   "2024-04-2"
output:
  html_document:
    toc: true
    toc_depth: 2
---

The example document we have does not have any metadata because the document is part of a larger book structure.

30.3 Compile

To compile a Markdown document into its output format, you can use the Render button in RStudio.

In a script, you use the render function from the rmarkdown package.

render("communicate-markdown.md", 
       output_format = html_document())