Markdown is a lightweight markup language, originally created by John Gruber and Aaron Swartz
allowing people “to write using an easy-to-read, easy-to-write plain text format, then convert
it to structurally valid XHTML (or HTML)”.
- Wikipedia
Block elements
Paragraphs and line breaks
A paragraph is one or more consecutive lines, separated by blank line.
To insert a <br />
, end a line with two or more spaces.
Setext-style
Markdown:
This is an H1
=============
This is an H2
-------------
HTML:
<h1> This is an H1</h1>
<h2> This is an H2</h2>
Atx-style
Markdown:
# This is an H1
## This is an H2
### This is an H3
#### This is an H4
##### This is an H5
###### This is an H6
HTML:
<h1> This is an H1</h1>
<h2> This is an H2</h2>
<h3> This is an H3</h3>
<h4> This is an H4</h4>
<h5> This is an H5</h5>
<h6> This is an H6</h6>
Blockquotes
Markdown:
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
>
> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.
HTML:
<blockquote>
<h2> This is a header.</h2>
<ol>
<li> This is the first list item.</li>
<li> This is the second list item.</li>
</ol>
<p> Here's some example code:</p>
<pre><code> return shell_exec("echo $input | $markdown_script");
</code></pre>
<p> This is the first level of quoting.</p>
<blockquote>
<p> This is nested blockquote.</p>
</blockquote>
<p> Back to the first level.</p>
</blockquote>
Lists
Unordered lists use asterisks *, pluses +, or hyphens -
Markdown:
* Red
* Green
* Blue
HTML:
<ul>
<li> Red</li>
<li> Green</li>
<li> Blue</li>
</ul>
Ordered lists
Markdown:
1. Bird
2. McHale
3. Parish
HTML:
<ol>
<li> Bird</li>
<li> McHale</li>
<li> Parish</li>
</ol>
Code blocks
To produce a code block, indent every line of the block by at least 4 spaces or 1 tab.
Markdown:
tell application "Foo"
beep
end tell
HTML:
<pre><code> tell application "Foo"
beep
end tell
</code></pre>
Horizontal rules
Markdown:
* * *
***
*****
- - -
__________________________________
HTML:
<hr />
<hr />
<hr />
<hr />
Span elements
Links
inline-style
Markdown:
This is [an example](http://example.com/ "Title") inline link.
[This link](http://example.net/) has no title attribute.
HTML:
<p> This is <a href= "http://example.com/" title= "Title" > an example</a> inline link.</p>
<p><a href= "http://example.net/" > This link</a> has no title attribute.</p>
reference-style
Markdown:
This is [an example][id] reference-style link.
[id]: http://example.com/ "Optional Title Here"
HTML:
<p> This is <a href= "http://example.com/" title= "Optional Title Here" > an example</a> reference-style link.</p>
Markdown:
Visit [Daring Fireball][] for more information.
[Daring Fireball]: http://daringfireball.net/
HTML:
<p> Visit <a href= "http://daringfireball.net/" > Daring Fireball</a> for more information.</p>
Emphasis
Markdown:
*single asterisks*
_single underscores_
**double asterisks**
__double underscores__
HTML:
<p><em> single asterisks</em></p>
<p><em> single underscores</em></p>
<p><strong> double asterisks</strong></p>
<p><strong> double underscores</strong></p>
Code
Markdown:
Use the `printf()` function.
HTML:
<p> Use the <code> printf()</code> function.</p>
Images
inline-style
Markdown:
![Alt text](/path/to/img.jpg "Optional title")
HTML:
<p><img src= "/path/to/img.jpg" alt= "Alt text" title= "Optional title" /></p>
reference-style
Markdown:
![Alt text](/path/to/img.jpg)
![Alt text](/path/to/img.jpg "Optional title")
HTML:
<p><img src= "/path/to/img.jpg" alt= "Alt text" title= "" /></p>
<p><img src= "/path/to/img.jpg" alt= "Alt text" title= "Optional title" /></p>
Miscellaneous
Automatic links
Markdown:
<http://example.com/>
HTML:
<p><a href= "http://example.com/" > http://example.com/</a></p>
Backslash escapes
The following characters could be escaped:
\ backslash
` backtick
* asterisk
_ underscore
{} curly braces
[] square brackets
() parentheses
# hash mark
+ plus sign
- minus sign (hyphen)
. dot
! exclamation mark
Markdown:
\*literal asterisks\*
HTML:
<p> *literal asterisks*</p>
References
Twitter · Facebook
Linkedin · Delicious
GitHub · Douban · Xbox Live