Cheatsheets:Markdown: Difference between revisions

From Wikibase
Jump to navigation Jump to search
Emphasis word-boundaries note as negative/positive table; Lists split into Unordered/Ordered subsections with marker and numbering equivalence tables (via update-page on MediaWiki MCP Server)
Line 143: Line 143:


<blockquote>
<blockquote>
'''Emphasis needs word boundaries''' — underscores inside a word are literal, not emphasis.
'''Emphasis needs word boundaries''' — underscores inside a word are literal, not emphasis:


Source <syntaxhighlight lang="markdown" inline>foo_bar_baz</syntaxhighlight> renders as foo_bar_baz, not as
{| class="wikitable"
"foo<i>bar</i>baz". Fix: use asterisks around whole words instead:
! Source !! Rendered
 
|-
<syntaxhighlight lang="markdown">
| <syntaxhighlight lang="markdown">foo_bar_baz</syntaxhighlight> || foo_bar_baz (literal, no emphasis)
*foo bar* baz
|-
</syntaxhighlight>
| <syntaxhighlight lang="markdown">*foo bar* baz</syntaxhighlight> || <em>foo bar</em> baz
|}
</blockquote>
</blockquote>


Line 178: Line 179:
== Lists ==
== Lists ==


Unordered markers <syntaxhighlight lang="markdown" inline>-</syntaxhighlight>, <syntaxhighlight lang="markdown" inline>*</syntaxhighlight> and <syntaxhighlight lang="markdown" inline>+</syntaxhighlight> are interchangeable. Ordered lists number from the first item's number, whatever you write:
=== Unordered ===
 
The markers <syntaxhighlight lang="markdown" inline>-</syntaxhighlight>, <syntaxhighlight lang="markdown" inline>*</syntaxhighlight> and <syntaxhighlight lang="markdown" inline>+</syntaxhighlight> are interchangeable — the same list, three ways:


{| class="wikitable"
! <syntaxhighlight lang="markdown" inline>-</syntaxhighlight> !! <syntaxhighlight lang="markdown" inline>*</syntaxhighlight> !! <syntaxhighlight lang="markdown" inline>+</syntaxhighlight>
|-
|
<syntaxhighlight lang="markdown">
<syntaxhighlight lang="markdown">
3. Mix the flour and milk.
- fruit
4. Cook the batter in a pan.
- veg
</syntaxhighlight>
||
<syntaxhighlight lang="markdown">
* fruit
* veg
</syntaxhighlight>
||
<syntaxhighlight lang="markdown">
+ fruit
+ veg
</syntaxhighlight>
</syntaxhighlight>
|}


Rendered:
All three render identically:


<blockquote>
<blockquote>
<ol start="3">
<ul>
<li>Mix the flour and milk.</li>
<li>fruit</li>
<li>Cook the batter in a pan.</li>
<li>veg</li>
</ol>
</ul>
</blockquote>
</blockquote>
The numbering starts at 3, as typed — the first item's number sets the start.


Nest with an indentation:
Nest with an indentation:
Line 216: Line 232:
<li>veg</li>
<li>veg</li>
</ul>
</ul>
</blockquote>
=== Ordered ===
Numbering starts from the first item's number, whatever you write afterwards:
{| class="wikitable"
! 3, 4 !! 3, 5 !! 3, 800
|-
|
<syntaxhighlight lang="markdown">
3. Mix the flour and milk.
4. Cook the batter in a pan.
</syntaxhighlight>
||
<syntaxhighlight lang="markdown">
3. Mix the flour and milk.
5. Cook the batter in a pan.
</syntaxhighlight>
||
<syntaxhighlight lang="markdown">
3. Mix the flour and milk.
800. Cook the batter in a pan.
</syntaxhighlight>
|}
All three render identically — the numbers after the first are ignored:
<blockquote>
<ol start="3">
<li>Mix the flour and milk.</li>
<li>Cook the batter in a pan.</li>
</ol>
</blockquote>
</blockquote>



Revision as of 16:06, 19 August 2026

Languages: English · français · Esperanto

Quick reference for smart people — part of our dev cheatsheets collection.

Markdown is plain text with a few markers that a renderer turns into HTML. This page is a syntax reference for CommonMark, the standard. GitHub Flavored Markdown (GFM) extensions are covered in the GFM extensions section.

New to Markdown? CommonMark interactive tutorial may interest you.

Basic example: Pancake recipe

Markdown source Compiled to HTML Rendered in the browser
# Pancakes

A quick pancake recipe for two.

## Ingredients

- 150 g flour
- 250 ml milk

## Steps

1. Mix the flour and milk.
2. Cook the batter in a pan.
<h1>Pancakes</h1>
<p>A quick pancake recipe for two.</p>
<h2>Ingredients</h2>
<ul>
<li>150 g flour</li>
<li>250 ml milk</li>
</ul>
<h2>Steps</h2>
<ol type="1">
<li>Mix the flour and milk.</li>
<li>Cook the batter in a pan.</li>
</ol>

Pancakes

A quick pancake recipe for two.

Ingredients

  • 150 g flour
  • 250 ml milk

Steps

  1. Mix the flour and milk.
  2. Cook the batter in a pan.

Paragraphs and line breaks

  • Two paragraphs must be separated by a blank line.
  • A single newline becomes a space when rendered.
  • For a hard linebreak within a paragraph, use \
line one
line two

Rendered:

line one line two

line one\
line two

Rendered:

line one
line two

Headings

One to six # markers set the level.

Source Level
# Pancakes h1
## Ingredients h2
... ...
###### Note h6

A space between the last marker and the text is required:

Wrong (no space) Right
#Pancakes

Rendered: the line stays a paragraph and the # is literal:

#Pancakes

# Pancakes

Rendered: a level-1 heading:

Pancakes

Emphasis

Source Rendered
*italic* or _italic_ italic
**bold** or __bold__ bold
***both*** both

Emphasis needs word boundaries — underscores inside a word are literal, not emphasis:

Source Rendered
foo_bar_baz
foo_bar_baz (literal, no emphasis)
*foo bar* baz
foo bar baz
Source Rendered
[CommonMark](https://commonmark.org) CommonMark
![alt text](image.png) alt text

Alternatively to classic links like [CommonMark](https://commonmark.org), you can also use reference-style links, which allow you to refer to the target link with an arbitrary placeholder then declare the equivalence of the placeholder to your target link at the end of the file. This allows you to reuse a link in multiple places without repeating it.

Source Rendered
[CommonMark][cm]

... 

[cm]: https://commonmark.org
CommonMark

Lists

Unordered

The markers -, * and + are interchangeable — the same list, three ways:

- * +
- fruit
- veg
* fruit
* veg
+ fruit
+ veg

All three render identically:

  • fruit
  • veg

Nest with an indentation:

- fruit
  - apple
  - pear
- veg

Rendered:

  • fruit
    • apple
    • pear
  • veg

Ordered

Numbering starts from the first item's number, whatever you write afterwards:

3, 4 3, 5 3, 800
3. Mix the flour and milk.
4. Cook the batter in a pan.
3. Mix the flour and milk.
5. Cook the batter in a pan.
3. Mix the flour and milk.
800. Cook the batter in a pan.

All three render identically — the numbers after the first are ignored:

  1. Mix the flour and milk.
  2. Cook the batter in a pan.

A blank line between items makes a loose list — each item is wrapped in a paragraph:

Without (tight) With a blank line (loose)
- fruit
- veg

Rendered:

  • fruit
  • veg
- fruit

- veg

Rendered:

  • fruit

  • veg

Code

Inline code — backticks; when the code itself contains a backtick, use two backticks:

Source Rendered
`pip install markdown` pip install markdown
`` `expr` `` `expr`

Fenced blocks — three backticks; the word after the opening fence enables syntax highlighting:

```python
print("hi")
```

Rendered:

print("hi")

Legacy syntax-indented code blocks: Four leading spaces also produce a code block, without highlighting:

    print("hi")

Rendered:

print("hi")

This form is not recommended — it is easy to break (a blank line ends it, and the indentation must change inside lists). Since this used to be the standard for early versions of commonMark, you may still see it in older documents.

Blockquotes

A line starting with > is a blockquote; an empty > keeps paragraphs separate inside the quote.

> quoted line
>
> second quoted line

Rendered:

quoted line

second quoted line

Nested quotes — >>:

> outer
>
> > inner

Rendered:

outer

inner

GFM extensions

GitHub Flavored Markdown (GFM) used on GitHub and increasingly elsewhere, extends commonMark syntax with the following additions:

Strikethrough — two tildes:

Source Rendered
~~struck~~ struck

Tables

| Left | Center | Right |
|:-----|:------:|------:|
| a    | b      | c     |

When rendered, the first column is left-aligned (:-----), the second center-aligned (:-----:) and the third right-aligned (-----:):

LeftCenterRight
abc

Task lists

- [x] mix the batter
- [ ] cook the pancakes

Rendered:

☑ mix the batter
☐ cook the pancakes

Escaping

A backslash makes the next character literal:

Source Rendered
\*not italic\* *not italic*
\# not a heading # not a heading

Also, Markdown inside an HTML block is not parsed — raw HTML passes through untouched.

<div>
*bold?* no, raw
</div>

renders the *bold?* literally:

*bold?* yes

Further reading