1<h1>Markdown: Syntax</h1>
2<ul id="ProjectSubmenu">
3    <li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
4    <li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
5    <li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
6    <li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
7    <li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
8</ul>
9<ul>
10<li><a href="#overview">Overview</a><ul>
11<li><a href="#philosophy">Philosophy</a></li>
12<li><a href="#html">Inline HTML</a></li>
13<li><a href="#autoescape">Automatic Escaping for Special Characters</a></li>
14</ul>
15</li>
16<li><a href="#block">Block Elements</a><ul>
17<li><a href="#p">Paragraphs and Line Breaks</a></li>
18<li><a href="#header">Headers</a></li>
19<li><a href="#blockquote">Blockquotes</a></li>
20<li><a href="#list">Lists</a></li>
21<li><a href="#precode">Code Blocks</a></li>
22<li><a href="#hr">Horizontal Rules</a></li>
23</ul>
24</li>
25<li><a href="#span">Span Elements</a><ul>
26<li><a href="#link">Links</a></li>
27<li><a href="#em">Emphasis</a></li>
28<li><a href="#code">Code</a></li>
29<li><a href="#img">Images</a></li>
30</ul>
31</li>
32<li><a href="#misc">Miscellaneous</a><ul>
33<li><a href="#backslash">Backslash Escapes</a></li>
34<li><a href="#autolink">Automatic Links</a></li>
35</ul>
36</li>
37</ul>
38<p><strong>Note:</strong> This document is itself written using Markdown; you
39can <a href="/projects/markdown/syntax.text">see the source for it by adding '.text' to the URL</a>.</p>
40<hr />
41<h2 id="overview">Overview</h2>
42<h3 id="philosophy">Philosophy</h3>
43<p>Markdown is intended to be as easy-to-read and easy-to-write as is feasible.</p>
44<p>Readability, however, is emphasized above all else. A Markdown-formatted
45document should be publishable as-is, as plain text, without looking
46like it's been marked up with tags or formatting instructions. While
47Markdown's syntax has been influenced by several existing text-to-HTML
48filters -- including <a href="http://docutils.sourceforge.net/mirror/setext.html">Setext</a>, <a href="http://www.aaronsw.com/2002/atx/">atx</a>, <a href="http://textism.com/tools/textile/">Textile</a>, <a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a>,
49<a href="http://www.triptico.com/software/grutatxt.html">Grutatext</a>, and <a href="http://ettext.taint.org/doc/">EtText</a> -- the single biggest source of
50inspiration for Markdown's syntax is the format of plain text email.</p>
51<p>To this end, Markdown's syntax is comprised entirely of punctuation
52characters, which punctuation characters have been carefully chosen so
53as to look like what they mean. E.g., asterisks around a word actually
54look like *emphasis*. Markdown lists look like, well, lists. Even
55blockquotes look like quoted passages of text, assuming you've ever
56used email.</p>
57<h3 id="html">Inline HTML</h3>
58<p>Markdown's syntax is intended for one purpose: to be used as a
59format for <em>writing</em> for the web.</p>
60<p>Markdown is not a replacement for HTML, or even close to it. Its
61syntax is very small, corresponding only to a very small subset of
62HTML tags. The idea is <em>not</em> to create a syntax that makes it easier
63to insert HTML tags. In my opinion, HTML tags are already easy to
64insert. The idea for Markdown is to make it easy to read, write, and
65edit prose. HTML is a <em>publishing</em> format; Markdown is a <em>writing</em>
66format. Thus, Markdown's formatting syntax only addresses issues that
67can be conveyed in plain text.</p>
68<p>For any markup that is not covered by Markdown's syntax, you simply
69use HTML itself. There's no need to preface it or delimit it to
70indicate that you're switching from Markdown to HTML; you just use
71the tags.</p>
72<p>The only restrictions are that block-level HTML elements -- e.g. <code>&lt;div&gt;</code>,
73<code>&lt;table&gt;</code>, <code>&lt;pre&gt;</code>, <code>&lt;p&gt;</code>, etc. -- must be separated from surrounding
74content by blank lines, and the start and end tags of the block should
75not be indented with tabs or spaces. Markdown is smart enough not
76to add extra (unwanted) <code>&lt;p&gt;</code> tags around HTML block-level tags.</p>
77<p>For example, to add an HTML table to a Markdown article:</p>
78<pre><code>This is a regular paragraph.
79
80&lt;table&gt;
81    &lt;tr&gt;
82        &lt;td&gt;Foo&lt;/td&gt;
83    &lt;/tr&gt;
84&lt;/table&gt;
85
86This is another regular paragraph.
87</code></pre>
88<p>Note that Markdown formatting syntax is not processed within block-level
89HTML tags. E.g., you can't use Markdown-style <code>*emphasis*</code> inside an
90HTML block.</p>
91<p>Span-level HTML tags -- e.g. <code>&lt;span&gt;</code>, <code>&lt;cite&gt;</code>, or <code>&lt;del&gt;</code> -- can be
92used anywhere in a Markdown paragraph, list item, or header. If you
93want, you can even use HTML tags instead of Markdown formatting; e.g. if
94you'd prefer to use HTML <code>&lt;a&gt;</code> or <code>&lt;img&gt;</code> tags instead of Markdown's
95link or image syntax, go right ahead.</p>
96<p>Unlike block-level HTML tags, Markdown syntax <em>is</em> processed within
97span-level tags.</p>
98<h3 id="autoescape">Automatic Escaping for Special Characters</h3>
99<p>In HTML, there are two characters that demand special treatment: <code>&lt;</code>
100and <code>&amp;</code>. Left angle brackets are used to start tags; ampersands are
101used to denote HTML entities. If you want to use them as literal
102characters, you must escape them as entities, e.g. <code>&amp;lt;</code>, and
103<code>&amp;amp;</code>.</p>
104<p>Ampersands in particular are bedeviling for web writers. If you want to
105write about 'AT&amp;T', you need to write '<code>AT&amp;amp;T</code>'. You even need to
106escape ampersands within URLs. Thus, if you want to link to:</p>
107<pre><code>http://images.google.com/images?num=30&amp;q=larry+bird
108</code></pre>
109<p>you need to encode the URL as:</p>
110<pre><code>http://images.google.com/images?num=30&amp;amp;q=larry+bird
111</code></pre>
112<p>in your anchor tag <code>href</code> attribute. Needless to say, this is easy to
113forget, and is probably the single most common source of HTML validation
114errors in otherwise well-marked-up web sites.</p>
115<p>Markdown allows you to use these characters naturally, taking care of
116all the necessary escaping for you. If you use an ampersand as part of
117an HTML entity, it remains unchanged; otherwise it will be translated
118into <code>&amp;amp;</code>.</p>
119<p>So, if you want to include a copyright symbol in your article, you can write:</p>
120<pre><code>&amp;copy;
121</code></pre>
122<p>and Markdown will leave it alone. But if you write:</p>
123<pre><code>AT&amp;T
124</code></pre>
125<p>Markdown will translate it to:</p>
126<pre><code>AT&amp;amp;T
127</code></pre>
128<p>Similarly, because Markdown supports <a href="#html">inline HTML</a>, if you use
129angle brackets as delimiters for HTML tags, Markdown will treat them as
130such. But if you write:</p>
131<pre><code>4 &lt; 5
132</code></pre>
133<p>Markdown will translate it to:</p>
134<pre><code>4 &amp;lt; 5
135</code></pre>
136<p>However, inside Markdown code spans and blocks, angle brackets and
137ampersands are <em>always</em> encoded automatically. This makes it easy to use
138Markdown to write about HTML code. (As opposed to raw HTML, which is a
139terrible format for writing about HTML syntax, because every single <code>&lt;</code>
140and <code>&amp;</code> in your example code needs to be escaped.)</p>
141<hr />
142<h2 id="block">Block Elements</h2>
143<h3 id="p">Paragraphs and Line Breaks</h3>
144<p>A paragraph is simply one or more consecutive lines of text, separated
145by one or more blank lines. (A blank line is any line that looks like a
146blank line -- a line containing nothing but spaces or tabs is considered
147blank.) Normal paragraphs should not be indented with spaces or tabs.</p>
148<p>The implication of the "one or more consecutive lines of text" rule is
149that Markdown supports "hard-wrapped" text paragraphs. This differs
150significantly from most other text-to-HTML formatters (including Movable
151Type's "Convert Line Breaks" option) which translate every line break
152character in a paragraph into a <code>&lt;br /&gt;</code> tag.</p>
153<p>When you <em>do</em> want to insert a <code>&lt;br /&gt;</code> break tag using Markdown, you
154end a line with two or more spaces, then type return.</p>
155<p>Yes, this takes a tad more effort to create a <code>&lt;br /&gt;</code>, but a simplistic
156"every line break is a <code>&lt;br /&gt;</code>" rule wouldn't work for Markdown.
157Markdown's email-style <a href="#blockquote">blockquoting</a> and multi-paragraph <a href="#list">list items</a>
158work best -- and look better -- when you format them with hard breaks.</p>
159<h3 id="header">Headers</h3>
160<p>Markdown supports two styles of headers, <a href="http://docutils.sourceforge.net/mirror/setext.html">Setext</a> and <a href="http://www.aaronsw.com/2002/atx/">atx</a>.</p>
161<p>Setext-style headers are "underlined" using equal signs (for first-level
162headers) and dashes (for second-level headers). For example:</p>
163<pre><code>This is an H1
164=============
165
166This is an H2
167-------------
168</code></pre>
169<p>Any number of underlining <code>=</code>'s or <code>-</code>'s will work.</p>
170<p>Atx-style headers use 1-6 hash characters at the start of the line,
171corresponding to header levels 1-6. For example:</p>
172<pre><code># This is an H1
173
174## This is an H2
175
176###### This is an H6
177</code></pre>
178<p>Optionally, you may "close" atx-style headers. This is purely
179cosmetic -- you can use this if you think it looks better. The
180closing hashes don't even need to match the number of hashes
181used to open the header. (The number of opening hashes
182determines the header level.) :</p>
183<pre><code># This is an H1 #
184
185## This is an H2 ##
186
187### This is an H3 ######
188</code></pre>
189<h3 id="blockquote">Blockquotes</h3>
190<p>Markdown uses email-style <code>&gt;</code> characters for blockquoting. If you're
191familiar with quoting passages of text in an email message, then you
192know how to create a blockquote in Markdown. It looks best if you hard
193wrap the text and put a <code>&gt;</code> before every line:</p>
194<pre><code>&gt; This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
195&gt; consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
196&gt; Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
197&gt;
198&gt; Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
199&gt; id sem consectetuer libero luctus adipiscing.
200</code></pre>
201<p>Markdown allows you to be lazy and only put the <code>&gt;</code> before the first
202line of a hard-wrapped paragraph:</p>
203<pre><code>&gt; This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
204consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
205Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
206
207&gt; Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
208id sem consectetuer libero luctus adipiscing.
209</code></pre>
210<p>Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
211adding additional levels of <code>&gt;</code>:</p>
212<pre><code>&gt; This is the first level of quoting.
213&gt;
214&gt; &gt; This is nested blockquote.
215&gt;
216&gt; Back to the first level.
217</code></pre>
218<p>Blockquotes can contain other Markdown elements, including headers, lists,
219and code blocks:</p>
220<pre><code>&gt; ## This is a header.
221&gt;
222&gt; 1.   This is the first list item.
223&gt; 2.   This is the second list item.
224&gt;
225&gt; Here's some example code:
226&gt;
227&gt;     return shell_exec("echo $input | $markdown_script");
228</code></pre>
229<p>Any decent text editor should make email-style quoting easy. For
230example, with BBEdit, you can make a selection and choose Increase
231Quote Level from the Text menu.</p>
232<h3 id="list">Lists</h3>
233<p>Markdown supports ordered (numbered) and unordered (bulleted) lists.</p>
234<p>Unordered lists use asterisks, pluses, and hyphens -- interchangably
235-- as list markers:</p>
236<pre><code>*   Red
237*   Green
238*   Blue
239</code></pre>
240<p>is equivalent to:</p>
241<pre><code>+   Red
242+   Green
243+   Blue
244</code></pre>
245<p>and:</p>
246<pre><code>-   Red
247-   Green
248-   Blue
249</code></pre>
250<p>Ordered lists use numbers followed by periods:</p>
251<pre><code>1.  Bird
2522.  McHale
2533.  Parish
254</code></pre>
255<p>It's important to note that the actual numbers you use to mark the
256list have no effect on the HTML output Markdown produces. The HTML
257Markdown produces from the above list is:</p>
258<pre><code>&lt;ol&gt;
259&lt;li&gt;Bird&lt;/li&gt;
260&lt;li&gt;McHale&lt;/li&gt;
261&lt;li&gt;Parish&lt;/li&gt;
262&lt;/ol&gt;
263</code></pre>
264<p>If you instead wrote the list in Markdown like this:</p>
265<pre><code>1.  Bird
2661.  McHale
2671.  Parish
268</code></pre>
269<p>or even:</p>
270<pre><code>3. Bird
2711. McHale
2728. Parish
273</code></pre>
274<p>you'd get the exact same HTML output. The point is, if you want to,
275you can use ordinal numbers in your ordered Markdown lists, so that
276the numbers in your source match the numbers in your published HTML.
277But if you want to be lazy, you don't have to.</p>
278<p>If you do use lazy list numbering, however, you should still start the
279list with the number 1. At some point in the future, Markdown may support
280starting ordered lists at an arbitrary number.</p>
281<p>List markers typically start at the left margin, but may be indented by
282up to three spaces. List markers must be followed by one or more spaces
283or a tab.</p>
284<p>To make lists look nice, you can wrap items with hanging indents:</p>
285<pre><code>*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
286    Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
287    viverra nec, fringilla in, laoreet vitae, risus.
288*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
289    Suspendisse id sem consectetuer libero luctus adipiscing.
290</code></pre>
291<p>But if you want to be lazy, you don't have to:</p>
292<pre><code>*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
293Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
294viverra nec, fringilla in, laoreet vitae, risus.
295*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
296Suspendisse id sem consectetuer libero luctus adipiscing.
297</code></pre>
298<p>If list items are separated by blank lines, Markdown will wrap the
299items in <code>&lt;p&gt;</code> tags in the HTML output. For example, this input:</p>
300<pre><code>*   Bird
301*   Magic
302</code></pre>
303<p>will turn into:</p>
304<pre><code>&lt;ul&gt;
305&lt;li&gt;Bird&lt;/li&gt;
306&lt;li&gt;Magic&lt;/li&gt;
307&lt;/ul&gt;
308</code></pre>
309<p>But this:</p>
310<pre><code>*   Bird
311
312*   Magic
313</code></pre>
314<p>will turn into:</p>
315<pre><code>&lt;ul&gt;
316&lt;li&gt;&lt;p&gt;Bird&lt;/p&gt;&lt;/li&gt;
317&lt;li&gt;&lt;p&gt;Magic&lt;/p&gt;&lt;/li&gt;
318&lt;/ul&gt;
319</code></pre>
320<p>List items may consist of multiple paragraphs. Each subsequent
321paragraph in a list item must be indented by either 4 spaces
322or one tab:</p>
323<pre><code>1.  This is a list item with two paragraphs. Lorem ipsum dolor
324    sit amet, consectetuer adipiscing elit. Aliquam hendrerit
325    mi posuere lectus.
326
327    Vestibulum enim wisi, viverra nec, fringilla in, laoreet
328    vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
329    sit amet velit.
330
3312.  Suspendisse id sem consectetuer libero luctus adipiscing.
332</code></pre>
333<p>It looks nice if you indent every line of the subsequent
334paragraphs, but here again, Markdown will allow you to be
335lazy:</p>
336<pre><code>*   This is a list item with two paragraphs.
337
338    This is the second paragraph in the list item. You're
339only required to indent the first line. Lorem ipsum dolor
340sit amet, consectetuer adipiscing elit.
341
342*   Another item in the same list.
343</code></pre>
344<p>To put a blockquote within a list item, the blockquote's <code>&gt;</code>
345delimiters need to be indented:</p>
346<pre><code>*   A list item with a blockquote:
347
348    &gt; This is a blockquote
349    &gt; inside a list item.
350</code></pre>
351<p>To put a code block within a list item, the code block needs
352to be indented <em>twice</em> -- 8 spaces or two tabs:</p>
353<pre><code>*   A list item with a code block:
354
355        &lt;code goes here&gt;
356</code></pre>
357<p>It's worth noting that it's possible to trigger an ordered list by
358accident, by writing something like this:</p>
359<pre><code>1986. What a great season.
360</code></pre>
361<p>In other words, a <em>number-period-space</em> sequence at the beginning of a
362line. To avoid this, you can backslash-escape the period:</p>
363<pre><code>1986\. What a great season.
364</code></pre>
365<h3 id="precode">Code Blocks</h3>
366<p>Pre-formatted code blocks are used for writing about programming or
367markup source code. Rather than forming normal paragraphs, the lines
368of a code block are interpreted literally. Markdown wraps a code block
369in both <code>&lt;pre&gt;</code> and <code>&lt;code&gt;</code> tags.</p>
370<p>To produce a code block in Markdown, simply indent every line of the
371block by at least 4 spaces or 1 tab. For example, given this input:</p>
372<pre><code>This is a normal paragraph:
373
374    This is a code block.
375</code></pre>
376<p>Markdown will generate:</p>
377<pre><code>&lt;p&gt;This is a normal paragraph:&lt;/p&gt;
378
379&lt;pre&gt;&lt;code&gt;This is a code block.
380&lt;/code&gt;&lt;/pre&gt;
381</code></pre>
382<p>One level of indentation -- 4 spaces or 1 tab -- is removed from each
383line of the code block. For example, this:</p>
384<pre><code>Here is an example of AppleScript:
385
386    tell application "Foo"
387        beep
388    end tell
389</code></pre>
390<p>will turn into:</p>
391<pre><code>&lt;p&gt;Here is an example of AppleScript:&lt;/p&gt;
392
393&lt;pre&gt;&lt;code&gt;tell application "Foo"
394    beep
395end tell
396&lt;/code&gt;&lt;/pre&gt;
397</code></pre>
398<p>A code block continues until it reaches a line that is not indented
399(or the end of the article).</p>
400<p>Within a code block, ampersands (<code>&amp;</code>) and angle brackets (<code>&lt;</code> and <code>&gt;</code>)
401are automatically converted into HTML entities. This makes it very
402easy to include example HTML source code using Markdown -- just paste
403it and indent it, and Markdown will handle the hassle of encoding the
404ampersands and angle brackets. For example, this:</p>
405<pre><code>    &lt;div class="footer"&gt;
406        &amp;copy; 2004 Foo Corporation
407    &lt;/div&gt;
408</code></pre>
409<p>will turn into:</p>
410<pre><code>&lt;pre&gt;&lt;code&gt;&amp;lt;div class="footer"&amp;gt;
411    &amp;amp;copy; 2004 Foo Corporation
412&amp;lt;/div&amp;gt;
413&lt;/code&gt;&lt;/pre&gt;
414</code></pre>
415<p>Regular Markdown syntax is not processed within code blocks. E.g.,
416asterisks are just literal asterisks within a code block. This means
417it's also easy to use Markdown to write about Markdown's own syntax.</p>
418<h3 id="hr">Horizontal Rules</h3>
419<p>You can produce a horizontal rule tag (<code>&lt;hr /&gt;</code>) by placing three or
420more hyphens, asterisks, or underscores on a line by themselves. If you
421wish, you may use spaces between the hyphens or asterisks. Each of the
422following lines will produce a horizontal rule:</p>
423<pre><code>* * *
424
425***
426
427*****
428
429- - -
430
431---------------------------------------
432
433_ _ _
434</code></pre>
435<hr />
436<h2 id="span">Span Elements</h2>
437<h3 id="link">Links</h3>
438<p>Markdown supports two style of links: <em>inline</em> and <em>reference</em>.</p>
439<p>In both styles, the link text is delimited by [square brackets].</p>
440<p>To create an inline link, use a set of regular parentheses immediately
441after the link text's closing square bracket. Inside the parentheses,
442put the URL where you want the link to point, along with an <em>optional</em>
443title for the link, surrounded in quotes. For example:</p>
444<pre><code>This is [an example](http://example.com/ "Title") inline link.
445
446[This link](http://example.net/) has no title attribute.
447</code></pre>
448<p>Will produce:</p>
449<pre><code>&lt;p&gt;This is &lt;a href="http://example.com/" title="Title"&gt;
450an example&lt;/a&gt; inline link.&lt;/p&gt;
451
452&lt;p&gt;&lt;a href="http://example.net/"&gt;This link&lt;/a&gt; has no
453title attribute.&lt;/p&gt;
454</code></pre>
455<p>If you're referring to a local resource on the same server, you can
456use relative paths:</p>
457<pre><code>See my [About](/about/) page for details.
458</code></pre>
459<p>Reference-style links use a second set of square brackets, inside
460which you place a label of your choosing to identify the link:</p>
461<pre><code>This is [an example][id] reference-style link.
462</code></pre>
463<p>You can optionally use a space to separate the sets of brackets:</p>
464<pre><code>This is [an example] [id] reference-style link.
465</code></pre>
466<p>Then, anywhere in the document, you define your link label like this,
467on a line by itself:</p>
468<pre><code>[id]: http://example.com/  "Optional Title Here"
469</code></pre>
470<p>That is:</p>
471<ul>
472<li>Square brackets containing the link identifier (optionally
473indented from the left margin using up to three spaces);</li>
474<li>followed by a colon;</li>
475<li>followed by one or more spaces (or tabs);</li>
476<li>followed by the URL for the link;</li>
477<li>optionally followed by a title attribute for the link, enclosed
478in double or single quotes, or enclosed in parentheses.</li>
479</ul>
480<p>The following three link definitions are equivalent:</p>
481<pre><code>[foo]: http://example.com/  "Optional Title Here"
482[foo]: http://example.com/  'Optional Title Here'
483[foo]: http://example.com/  (Optional Title Here)
484</code></pre>
485<p><strong>Note:</strong> There is a known bug in Markdown.pl 1.0.1 which prevents
486single quotes from being used to delimit link titles.</p>
487<p>The link URL may, optionally, be surrounded by angle brackets:</p>
488<pre><code>[id]: &lt;http://example.com/&gt;  "Optional Title Here"
489</code></pre>
490<p>You can put the title attribute on the next line and use extra spaces
491or tabs for padding, which tends to look better with longer URLs:</p>
492<pre><code>[id]: http://example.com/longish/path/to/resource/here
493    "Optional Title Here"
494</code></pre>
495<p>Link definitions are only used for creating links during Markdown
496processing, and are stripped from your document in the HTML output.</p>
497<p>Link definition names may consist of letters, numbers, spaces, and
498punctuation -- but they are <em>not</em> case sensitive. E.g. these two
499links:</p>
500<pre><code>[link text][a]
501[link text][A]
502</code></pre>
503<p>are equivalent.</p>
504<p>The <em>implicit link name</em> shortcut allows you to omit the name of the
505link, in which case the link text itself is used as the name.
506Just use an empty set of square brackets -- e.g., to link the word
507"Google" to the google.com web site, you could simply write:</p>
508<pre><code>[Google][]
509</code></pre>
510<p>And then define the link:</p>
511<pre><code>[Google]: http://google.com/
512</code></pre>
513<p>Because link names may contain spaces, this shortcut even works for
514multiple words in the link text:</p>
515<pre><code>Visit [Daring Fireball][] for more information.
516</code></pre>
517<p>And then define the link:</p>
518<pre><code>[Daring Fireball]: http://daringfireball.net/
519</code></pre>
520<p>Link definitions can be placed anywhere in your Markdown document. I
521tend to put them immediately after each paragraph in which they're
522used, but if you want, you can put them all at the end of your
523document, sort of like footnotes.</p>
524<p>Here's an example of reference links in action:</p>
525<pre><code>I get 10 times more traffic from [Google] [1] than from
526[Yahoo] [2] or [MSN] [3].
527
528  [1]: http://google.com/        "Google"
529  [2]: http://search.yahoo.com/  "Yahoo Search"
530  [3]: http://search.msn.com/    "MSN Search"
531</code></pre>
532<p>Using the implicit link name shortcut, you could instead write:</p>
533<pre><code>I get 10 times more traffic from [Google][] than from
534[Yahoo][] or [MSN][].
535
536  [google]: http://google.com/        "Google"
537  [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
538  [msn]:    http://search.msn.com/    "MSN Search"
539</code></pre>
540<p>Both of the above examples will produce the following HTML output:</p>
541<pre><code>&lt;p&gt;I get 10 times more traffic from &lt;a href="http://google.com/"
542title="Google"&gt;Google&lt;/a&gt; than from
543&lt;a href="http://search.yahoo.com/" title="Yahoo Search"&gt;Yahoo&lt;/a&gt;
544or &lt;a href="http://search.msn.com/" title="MSN Search"&gt;MSN&lt;/a&gt;.&lt;/p&gt;
545</code></pre>
546<p>For comparison, here is the same paragraph written using
547Markdown's inline link style:</p>
548<pre><code>I get 10 times more traffic from [Google](http://google.com/ "Google")
549than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
550[MSN](http://search.msn.com/ "MSN Search").
551</code></pre>
552<p>The point of reference-style links is not that they're easier to
553write. The point is that with reference-style links, your document
554source is vastly more readable. Compare the above examples: using
555reference-style links, the paragraph itself is only 81 characters
556long; with inline-style links, it's 176 characters; and as raw HTML,
557it's 234 characters. In the raw HTML, there's more markup than there
558is text.</p>
559<p>With Markdown's reference-style links, a source document much more
560closely resembles the final output, as rendered in a browser. By
561allowing you to move the markup-related metadata out of the paragraph,
562you can add links without interrupting the narrative flow of your
563prose.</p>
564<h3 id="em">Emphasis</h3>
565<p>Markdown treats asterisks (<code>*</code>) and underscores (<code>_</code>) as indicators of
566emphasis. Text wrapped with one <code>*</code> or <code>_</code> will be wrapped with an
567HTML <code>&lt;em&gt;</code> tag; double <code>*</code>'s or <code>_</code>'s will be wrapped with an HTML
568<code>&lt;strong&gt;</code> tag. E.g., this input:</p>
569<pre><code>*single asterisks*
570
571_single underscores_
572
573**double asterisks**
574
575__double underscores__
576</code></pre>
577<p>will produce:</p>
578<pre><code>&lt;em&gt;single asterisks&lt;/em&gt;
579
580&lt;em&gt;single underscores&lt;/em&gt;
581
582&lt;strong&gt;double asterisks&lt;/strong&gt;
583
584&lt;strong&gt;double underscores&lt;/strong&gt;
585</code></pre>
586<p>You can use whichever style you prefer; the lone restriction is that
587the same character must be used to open and close an emphasis span.</p>
588<p>Emphasis can be used in the middle of a word:</p>
589<pre><code>un*frigging*believable
590</code></pre>
591<p>But if you surround an <code>*</code> or <code>_</code> with spaces, it'll be treated as a
592literal asterisk or underscore.</p>
593<p>To produce a literal asterisk or underscore at a position where it
594would otherwise be used as an emphasis delimiter, you can backslash
595escape it:</p>
596<pre><code>\*this text is surrounded by literal asterisks\*
597</code></pre>
598<h3 id="code">Code</h3>
599<p>To indicate a span of code, wrap it with backtick quotes (<code>`</code>).
600Unlike a pre-formatted code block, a code span indicates code within a
601normal paragraph. For example:</p>
602<pre><code>Use the `printf()` function.
603</code></pre>
604<p>will produce:</p>
605<pre><code>&lt;p&gt;Use the &lt;code&gt;printf()&lt;/code&gt; function.&lt;/p&gt;
606</code></pre>
607<p>To include a literal backtick character within a code span, you can use
608multiple backticks as the opening and closing delimiters:</p>
609<pre><code>``There is a literal backtick (`) here.``
610</code></pre>
611<p>which will produce this:</p>
612<pre><code>&lt;p&gt;&lt;code&gt;There is a literal backtick (`) here.&lt;/code&gt;&lt;/p&gt;
613</code></pre>
614<p>The backtick delimiters surrounding a code span may include spaces --
615one after the opening, one before the closing. This allows you to place
616literal backtick characters at the beginning or end of a code span:</p>
617<pre><code>A single backtick in a code span: `` ` ``
618
619A backtick-delimited string in a code span: `` `foo` ``
620</code></pre>
621<p>will produce:</p>
622<pre><code>&lt;p&gt;A single backtick in a code span: &lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
623
624&lt;p&gt;A backtick-delimited string in a code span: &lt;code&gt;`foo`&lt;/code&gt;&lt;/p&gt;
625</code></pre>
626<p>With a code span, ampersands and angle brackets are encoded as HTML
627entities automatically, which makes it easy to include example HTML
628tags. Markdown will turn this:</p>
629<pre><code>Please don't use any `&lt;blink&gt;` tags.
630</code></pre>
631<p>into:</p>
632<pre><code>&lt;p&gt;Please don't use any &lt;code&gt;&amp;lt;blink&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;
633</code></pre>
634<p>You can write this:</p>
635<pre><code>`&amp;#8212;` is the decimal-encoded equivalent of `&amp;mdash;`.
636</code></pre>
637<p>to produce:</p>
638<pre><code>&lt;p&gt;&lt;code&gt;&amp;amp;#8212;&lt;/code&gt; is the decimal-encoded
639equivalent of &lt;code&gt;&amp;amp;mdash;&lt;/code&gt;.&lt;/p&gt;
640</code></pre>
641<h3 id="img">Images</h3>
642<p>Admittedly, it's fairly difficult to devise a "natural" syntax for
643placing images into a plain text document format.</p>
644<p>Markdown uses an image syntax that is intended to resemble the syntax
645for links, allowing for two styles: <em>inline</em> and <em>reference</em>.</p>
646<p>Inline image syntax looks like this:</p>
647<pre><code>![Alt text](/path/to/img.jpg)
648
649![Alt text](/path/to/img.jpg "Optional title")
650</code></pre>
651<p>That is:</p>
652<ul>
653<li>An exclamation mark: <code>!</code>;</li>
654<li>followed by a set of square brackets, containing the <code>alt</code>
655attribute text for the image;</li>
656<li>followed by a set of parentheses, containing the URL or path to
657the image, and an optional <code>title</code> attribute enclosed in double
658or single quotes.</li>
659</ul>
660<p>Reference-style image syntax looks like this:</p>
661<pre><code>![Alt text][id]
662</code></pre>
663<p>Where "id" is the name of a defined image reference. Image references
664are defined using syntax identical to link references:</p>
665<pre><code>[id]: url/to/image  "Optional title attribute"
666</code></pre>
667<p>As of this writing, Markdown has no syntax for specifying the
668dimensions of an image; if this is important to you, you can simply
669use regular HTML <code>&lt;img&gt;</code> tags.</p>
670<hr />
671<h2 id="misc">Miscellaneous</h2>
672<h3 id="autolink">Automatic Links</h3>
673<p>Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:</p>
674<pre><code>&lt;http://example.com/&gt;
675</code></pre>
676<p>Markdown will turn this into:</p>
677<pre><code>&lt;a href="http://example.com/"&gt;http://example.com/&lt;/a&gt;
678</code></pre>
679<p>Automatic links for email addresses work similarly, except that
680Markdown will also perform a bit of randomized decimal and hex
681entity-encoding to help obscure your address from address-harvesting
682spambots. For example, Markdown will turn this:</p>
683<pre><code>&lt;address@example.com&gt;
684</code></pre>
685<p>into something like this:</p>
686<pre><code>&lt;a href="&amp;#x6D;&amp;#x61;i&amp;#x6C;&amp;#x74;&amp;#x6F;:&amp;#x61;&amp;#x64;&amp;#x64;&amp;#x72;&amp;#x65;
687&amp;#115;&amp;#115;&amp;#64;&amp;#101;&amp;#120;&amp;#x61;&amp;#109;&amp;#x70;&amp;#x6C;e&amp;#x2E;&amp;#99;&amp;#111;
688&amp;#109;"&gt;&amp;#x61;&amp;#x64;&amp;#x64;&amp;#x72;&amp;#x65;&amp;#115;&amp;#115;&amp;#64;&amp;#101;&amp;#120;&amp;#x61;
689&amp;#109;&amp;#x70;&amp;#x6C;e&amp;#x2E;&amp;#99;&amp;#111;&amp;#109;&lt;/a&gt;
690</code></pre>
691<p>which will render in a browser as a clickable link to "address@example.com".</p>
692<p>(This sort of entity-encoding trick will indeed fool many, if not
693most, address-harvesting bots, but it definitely won't fool all of
694them. It's better than nothing, but an address published in this way
695will probably eventually start receiving spam.)</p>
696<h3 id="backslash">Backslash Escapes</h3>
697<p>Markdown allows you to use backslash escapes to generate literal
698characters which would otherwise have special meaning in Markdown's
699formatting syntax. For example, if you wanted to surround a word
700with literal asterisks (instead of an HTML <code>&lt;em&gt;</code> tag), you can use
701backslashes before the asterisks, like this:</p>
702<pre><code>\*literal asterisks\*
703</code></pre>
704<p>Markdown provides backslash escapes for the following characters:</p>
705<pre><code>\	backslash
706`	backtick
707*	asterisk
708_	underscore
709{}	curly braces
710[]	square brackets
711()	parentheses
712#	hash mark
713+	plus sign
714-	minus sign (hyphen)
715.	dot
716!	exclamation mark
717</code></pre>
718