10  Markdown

Author

Jarad Niemi

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.

10.1 Syntax

10.1.1 Headings

# Heading 1

## Heading 2

### Heading 3

10.1.2 Block quotes

The Markdown definition above uses a block quote.

> This is a block quote

10.1.3 Lists

We can easily construct unordered lists

- item 1
- item 2
- item 3

and ordered lists

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

and checklists

- [ ] to do 1
- [ ] to do 2
- [x] to do 3

10.1.4 Text Formatting

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

- *italics*, **bold**, ***bold italics***
- superscript^2^ / subscript~2~
- ~~strikethrough~~
- `verbatim code`

10.1.6 Math

We can include math inline \(1+1=2\) or as display math using language similar to the LaTeX language.

$$
Y \sim Bin(n,\theta).
$$

10.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 beginning 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
---

10.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())