README: clean up old version history entries
[markdown.git] / basics.md
blob82cb22d7db63a4e9a2fc72e4b18a24d75163ed23
1 ================
2 Markdown: Basics
3 ================
5 * _[Markdown Basics]( "Markdown Basics")_
6 * [Syntax]
7 * [License]
9 - - - - -
11 ------------------------------------------------
12 Getting the Gist of Markdown's Formatting Syntax
13 ------------------------------------------------
15 This page offers a brief overview of what it's like to use Markdown.
16 The [syntax page][syntax] provides complete, detailed documentation for
17 every feature, but Markdown should be very easy to pick up simply by
18 looking at a few examples of it in action. The examples on this page
19 are written in a before/after style, showing example syntax and the
20 HTML output produced by Markdown.
22 **Note:** This document is itself written using Markdown; you
23 can [see the source for it by adding `.md` to the URL] [src].
25   [syntax]: syntax.html  "Markdown Syntax"
26   [license]: license.html "License Information"
27   [src]: basics.md
30 --------------------------------
31 Paragraphs, Headers, Blockquotes
32 --------------------------------
34 A paragraph is simply one or more consecutive lines of text, separated
35 by one or more blank lines.  (A blank line is any line that looks like
36 a blank line -- a line containing nothing but spaces or tabs is
37 considered blank.)  Normal paragraphs should not be indented with
38 spaces or tabs.  Note that Markdown expands all tabs to spaces before
39 doing anything else.
41 Markdown offers two styles of headers: *Setext* and *atx*.
42 Setext-style headers for `<h1>`, `<h2>` and `<h3>` are created by
43 "underlining" with equal signs (`=`), hyphens (`-`) and tildes (`~`)
44 respectively.  An optional matching "overline" may precede the header.
45 To create an atx-style header, you put 1-6 hash marks (`#`) at the
46 beginning of the line -- the number of hashes equals the resulting
47 HTML header level.
49 Blockquotes are indicated using email-style '`>`' angle brackets.
51 Markdown:
53       ====================
54       A First Level Header
55       ====================
57       A Second Level Header
58       ---------------------
60       A Third Level Header
61       ~~~~~~~~~~~~~~~~~~~~
63       Now is the time for all good men to come to
64       the aid of their country. This is just a
65       regular paragraph.
67       The quick brown fox jumped over the lazy
68       dog's back.
70       ### Header 4
72       > This is a blockquote.
73       >
74       > This is the second paragraph in the blockquote.
75       >
76       > ## This is an H2 in a blockquote
79 Output:
81       <h1>A First Level Header</h1>
83       <h2>A Second Level Header</h2>
85       <h3>A Third Level Header</h3>
87       <p>Now is the time for all good men to come to
88       the aid of their country. This is just a
89       regular paragraph.</p>
91       <p>The quick brown fox jumped over the lazy
92       dog's back.</p>
94       <h4>Header 3</h4>
96       <blockquote>
97           <p>This is a blockquote.</p>
99           <p>This is the second paragraph in the blockquote.</p>
101           <h2>This is an H2 in a blockquote</h2>
102       </blockquote>
105 ~~~~~~~~~~~~~~~
106 Phrase Emphasis
107 ~~~~~~~~~~~~~~~
109 Markdown uses asterisks and underscores to indicate spans of emphasis.
111 Markdown:
113       Some of these words *are emphasized*.
114       Some of these words _are emphasized also_.
116       Use two asterisks for **strong emphasis**.
117       Or, if you prefer, __use two underscores instead__.
118       Or, even, ~~strike through instead~~.
120 Output:
122       <p>Some of these words <em>are emphasized</em>.
123       Some of these words <em>are emphasized also</em>.</p>
125       <p>Use two asterisks for <strong>strong emphasis</strong>.
126       Or, if you prefer, <strong>use two underscores instead</strong>.
127       Or, even, <strke>strike through instead</strike>.</p>
130 -----
131 Lists
132 -----
134 Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`,
135 `+`, and `-`) as list markers. These three markers are
136 interchangable; this:
138       *   Candy.
139       *   Gum.
140       *   Booze.
142 this:
144       +   Candy.
145       +   Gum.
146       +   Booze.
148 and this:
150       -   Candy.
151       -   Gum.
152       -   Booze.
154 all produce the same output:
156       <ul>
157       <li>Candy.</li>
158       <li>Gum.</li>
159       <li>Booze.</li>
160       </ul>
162 Ordered (numbered or lettered) lists use regular numbers (or letters or
163 roman numerals), followed by periods (or right parentheses), as list
164 markers:
166       1.  Red
167       2.  Green
168       3.  Blue
170 Output:
172       <ol>
173       <li>Red</li>
174       <li>Green</li>
175       <li>Blue</li>
176       </ol>
178 If you put blank lines between items, you'll get `<p>` tags for the
179 list item text. You can create multi-paragraph list items by indenting
180 the paragraphs by 4 spaces:
182       *   A list item.
184           With multiple paragraphs.
186       *   Another item in the list.
188 Output:
190       <ul>
191       <li><p>A list item.</p>
192       <p>With multiple paragraphs.</p></li>
193       <li><p>Another item in the list.</p></li>
194       </ul>
197 ~~~~~~
198 Tables
199 ~~~~~~
201 Markdown supports simple tables like so:
203     | Item | Price | Description |
204     | ---- | -----:| ----------- |
205     | Nut  | $1.29 | Delicious   |
206     | Bean | $0.37 | Fiber       |
208 Output:
210     <table>
211       <tr><th>Item</th><th align="right">Price</th><th>Description</th></tr>
212       <tr><td>Nut</td><td align="right">$1.29</td><td>Delicious</td></tr>
213       <tr><td>Bean</td><td align="right">$0.37</td><td>Fiber</td></tr>
214     </table>
217 ~~~~~
218 Links
219 ~~~~~
221 Markdown supports two styles for creating links: *inline* and
222 *reference*. With both styles, you use square brackets to delimit the
223 text you want to turn into a link.
225 Inline-style links use parentheses immediately after the link text.
226 For example:
228       This is an [example link](http://example.com/).
230 Output:
232       <p>This is an <a href="http://example.com/">
233       example link</a>.</p>
235 Optionally, you may include a title attribute in the parentheses:
237       This is an [example link](http://example.com/ "With a Title").
239 Output:
241       <p>This is an <a href="http://example.com/" title="With a Title">
242       example link</a>.</p>
244 Reference-style links allow you to refer to your links by names, which
245 you define elsewhere in your document:
247       I get 10 times more traffic from [Google][1] than from
248       [Yahoo][2] or [MSN][3].
250       [1]: https://google.com/       "Google"
251       [2]: https://search.yahoo.com/ "Yahoo Search"
252       [3]: https://search.msn.com/   "MSN Search"
254 Output:
256       <p>I get 10 times more traffic from <a href="https://google.com/"
257       title="Google">Google</a> than from <a href="https://search.yahoo.com/"
258       title="Yahoo Search">Yahoo</a> or <a href="https://search.msn.com/"
259       title="MSN Search">MSN</a>.</p>
261 The title attribute is optional. Link names may contain letters,
262 numbers and spaces, but are *not* case sensitive:
264       I start my morning with a cup of coffee and
265       [The New York Times][NY Times].
267       [ny times]: https://www.nytimes.com/
269 Output:
271       <p>I start my morning with a cup of coffee and
272       <a href="https://www.nytimes.com/">The New York Times</a>.</p>
275 ~~~~~~
276 Images
277 ~~~~~~
279 Image syntax is very much like link syntax.
281 Inline (titles are optional):
283       ![alt text](/path/to/img.jpg "Title")
285 Reference-style:
287       ![alt text][id]
289       [id]: /path/to/img.jpg "Title"
291 Both of the above examples produce the same output:
293       <img src="/path/to/img.jpg" alt="alt text" title="Title" />
296 ~~~~
297 Code
298 ~~~~
300 In a regular paragraph, you can create code span by wrapping text in
301 backtick quotes. Any ampersands (`&`) and angle brackets (`<` or
302 `>`) will automatically be translated into HTML entities. This makes
303 it easy to use Markdown to write about HTML example code:
305       I strongly recommend against using any `<blink>` tags.
307       I wish SmartyPants used named entities like `&mdash;`
308       instead of decimal-encoded entites like `&#8212;`.
310 Output:
312       <p>I strongly recommend against using any
313       <code>&lt;blink&gt;</code> tags.</p>
315       <p>I wish SmartyPants used named entities like
316       <code>&amp;mdash;</code> instead of decimal-encoded
317       entites like <code>&amp;#8212;</code>.</p>
320 To specify an entire block of pre-formatted code, indent every line of
321 the block by 4 spaces.  Just like with code spans, `&`, `<`, and `>`
322 characters will be escaped automatically.
324 Alternatively an entire block of pre-formatted code may be preceded with a
325 line consisting of 3 backtick quotes (or more) and followed by a line
326 consisting of the same number of backtick quotes -- in which case the code
327 itself does not need to be additionally indented.  The first line may
328 optionally have a syntax specifier (e.g. sh, c, perl, etc.) appended.
329 Note also that any physical tab characters within a 3-backtick-quotes,
330 non-indented code block are *always* expanded correctly to 8-character
331 tab-stop positions.  This is to facilitate simple copy-and-paste to include
332 code snippets.
334 Markdown:
336       ```
337       # This is a simple code block with unspecified syntax
338       ```
340 Output:
342       <pre><code># This is a simple code block with unspecified syntax
343       </code></pre>
345 Markdown:
347       ``` perl
348       my $var = "value"; # this should be highlighted as Perl code
349       ```
351 Output:
353       <pre><code>my $var = "value"; # this should be highlighted as Perl code
354       </code></pre>
356 Markdown:
358       If you want your page to validate under XHTML 1.0 Strict,
359       you've got to put paragraph tags in your blockquotes:
361           <blockquote>
362               <p>For example.</p>
363           </blockquote>
365 Output:
367       <p>If you want your page to validate under XHTML 1.0 Strict,
368       you've got to put paragraph tags in your blockquotes:</p>
370       <pre><code>&lt;blockquote&gt;
371           &lt;p&gt;For example.&lt;/p&gt;
372       &lt;/blockquote&gt;
373       </code></pre>