Part 7 Markdown

Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Markdown’s simplicity and readability render it attractive for a wide range of writing and documentation tasks. Its flexibility allows it to be extended to suit more complex needs, making it a versatile tool. Created by John Gruber in 2004, its primary purpose is to allow people to write in an easy-to-read and easy-to-write plain text format, which can then be converted to structurally valid HTML (or other formats such as docx or pdf). Markdown is widely used for documentation, web writing, and content creation because of its simplicity and flexibility. Markdown provides an authoring framework for data science as Markdown can produce high quality reports that can be shared with an audience. The advantage of Markdown is that one can use a single Markdown file (or Markdown document) to combine

  • executable code

  • code output (such as visualizations and results of calculations)

  • plain text (to explain, report, and document)

R Markdown documents are fully reproducible and support dozens of static and dynamic output formats. Here are some key points about Markdown:

  • Simplicity: Markdown syntax is designed to be readable and easy to write. It avoids the complexity of other markup languages, making it accessible even for non-technical users.

  • Plain Text Formatting: Since Markdown is written in plain text, it can be created and edited in any text editor. This makes it highly portable and version control friendly.

  • Conversion: Markdown can be easily converted to HTML, making it ideal for web content. Many static site generators and content management systems support Markdown natively.

  • Extensibility: While the core syntax is intentionally simple, Markdown can be extended with plugins or additional syntaxes for more advanced features like tables, footnotes, and embedded content.

Common Uses of Markdown include, for example, documentation, read-me files, notes, and to-do lists because it is easy to read in its raw form and can be rendered beautifully in web browsers.

Check out this introduction to R Markdown by RStudio and have a look at this R Markdown cheat sheet.

Here’s a guide with commands on the top and their rendered output below.

Headings

Command:

# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6

Rendered:

# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6

7.1 Custom IDs for Headings

Command:

### Custom ID Heading {#custom-id}

Rendered:

7.1.1 Custom ID Heading

Table of Contents

Command:

## Table of Contents
- [Headings](#headings)
- [Blockquotes](#blockquotes)
- [Images](#images)
- [Tables](#tables)

Rendered:

7.2 Table of Contents

Emphasis

Command:

*Italic text*
_Italic text_

**Bold text**
__Bold text__

***Bold and italic***
___Bold and italic___

Rendered:

Italic text
Italic text

Bold text
Bold text

Bold and italic
Bold and italic

Strikethrough

Command:

This is a ~~strikethrough~~ example.

Rendered:

This is a strikethrough example.

Superscript and Subscript

Command:

H~2~O and E=mc^2^

Rendered:

H2O and E=mc2

Highlight

Command:

I need to ==highlight== this text.

Rendered:

I need to ==highlight== this text.

Emojis

Command:

Here is an emoji: :smile:

Rendered:

Here is an emoji: :smile:

Emoji Shortcodes

Command:

:smile: :+1: :sparkles:

Rendered:

:smile: :+1: :sparkles:

Lists

Unordered List

Command:

- Item 1
- Item 2
  - Subitem 2.1
  - Subitem 2.2
- Item 3

Rendered:

  • Item 1
  • Item 2
    • Subitem 2.1
    • Subitem 2.2
  • Item 3

Ordered List

Command:

1. First item
2. Second item
3. Third item
   1. Subitem 3.1
   2. Subitem 3.2

Rendered:

  1. First item
  2. Second item
  3. Third item
    1. Subitem 3.1
    2. Subitem 3.2

Task Lists

Command:

- [x] Completed task
- [ ] Incomplete task
- [ ] Another incomplete task

Rendered:

Advanced Task Lists

Command:

- [ ] Task 1
  - [x] Subtask 1
  - [ ] Subtask 2
- [x] Task 2

Rendered:

Definition Lists

Command:

First Term
: This is the definition of the first term.

Second Term
: This is the definition of the second term.

Rendered:

First Term
This is the definition of the first term.
Second Term
This is the definition of the second term.

Nested Lists

Command:

1. First item
   - Subitem 1
     - Sub-subitem 1
   - Subitem 2
2. Second item

Rendered:

  1. First item
    • Subitem 1
      • Sub-subitem 1
    • Subitem 2
  2. Second item

Images

Command:

![Alt text](https://via.placeholder.com/150)

Rendered:

Alt text
Alt text

Blockquotes

Command:

> This is a blockquote.
> 
> This is a second paragraph within the blockquote.

Rendered:

This is a blockquote.

This is a second paragraph within the blockquote.

Blockquotes with Multiple Paragraphs

Command:

> This is a blockquote with multiple paragraphs.
>
> This is the second paragraph in the blockquote.

Rendered:

This is a blockquote with multiple paragraphs.

This is the second paragraph in the blockquote.

Code

Inline Code

Command:

`inline code`

Rendered:

inline code

Code Block

Command:

```markdown
{
  "firstName": "Martin",
  "lastName": "Schweinberger",
  "age": 43
}
```

Rendered:

{
  "firstName": "John",
  "lastName": "Smith",
  "age": 25
}

Blockquotes with Nested Elements

Command:

> ### This is a heading
> - This is a list item within a blockquote
> - Another item
>
> > This is a nested blockquote

Rendered:

This is a heading

  • This is a list item within a blockquote
  • Another item

This is a nested blockquote

Inline HTML

Command:

<p>This is an inline HTML paragraph.</p>

Rendered:

This is an inline HTML paragraph.

HTML Entities

Command:

AT&T &copy; 2024

Rendered:

AT&T © 2024

Expandable Sections (Details Tag)

Command:

<details>
  <summary>Click to expand</summary>
  This is the detailed content that is hidden until expanded.
</details>

Rendered:

Click to expand This is the detailed content that is hidden until expanded.

Horizontal Rule

Command:

---

Rendered:


Tables

Command:

| Header 1 | Header 2 |
|----------|----------|
| Cell 1   | Cell 2   |
| Cell 3   | Cell 4   |

Rendered:

Header 1 Header 2
Cell 1 Cell 2
Cell 3 Cell 4

Advanced Tables

Command:

| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 |
| Row 2 Col 1 | Row 2 Col 2 | Row 2 Col 3 |

Rendered:

Header 1 Header 2 Header 3
Row 1 Col 1 Row 1 Col 2 Row 1 Col 3
Row 2 Col 1 Row 2 Col 2 Row 2 Col 3

Footnotes

Command:

Here is a simple footnote[^1].

[^1]: This is the footnote.

Rendered:

Here is a simple footnote1 (you can find it at the end/bottom of this document).

Syntax Highlighting

Command:

```python
def hello_world():
    print("Hello, world!")
```

Rendered:

def hello_world():
    print("Hello, world!")

Math Expressions

Command:

Inline math: $E = mc^2$

Block math:
$$
\frac{a}{b} = c
$$

Rendered:

Inline math: \(E = mc^2\)

Block math:

\[ \frac{a}{b} = c \]

Escaping Characters

Command:

Use the backslash to escape special characters: \*literal asterisks\*

Rendered:

Use the backslash to escape special characters: *literal asterisks*

Mermaid Diagrams

Command:

```mermaid
graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;

**Rendered:**

```mermaid
graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;

These additional advanced Markdown features allow you to create even more complex and sophisticated documents. Practice using these commands to further enhance your Markdown proficiency!


  1. This is the footnote.↩︎