Markdown.pl: allow documented single-quote ref titles
[markdown.git] / syntax.md
blob48ae4bb77d87013e3564bccd57fbc9735b082613
1 ================
2 Markdown: Syntax
3 ================
5 * [Markdown Basics]
6 * _[Syntax]( "Markdown Syntax Documentation")_
7 * [License]
9 - - - - -
11 *   [Overview]
12     *   [Philosophy]
13     *   [Inline HTML]
14     *   [Automatic Escaping for Special Characters]
15 *   [Block Elements]
16     *   [Paragraphs and Line Breaks]
17     *   [Headers]
18     *   [Blockquotes]
19     *   [Lists]
20     *   [Tables]
21     *   [Style Sheet]
22     *   [Code Blocks]
23     *   [Horizontal Rules]
24 *   [Span Elements]
25     *   [Links]
26     *   [Emphasis]
27     *   [Code]
28     *   [Images]
29 *   [Miscellaneous]
30     *   [Backslash Escapes]
31     *   [Automatic Links]
34 **Note:** This document is itself written using Markdown; you
35 can [see the source for it by adding `.md` to the URL][src].
37   [markdown basics]: basics.html  "Markdown Basics"
38   [license]: license.html "License Information"
39   [src]: syntax.md
41 - - - - -
43 --------
44 Overview
45 --------
47 ~~~~~~~~~~
48 Philosophy
49 ~~~~~~~~~~
51 Markdown is intended to be as easy-to-read and easy-to-write as is feasible.
53 Readability, however, is emphasized above all else. A Markdown-formatted
54 document should be publishable as-is, as plain text, without looking
55 like it's been marked up with tags or formatting instructions. While
56 Markdown's syntax has been influenced by several existing text-to-HTML
57 filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4],
58 [Grutatext] [5], and [EtText] [6] -- the single biggest source of
59 inspiration for Markdown's syntax is the format of plain text email.
61   [1]: http://docutils.sourceforge.net/mirror/setext.html
62   [2]: http://www.aaronsw.com/2002/atx/
63   [3]: http://textism.com/tools/textile/
64   [4]: http://docutils.sourceforge.net/rst.html
65   [5]: http://www.triptico.com/software/grutatxt.html
66   [6]: http://ettext.taint.org/doc/
68 To this end, Markdown's syntax is comprised entirely of punctuation
69 characters, which punctuation characters have been carefully chosen so
70 as to look like what they mean. E.g., asterisks around a word actually
71 look like \*emphasis\*. Markdown lists look like, well, lists. Even
72 blockquotes look like quoted passages of text, assuming you've ever
73 used email.
76 ~~~~~~~~~~~
77 Inline HTML
78 ~~~~~~~~~~~
80 Markdown's syntax is intended for one purpose: to be used as a
81 format for *writing* for the web.
83 Markdown is not a replacement for HTML, or even close to it. Its
84 syntax is very small, corresponding only to a very small subset of
85 HTML tags. The idea is *not* to create a syntax that makes it easier
86 to insert HTML tags. In my opinion, HTML tags are already easy to
87 insert. The idea for Markdown is to make it easy to read, write, and
88 edit prose. HTML is a *publishing* format; Markdown is a *writing*
89 format. Thus, Markdown's formatting syntax only addresses issues that
90 can be conveyed in plain text.
92 For any markup that is not covered by Markdown's syntax, you simply
93 use HTML itself. There's no need to preface it or delimit it to
94 indicate that you're switching from Markdown to HTML; you just use
95 the tags.
97 The only restrictions are that block-level HTML elements -- e.g. `<div>`,
98 `<table>`, `<pre>`, `<p>`, etc. -- must be separated from surrounding
99 content by blank lines, and the start and end tags of the block should
100 not be indented with tabs or spaces. Markdown is smart enough not
101 to add extra (unwanted) `<p>` tags around HTML block-level tags.
103 For example, to add an HTML table to a Markdown article:
105       This is a regular paragraph.
107       <table>
108           <tr>
109               <td>Foo</td>
110           </tr>
111       </table>
113       This is another regular paragraph.
115 Note that Markdown formatting syntax is not processed within block-level
116 HTML tags. E.g., you can't use Markdown-style `*emphasis*` inside an
117 HTML block.
119 Span-level HTML tags -- e.g. `<span>`, `<cite>`, or `<del>` -- can be
120 used anywhere in a Markdown paragraph, list item, or header. If you
121 want, you can even use HTML tags instead of Markdown formatting; e.g. if
122 you'd prefer to use HTML `<a>` or `<img>` tags instead of Markdown's
123 link or image syntax, go right ahead.
125 Unlike block-level HTML tags, Markdown syntax *is* processed within
126 span-level tags.
128 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129 Automatic Escaping for Special Characters
130 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132 In HTML, there are two characters that demand special treatment: `<`
133 and `&`. Left angle brackets are used to start tags; ampersands are
134 used to denote HTML entities. If you want to use them as literal
135 characters, you must escape them as entities, e.g. `&lt;`, and
136 `&amp;`.
138 Ampersands in particular are bedeviling for web writers. If you want to
139 write about 'AT&T', you need to write '`AT&amp;T`'. You even need to
140 escape ampersands within URLs. Thus, if you want to link to:
142       http://images.google.com/images?num=30&q=larry+bird
144 you need to encode the URL as:
146       http://images.google.com/images?num=30&amp;q=larry+bird
148 in your anchor tag `href` attribute. Needless to say, this is easy to
149 forget, and is probably the single most common source of HTML validation
150 errors in otherwise well-marked-up web sites.
152 Markdown allows you to use these characters naturally, taking care of
153 all the necessary escaping for you. If you use an ampersand as part of
154 an HTML entity, it remains unchanged; otherwise it will be translated
155 into `&amp;`.
157 So, if you want to include a copyright symbol in your article, you can write:
159       &copy;
161 and Markdown will leave it alone. But if you write:
163       AT&T
165 Markdown will translate it to:
167       AT&amp;T
169 Similarly, because Markdown supports [inline HTML](#html), if you use
170 angle brackets as delimiters for HTML tags, Markdown will treat them as
171 such. But if you write:
173       4 < 5
175 Markdown will translate it to:
177       4 &lt; 5
179 However, inside Markdown code spans and blocks, angle brackets and
180 ampersands are *always* encoded automatically. This makes it easy to use
181 Markdown to write about HTML code. (As opposed to raw HTML, which is a
182 terrible format for writing about HTML syntax, because every single `<`
183 and `&` in your example code needs to be escaped.)
186 - - - - -
188 --------------
189 Block Elements
190 --------------
192 ~~~~~~~~~~~~~~~~~~~~~~~~~~
193 Paragraphs and Line Breaks
194 ~~~~~~~~~~~~~~~~~~~~~~~~~~
196 A paragraph is simply one or more consecutive lines of text, separated
197 by one or more blank lines.  (A blank line is any line that looks like a
198 blank line -- a line containing nothing but spaces or tabs is considered
199 blank.)  Normal paragraphs should not be indented with spaces or tabs.
200 Note that Markdown expands all tabs to spaces before doing anything else.
202 The implication of the "one or more consecutive lines of text" rule is
203 that Markdown supports "hard-wrapped" text paragraphs. This differs
204 significantly from most other text-to-HTML formatters (including Movable
205 Type's "Convert Line Breaks" option) which translate every line break
206 character in a paragraph into a `<br />` tag.
208 When you *do* want to insert a `<br />` break tag using Markdown, you
209 end a line with two or more spaces, then type return.
211 Yes, this takes a tad more effort to create a `<br />`, but a simplistic
212 "every line break is a `<br />`" rule wouldn't work for Markdown.
213 Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l]
214 work best -- and look better -- when you format them with hard breaks.
216   [bq]: #blockquote
217   [l]:  #list
220 ~~~~~~~
221 Headers
222 ~~~~~~~
224 Markdown supports two styles of headers, [Setext] [1] and [atx] [2].
226 Setext-style headers are "underlined" using equal signs (for first-level
227 headers), dashes (for second-level headers) and tildes (for third-level
228 headers). For example:
230       This is an H1
231       =============
233       This is an H2
234       -------------
236       This is an H3
237       ~~~~~~~~~~~~~
239 Any number of underlining `=`'s, `-`'s or `~`'s will work.  An optional
240 matching "overline" may precede the header like so:
242       =============
243       This is an H1
244       =============
246       -------------
247       This is an H2
248       -------------
250       ~~~~~~~~~~~~~
251       This is an H3
252       ~~~~~~~~~~~~~
254 Atx-style headers use 1-6 hash characters at the start of the line,
255 corresponding to header levels 1-6. For example:
257       # This is an H1
259       ## This is an H2
261       ###### This is an H6
263 Optionally, you may "close" atx-style headers. This is purely
264 cosmetic -- you can use this if you think it looks better. The
265 closing hashes don't even need to match the number of hashes
266 used to open the header. (The number of opening hashes
267 determines the header level.) :
269       # This is an H1 #
271       ## This is an H2 ##
273       ### This is an H3 ######
276 ~~~~~~~~~~~
277 Blockquotes
278 ~~~~~~~~~~~
280 Markdown uses email-style `>` characters for blockquoting. If you're
281 familiar with quoting passages of text in an email message, then you
282 know how to create a blockquote in Markdown. It looks best if you hard
283 wrap the text and put a `>` before every line:
285       > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
286       > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
287       > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
288       >
289       > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
290       > id sem consectetuer libero luctus adipiscing.
292 Markdown allows you to be lazy and only put the `>` before the first
293 line of a hard-wrapped paragraph:
295       > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
296       consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
297       Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
299       > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
300       id sem consectetuer libero luctus adipiscing.
302 Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
303 adding additional levels of `>`:
305       > This is the first level of quoting.
306       >
307       > > This is nested blockquote.
308       >
309       > Back to the first level.
311 Blockquotes can contain other Markdown elements, including headers, lists,
312 and code blocks:
314       > ## This is a header.
315       >
316       > 1.  This is the first list item.
317       > 2.  This is the second list item.
318       >
319       > Here's some example code:
320       >
321       >     return shell_exec("echo $input | $markdown_script");
323 Any decent text editor should make email-style quoting easy. For
324 example, with BBEdit, you can make a selection and choose Increase
325 Quote Level from the Text menu.
328 ~~~~~
329 Lists
330 ~~~~~
332 Markdown supports ordered (numbered, lettered or roman numeraled)
333 and unordered (bulleted) lists.
335 Unordered lists use asterisks, pluses, and hyphens -- interchangably
336 -- as list markers:
338       *   Red
339       *   Green
340       *   Blue
342 is equivalent to:
344       +   Red
345       +   Green
346       +   Blue
348 and:
350       -   Red
351       -   Green
352       -   Blue
354 Ordered lists use numbers or letters (latin or greek) or roman numerals
355 followed by a period or right parenthesis `)`:
357       1.  Bird
358       2.  McHale
359       3.  Parish
361 It's important to note that the actual numbers (or letters or roman
362 numerals) you use to mark the list *do* have an effect on the HTML
363 output Markdown produces, but only if you skip ahead and/or change
364 the list marker style.
366 The HTML Markdown produces from the above list is:
368       <ol>
369       <li>Bird</li>
370       <li>McHale</li>
371       <li>Parish</li>
372       </ol>
374 If you instead wrote the list in Markdown like this:
376       1.  Bird
377       1.  McHale
378       1.  Parish
380 or even:
382       3. Bird
383       1. McHale
384       8. Parish
386 you'd get the exact same HTML output in the first case, but in the
387 second case the numbers would be in the sequence 3, 4 and 8 because
388 you are only allowed to skip ahead (and the first item in the list
389 must be numbered at least 0 [or `a`, `i`, etc.]).
391 The point is, if you want to, you can use ordinal numbers in your
392 ordered Markdown lists, so that the numbers in your source match the
393 numbers in your published HTML.  But if you want to be lazy, you don't
394 have to.
396 The style of the list marker is determined by the first list item.
397 If the first list item uses numbers the list style will be `decimal`.
398 If the first list item uses a roman numeral then the list style will
399 be either `lower-roman` or `upper-roman` depending on the case used.
400 Similarly for any non-roman letter you get `lower-alpha`, `upper-alpha`
401 or `lower-greek`.
403 However, if later list items change the style, an attempt is made to
404 modify the list numbering style for that item which should be effective
405 in just about any browser available today.
407 Similarly if a list item "skips ahead" an attempt is made to skip the
408 list number ahead which again should be effective in just about any
409 browser available today.
411 A right parenthesis ')' may be used in place of the `.` for any of the
412 numbering styles but it requires the [style sheet] to be included or
413 you will end up just seeing `.` instead.  For example this list:
415       a)  Alpha
416       b)  Beta
417       c)  Gamma
419 will end up being displayed like this without the [style sheet]:
421       a.  Alpha
422       b.  Beta
423       c.  Gamma
425 If you do use lazy list numbering, however, you should still start the
426 list with the number 1 (or letter A or a or roman numeral I or i) or even
427 a higher number if desired and then stick with that number (or letter) for
428 the rest of the items.  Since you may only skip forward in the numbering,
429 the items will end up numbered (or "lettered") starting with the value
430 used for the first item.
432 List markers typically start at the left margin, but may be indented by
433 up to three spaces.  List markers must be followed by one or more spaces.
435 Attempts to change an unordered list's style or switch from an ordered
436 list to an unordered list (or vice versa) in mid-list are ignored.
438 Lists end when the first non-blank, non-indented line (relative to the
439 current list nesting level) is encountered that does not begin with a
440 list marker.
442 To create two distinct lists when there are only blank lines between the
443 end of the first list and the start of the second, a separator line must
444 be inserted.  ([Horizontal rules] work just fine for this).
446 If desired, an HTML-style comment (e.g. `<!-- -->`) may be used for this
447 purpose provided it is preceded and followed by at least one blank line.
449 Any non-list-marker, non-blank, non-indented (relative to the current
450 list nesting level) line may be used for this purpose but the HTML-style
451 comment has the advantage of not causing anything extra to be shown when
452 the HTML output is displayed in a browser.
454 To make lists look nice, you can wrap items with hanging indents:
456       *   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
457           Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
458           viverra nec, fringilla in, laoreet vitae, risus.
459       *   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
460           Suspendisse id sem consectetuer libero luctus adipiscing.
462 But if you want to be lazy, you don't have to:
464       *   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
465       Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
466       viverra nec, fringilla in, laoreet vitae, risus.
467       *   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
468       Suspendisse id sem consectetuer libero luctus adipiscing.
470 If list items are separated by blank lines, Markdown will wrap the
471 items in `<p>` tags in the HTML output. For example, this input:
473       *   Bird
474       *   Magic
476 will turn into:
478       <ul>
479       <li>Bird</li>
480       <li>Magic</li>
481       </ul>
483 But this:
485       *   Bird
487       *   Magic
489 will turn into:
491       <ul>
492       <li><p>Bird</p></li>
493       <li><p>Magic</p></li>
494       </ul>
496 List items may consist of multiple paragraphs. Each subsequent
497 paragraph in a list item must be indented by 4 spaces:
499       1.  This is a list item with two paragraphs. Lorem ipsum dolor
500           sit amet, consectetuer adipiscing elit. Aliquam hendrerit
501           mi posuere lectus.
503           Vestibulum enim wisi, viverra nec, fringilla in, laoreet
504           vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
505           sit amet velit.
507       2.  Suspendisse id sem consectetuer libero luctus adipiscing.
509 It looks nice if you indent every line of the subsequent
510 paragraphs, but here again, Markdown will allow you to be
511 lazy:
513       *   This is a list item with two paragraphs.
515           This is the second paragraph in the list item. You're
516       only required to indent the first line. Lorem ipsum dolor
517       sit amet, consectetuer adipiscing elit.
519       *   Another item in the same list.
521 To put a blockquote within a list item, the blockquote's `>`
522 delimiters need to be indented:
524       *   A list item with a blockquote:
526           > This is a blockquote
527           > inside a list item.
529 To put a code block within a list item, the code block needs
530 to be indented *twice* (in other words 8 spaces):
532       *   A list item with a code block:
534               <code goes here>
537 It's worth noting that it's possible to trigger an ordered list by
538 accident, by writing something like this:
540       1986. What a great season.
542 In other words, a *number-period-space* sequence at the beginning of a
543 line. To avoid this, you can backslash-escape the period:
545       1986\. What a great season.
547 Markdown tries to be smart about this and requires either a blank line
548 before something that looks like a list item or requires that a list
549 definition is already active or requires that two lines in a row look
550 like list items in order for Markdown to recognize a list item.
552 So the above, by itself without the escaped ".", will not start a list
553 when it's outside of any list unless it's preceded by a blank line or
554 immediately followed by another line that looks like a list item (either
555 of the same kind or of a sublist).
558 ~~~~~~
559 Tables
560 ~~~~~~
562 Markdown supports simple tables like so:
564     | Item | Price | Description |
565     | ---- | -----:| ----------- |
566     | Nut  | $1.29 | Delicious   |
567     | Bean | $0.37 | Fiber       |
569 Output:
571     <table>
572       <tr><th>Item</th><th align="right">Price</th><th>Description</th></tr>
573       <tr><td>Nut</td><td align="right">$1.29</td><td>Delicious</td></tr>
574       <tr><td>Bean</td><td align="right">$0.37</td><td>Fiber</td></tr>
575     </table>
577 The leading and trailing `|` on each line are optional unless there is only
578 a single column in which case at least one `|` is always required -- two if
579 the single column contains only whitespace.
581 Leading and trailing whitespace are always trimmed from each column's value
582 before using it.
584 To include a literal `|` (veritical bar) character in a column's value, precede
585 it with a `\` (backslash).  To include a literal `\` use `\\` (double them).
587 The number of columns in the separator row must match exactly the number of
588 columns in the header row in order for the table to be recognized.
590 Each separator in the separator line must be one or more `-` (dash) characters
591 optionally with a `:` (colon) on either or both ends.  With no colons the
592 column alignment will be the default.  With a colon only on the left the
593 alignment will be `left`.  With a colon only on the right the alignment will
594 be `right`.  And finally, with a colon on both ends the alignment will be
595 `center`.  The alignment will be applied to the column in both header and body
596 rows.
598 Body rows that contain fewer columns than the header row have empty columns
599 added.  Body rows that contain more columns than the header row have the
600 extra columns dropped.
602 The vertical bars do not need to be lined up, sloppy tables work just fine.
603 The above example could be rewritten like so:
605     Item|Price|Description
606     -|-:|-
607     Nut|$1.29|Delicious
608     Bean|$0.37|Fiber
610 Inline markup is recognized just fine within each column:
612     |Example
613     |:-
614     |~~Strikeout~~ `code` _etc._
617 ~~~~~~~~~~~
618 Style Sheet
619 ~~~~~~~~~~~
621 If an unordered list item begins with `[ ]` or `[x]` then its bullet will
622 be suppressed and a nice checkbox shown instead.  In order for the fancy
623 checkboxes to show the markdown style sheet must be included.
625 It may be included in the output with the `--show-stylesheet` option.
626 To get just the style sheet, run `Markdown.pl` with no arguments with the
627 input redirected to `/dev/null`.  Without the style sheet these items
628 will show normally (i.e. with a bullet and as `[ ]` or `[x]`).
630 Ordered lists that make use of a `)` instead of a `.` to terminate the
631 marker also require the style sheet otherwise they will display with
632 the normal `.` marker termination.
635 ~~~~~~~~~~~
636 Code Blocks
637 ~~~~~~~~~~~
639 Pre-formatted code blocks are used for writing about programming or
640 markup source code. Rather than forming normal paragraphs, the lines
641 of a code block are interpreted literally. Markdown wraps a code block
642 in both `<pre>` and `<code>` tags.
644 To produce a code block in Markdown, simply indent every line of the
645 block by at least 4 spaces.  Alternatively precede the block with a
646 line consisting of 3 backtick quotes (or more) and follow it with a
647 line consisting of the same number of backtick quotes -- in this case the
648 code lines themselves do not require any additional indentation.
649 For example, given this input:
651       This is a normal paragraph:
653           This is a code block.
655 Or this equivalent input:
657       This is a normal paragraph.
659       ```
660       This is a code block.
661       ```
663 Markdown will generate:
665       <p>This is a normal paragraph:</p>
667       <pre><code>This is a code block.
668       </code></pre>
670 Note that when using the 3 backtick quotes technique, the blank line
671 before the start of the code block is optional. One level of
672 indentation -- 4 spaces -- is removed from each line of the code block
673 unless the 3 backtick quotes are used.  For example, this:
675       Here is an example of AppleScript:
677           tell application "Foo"
678               beep
679           end tell
681 will turn into:
683       <p>Here is an example of AppleScript:</p>
685       <pre><code>tell application "Foo"
686           beep
687       end tell
688       </code></pre>
690 A code block continues until it reaches a line that is not indented
691 (or the end of the article) when using the indentation technique or
692 until a line consisting of the same number of backtick quotes is found
693 when using the 3 backtick quotes technique.
695 Note that the 3 backtick quotes (or more) must appear at the beginning
696 of the line.  To include a code block within a list (or other indented
697 element), the indentation technique must be used.
699 Also note that within a backticks-delimited code block, tab characters
700 are always expanded with the tab stop locations 8 characters apart.
702 Within a code block, ampersands (`&`) and angle brackets (`<` and `>`)
703 are automatically converted into HTML entities. This makes it very
704 easy to include example HTML source code using Markdown -- just paste
705 it and indent it, and Markdown will handle the hassle of encoding the
706 ampersands and angle brackets. For example, this:
708       <div class="footer">
709           &copy; 2004 Foo Corporation
710       </div>
712 will turn into:
714       <pre><code>&lt;div class="footer"&gt;
715           &amp;copy; 2004 Foo Corporation
716       &lt;/div&gt;
717       </code></pre>
719 Regular Markdown syntax is not processed within code blocks. E.g.,
720 asterisks are just literal asterisks within a code block. This means
721 it's also easy to use Markdown to write about Markdown's own syntax.
724 ~~~~~~~~~~~~~~~~
725 Horizontal Rules
726 ~~~~~~~~~~~~~~~~
728 You can produce a horizontal rule tag (`<hr />`) by placing three or
729 more hyphens, asterisks, or underscores on a line by themselves. If you
730 wish, you may use spaces between the hyphens or asterisks. Each of the
731 following lines will produce a horizontal rule:
733       * * *
735       ***
737       *****
739       - - -
741       ---------------------------------------
744 - - - - -
747 -------------
748 Span Elements
749 -------------
751 ~~~~~
752 Links
753 ~~~~~
755 Markdown supports two style of links: *inline* and *reference*.
757 In both styles, the link text is delimited by [square brackets].
759 To create an inline link, use a set of regular parentheses immediately
760 after the link text's closing square bracket. Inside the parentheses,
761 put the URL where you want the link to point, along with an *optional*
762 title for the link, surrounded in quotes. For example:
764       This is [an example](http://example.com/ "Title") inline link.
766       [This link](http://example.net/) has no title attribute.
768 Will produce:
770       <p>This is <a href="http://example.com/" title="Title">
771       an example</a> inline link.</p>
773       <p><a href="http://example.net/">This link</a> has no
774       title attribute.</p>
776 If you're referring to a local resource on the same server, you can
777 use relative paths:
779       See my [About](/about/) page for details.
781 Reference-style links use a second set of square brackets, inside
782 which you place a label of your choosing to identify the link:
784       This is [an example][id] reference-style link.
786 You can optionally use a space to separate the sets of brackets:
788       This is [an example] [id] reference-style link.
790 Then, anywhere in the document, you define your link label like this,
791 on a line by itself:
793       [id]: http://example.com/  "Optional Title Here"
795 That is:
797 *   Square brackets containing the link identifier (optionally
798     indented from the left margin using up to three spaces);
799 *   followed by a colon;
800 *   followed by one or more spaces (or tabs);
801 *   followed by the URL for the link;
802 *   optionally followed by a title attribute for the link, enclosed
803     in double or single quotes, or enclosed in parentheses.
805 The following three link definitions are equivalent:
807       [foo]: http://example.com/  "Optional Title Here"
808       [foo]: http://example.com/  'Optional Title Here'
809       [foo]: http://example.com/  (Optional Title Here)
811 **Note:** There is a known bug in Markdown.pl 1.0.3 which prevents
812 single quotes from being used to delimit link titles.
814 The link URL may, optionally, be surrounded by angle brackets:
816       [id]: <http://example.com/>  "Optional Title Here"
818 You can put the title attribute on the next line and use extra spaces
819 or tabs for padding, which tends to look better with longer URLs:
821       [id]: http://example.com/longish/path/to/resource/here
822             "Optional Title Here"
824 Link definitions are only used for creating links during Markdown
825 processing, and are stripped from your document in the HTML output.
827 Link definition names may consist of letters, numbers, spaces, and
828 punctuation -- but they are *not* case sensitive. E.g. these two
829 links:
831       [link text][a]
832       [link text][A]
834 are equivalent.
836 The *implicit link name* shortcut allows you to omit the name of the
837 link, in which case the link text itself is used as the name.
838 Just use an empty set of square brackets (or none) -- e.g., to link the
839 word "Google" to the google.com web site, you could simply write:
841       [Google][]
843 Or even just this:
845       [Google]
847 And then define the link:
849       [Google]: http://google.com/
851 Because link names may contain spaces, this shortcut even works for
852 multiple words in the link text:
854       Visit [Daring Fireball] for more information.
856 And then define the link:
858       [Daring Fireball]: http://daringfireball.net/
860 Text inside square brackets is left completely unchanged (including the
861 surrounding brackets) _unless_ it matches a link definition.  Furthermore,
862 the single pair of surrounding square brackets case is always checked
863 for last so you may only omit the trailing `[]` of an *implicit link name*
864 shortcut when the result would still be unambiguous.
866 Link definitions can be placed anywhere in your Markdown document. I
867 tend to put them immediately after each paragraph in which they're
868 used, but if you want, you can put them all at the end of your
869 document, sort of like footnotes.
871 All first, second and third level headers defined at the top-level
872 (in other words they are not in lists and start at the left margin)
873 using either the setext-style or atx-style automatically have an
874 anchor id and link definition added for them provided there is not
875 already a previous definition with the same id.  You can use this
876 to place a table-of-contents at the top of the document that links
877 to subsections later in the document.  Just like this document.
879 For example, all six of these links point to subsections later in
880 the same document:
882       * Self Same
883         * [Introduction]
884         * [Part Two]
885         * [Part Three]
886       * Different
887         * [Introduction](#Part-Two)
888         * [Part Two](#Part_Three)
889         * [Part Three](#introduction)
891       ## Introduction
893       ## Part Two
895       ## Part Three
897 Here's an example of reference links in action:
899       I get 10 times more traffic from [Google] [1] than from
900       [Yahoo] [2] or [MSN] [3].
902       [1]: http://google.com/        "Google"
903       [2]: http://search.yahoo.com/  "Yahoo Search"
904       [3]: http://search.msn.com/    "MSN Search"
906 Using the implicit link name shortcut, you could instead write:
908       I get 10 times more traffic from [Google] than from
909       [Yahoo] or [MSN].
911       [google]: http://google.com/        "Google"
912       [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
913       [msn]:    http://search.msn.com/    "MSN Search"
915 Both of the above examples will produce the following HTML output:
917       <p>I get 10 times more traffic from <a href="http://google.com/"
918       title="Google">Google</a> than from
919       <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
920       or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
922 For comparison, here is the same paragraph written using
923 Markdown's inline link style:
925       I get 10 times more traffic from [Google](http://google.com/ "Google")
926       than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
927       [MSN](http://search.msn.com/ "MSN Search").
929 The point of reference-style links is not that they're easier to
930 write. The point is that with reference-style links, your document
931 source is vastly more readable. Compare the above examples: using
932 reference-style links, the paragraph itself is only 81 characters
933 long; with inline-style links, it's 176 characters; and as raw HTML,
934 it's 234 characters. In the raw HTML, there's more markup than there
935 is text.
937 With Markdown's reference-style links, a source document much more
938 closely resembles the final output, as rendered in a browser. By
939 allowing you to move the markup-related metadata out of the paragraph,
940 you can add links without interrupting the narrative flow of your
941 prose.
944 ~~~~~~~~
945 Emphasis
946 ~~~~~~~~
948 Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
949 emphasis. Text wrapped with one `*` or `_` will be wrapped with an
950 HTML `<em>` tag; double `*`'s or `_`'s will be wrapped with an HTML
951 `<strong>` tag. Double `~`'s will be wrapped with an HTML `<strike>` tag.
952 E.g., this input:
954       *single asterisks*
956       _single underscores_
958       **double asterisks**
960       __double underscores__
962       ~~double tildes~~
964 will produce:
966       <em>single asterisks</em>
968       <em>single underscores</em>
970       <strong>double asterisks</strong>
972       <strong>double underscores</strong>
974       <strike>strike through</strike>
976 You can use whichever style you prefer; the lone restriction is that
977 the same character must be used to open and close an emphasis span.
978 Additionally `_` and double `_` are not recognized within words.
980 Emphasis using `*`'s or `~`'s can be used in the middle of a word:
982       un*frigging*believable fan~~frigging~~tastic
984 But if you surround an `*`, `_` or `~` with spaces, it'll be treated as a
985 literal asterisk, underscore or tilde.
987 To produce a literal asterisk, underscore or tilde at a position where it
988 would otherwise be used as an emphasis delimiter, you can backslash
989 escape it:
991       \*this text is surrounded by literal asterisks\*
994 ~~~~
995 Code
996 ~~~~
998 To indicate a span of code, wrap it with backtick quotes (`` ` ``).
999 Unlike a pre-formatted code block, a code span indicates code within a
1000 normal paragraph. For example:
1002       Use the `printf()` function.
1004 will produce:
1006       <p>Use the <code>printf()</code> function.</p>
1008 To include a literal backtick character within a code span, you can use
1009 multiple backticks as the opening and closing delimiters:
1011       ``There is a literal backtick (`) here.``
1013 which will produce this:
1015       <p><code>There is a literal backtick (`) here.</code></p>
1017 The backtick delimiters surrounding a code span may include spaces --
1018 one after the opening, one before the closing. This allows you to place
1019 literal backtick characters at the beginning or end of a code span:
1021       A single backtick in a code span: `` ` ``
1023       A backtick-delimited string in a code span: `` `foo` ``
1025 will produce:
1027       <p>A single backtick in a code span: <code>`</code></p>
1029       <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
1031 With a code span, ampersands and angle brackets are encoded as HTML
1032 entities automatically, which makes it easy to include example HTML
1033 tags. Markdown will turn this:
1035       Please don't use any `<blink>` tags.
1037 into:
1039       <p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
1041 You can write this:
1043       `&#8212;` is the decimal-encoded equivalent of `&mdash;`.
1045 to produce:
1047       <p><code>&amp;#8212;</code> is the decimal-encoded
1048       equivalent of <code>&amp;mdash;</code>.</p>
1051 ~~~~~~
1052 Images
1053 ~~~~~~
1055 Admittedly, it's fairly difficult to devise a "natural" syntax for
1056 placing images into a plain text document format.
1058 Markdown uses an image syntax that is intended to resemble the syntax
1059 for links, allowing for two styles: *inline* and *reference*.
1061 Inline image syntax looks like this:
1063       ![Alt text](/path/to/img.jpg)
1065       ![Alt text](/path/to/img.jpg "Optional title")
1067 That is:
1069 *   An exclamation mark: `!`;
1070 *   followed by a set of square brackets, containing the `alt`
1071     attribute text for the image;
1072 *   followed by a set of parentheses, containing the URL or path to
1073     the image, and an optional `title` attribute enclosed in double
1074     or single quotes.
1076 Reference-style image syntax looks like this:
1078       ![Alt text][id]
1080 Where "id" is the name of a defined image reference. Image references
1081 are defined using syntax identical to link references:
1083       [id]: url/to/image  "Optional title attribute"
1085 To specify one or both dimensions of an image, include the dimensions
1086 in parentheses at the end of the title like so:
1088       [id]: url/to/image  "Optional title attribute (512x342)"
1090 To resize in just one dimension, specify the other as a "?" like so:
1092       [id]: url/to/image  "Optional title attribute (?x342)"
1093       [id]: url/to/image  "Optional title attribute (512x?)"
1095 The first dimension sets the "width" attribute and the second
1096 dimension sets the "height" attribute.  The dimensions are then
1097 removed from the "title" attribute.
1099 It's possible to wrap the url when it's specified in a reference.
1100 Both of these examples:
1102       [id]: url/\
1103             t\
1104             o/image
1105             "Optional title"
1107       [id]: url/to/image "Optional title"
1109 Produce identical "img" tags.  Only the url can be wrapped and
1110 only when it's in a reference.  The backslash ("\") must be the
1111 last character on the line and the next line (after optional
1112 ignored leading whitespace) must contain at least one additional
1113 character that's part of the URL.
1115 This can be useful for data: urls like so:
1117       ![image][1]
1119       [1]: data:image/gif;base64,R0lGODlhFwAXAPMAMf///+7u7t3d3czMzLu7u6qqqp\
1120            mZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREQAAACwAAAAAFwAXAAAExxDISau9Mg\
1121            She8DURhhHWRLDB26FkSjKqxxFqlbBWOwF4fOGgsCycRkInI+ocEAQNBNWq0caCJ\
1122            i9aSqqGwwIL4MAsRATeMMMEykYHBLIt7DNHETrAPrBihVwDAh2ansBXygaAj5sa1\
1123            x7iTUAKomEBU53B0hGVoVMTleEg0hkCD0DJAhwAlVcQT6nLwgHR1liUQNaqgkMDT\
1124            NWXWkSbS6lZ0eKTUIWuTSbGzlNlkS3LSYksjtPK6YJCzEwNMAgbT9nKBwg6Onq6B\
1125            EAOw== "title (100x100)"
1127 Thus allowing small amounts of image data to be embedded directly in the
1128 source "text" file with minimal fuss.
1131 - - - - -
1134 -------------
1135 Miscellaneous
1136 -------------
1138 ~~~~~~~~~~~~~~~
1139 Automatic Links
1140 ~~~~~~~~~~~~~~~
1142 Markdown supports a shortcut style for creating "automatic" links for URLs
1143 and email addresses: simply surround the URL or email address with angle
1144 brackets or don't. What this means is that if you want to show the actual text
1145 of a URL or email address, and also have it be a clickable link, you can do:
1147       <http://example.com/>
1149 or this:
1151       http://example.com/
1153 Markdown will turn that into:
1155       &lt;<a href="http://example.com/">http://example.com/</a>&gt;
1157 or this:
1159       <a href="http://example.com/">http://example.com/</a>
1161 If Markdown is not quite grabbing the right link when it's not surrounded
1162 by angle brackets then just add the angle brackets to avoid the guessing.
1164 Automatic links for email addresses work similarly, except that
1165 Markdown will also perform a bit of randomized decimal and hex
1166 entity-encoding to help obscure your address from address-harvesting
1167 spambots. For example, Markdown will turn this:
1169       <address@example.com>
1171 into something like this:
1173       <a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
1174       &#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
1175       &#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
1176       &#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
1178 which will render in a browser as a clickable link to "address@example.com".
1180 (This sort of entity-encoding trick will indeed fool many, if not
1181 most, address-harvesting bots, but it definitely won't fool all of
1182 them. It's better than nothing, but an address published in this way
1183 will probably eventually start receiving spam.)
1186 ~~~~~~~~~~~~~~~~~
1187 Backslash Escapes
1188 ~~~~~~~~~~~~~~~~~
1190 Markdown allows you to use backslash escapes to generate literal
1191 characters which would otherwise have special meaning in Markdown's
1192 formatting syntax. For example, if you wanted to surround a word
1193 with literal asterisks (instead of an HTML `<em>` tag), you can use
1194 backslashes before the asterisks, like this:
1196       \*literal asterisks\*
1198 Markdown provides backslash escapes for the following characters:
1200       \   backslash
1201       `   backtick
1202       *   asterisk
1203       _   underscore
1204       ~   tilde
1205       {}  curly braces
1206       []  square brackets
1207       ()  parentheses
1208       #   hash mark
1209       +   plus sign
1210       -   minus sign (hyphen)
1211       .   dot
1212       !   exclamation mark
1213       |   vertical bar (escape only needed/recognized in tables)