3 caption: This Markdown is Tested!
8 <ul id="ProjectSubmenu">
9 <li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
10 <li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
11 <li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
12 <li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
13 <li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
17 * [Overview](#overview)
18 * [Philosophy](#philosophy)
19 * [Inline HTML](#html)
20 * [Automatic Escaping for Special Characters](#autoescape)
21 * [Block Elements](#block)
22 * [Paragraphs and Line Breaks](#p)
24 * [Blockquotes](#blockquote)
26 * [Code Blocks](#precode)
27 * [Horizontal Rules](#hr)
28 * [Span Elements](#span)
33 * [Miscellaneous](#misc)
34 * [Backslash Escapes](#backslash)
35 * [Automatic Links](#autolink)
38 **Note:** This document is itself written using Markdown; you
39 can [see the source for it by adding '.text' to the URL][src].
41 [src]: /projects/markdown/syntax.text
45 <h2 id="overview">Overview</h2>
47 <h3 id="philosophy">Philosophy</h3>
49 Markdown is intended to be as easy-to-read and easy-to-write as is feasible.
51 Readability, however, is emphasized above all else. A Markdown-formatted
52 document should be publishable as-is, as plain text, without looking
53 like it's been marked up with tags or formatting instructions. While
54 Markdown's syntax has been influenced by several existing text-to-HTML
55 filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4],
56 [Grutatext] [5], and [EtText] [6] -- the single biggest source of
57 inspiration for Markdown's syntax is the format of plain text email.
59 [1]: http://docutils.sourceforge.net/mirror/setext.html
60 [2]: http://www.aaronsw.com/2002/atx/
61 [3]: http://textism.com/tools/textile/
62 [4]: http://docutils.sourceforge.net/rst.html
63 [5]: http://www.triptico.com/software/grutatxt.html
64 [6]: http://ettext.taint.org/doc/
66 To this end, Markdown's syntax is comprised entirely of punctuation
67 characters, which punctuation characters have been carefully chosen so
68 as to look like what they mean. E.g., asterisks around a word actually
69 look like \*emphasis\*. Markdown lists look like, well, lists. Even
70 blockquotes look like quoted passages of text, assuming you've ever
75 <h3 id="html">Inline HTML</h3>
77 Markdown's syntax is intended for one purpose: to be used as a
78 format for *writing* for the web.
80 Markdown is not a replacement for HTML, or even close to it. Its
81 syntax is very small, corresponding only to a very small subset of
82 HTML tags. The idea is *not* to create a syntax that makes it easier
83 to insert HTML tags. In my opinion, HTML tags are already easy to
84 insert. The idea for Markdown is to make it easy to read, write, and
85 edit prose. HTML is a *publishing* format; Markdown is a *writing*
86 format. Thus, Markdown's formatting syntax only addresses issues that
87 can be conveyed in plain text.
89 For any markup that is not covered by Markdown's syntax, you simply
90 use HTML itself. There's no need to preface it or delimit it to
91 indicate that you're switching from Markdown to HTML; you just use
94 The only restrictions are that block-level HTML elements -- e.g. `<div>`,
95 `<table>`, `<pre>`, `<p>`, etc. -- must be separated from surrounding
96 content by blank lines, and the start and end tags of the block should
97 not be indented with tabs or spaces. Markdown is smart enough not
98 to add extra (unwanted) `<p>` tags around HTML block-level tags.
100 For example, to add an HTML table to a Markdown article:
102 This is a regular paragraph.
110 This is another regular paragraph.
112 Note that Markdown formatting syntax is not processed within block-level
113 HTML tags. E.g., you can't use Markdown-style `*emphasis*` inside an
116 Span-level HTML tags -- e.g. `<span>`, `<cite>`, or `<del>` -- can be
117 used anywhere in a Markdown paragraph, list item, or header. If you
118 want, you can even use HTML tags instead of Markdown formatting; e.g. if
119 you'd prefer to use HTML `<a>` or `<img>` tags instead of Markdown's
120 link or image syntax, go right ahead.
122 Unlike block-level HTML tags, Markdown syntax *is* processed within
126 <h3 id="autoescape">Automatic Escaping for Special Characters</h3>
128 In HTML, there are two characters that demand special treatment: `<`
129 and `&`. Left angle brackets are used to start tags; ampersands are
130 used to denote HTML entities. If you want to use them as literal
131 characters, you must escape them as entities, e.g. `<`, and
134 Ampersands in particular are bedeviling for web writers. If you want to
135 write about 'AT&T', you need to write '`AT&T`'. You even need to
136 escape ampersands within URLs. Thus, if you want to link to:
138 http://images.google.com/images?num=30&q=larry+bird
140 you need to encode the URL as:
142 http://images.google.com/images?num=30&q=larry+bird
144 in your anchor tag `href` attribute. Needless to say, this is easy to
145 forget, and is probably the single most common source of HTML validation
146 errors in otherwise well-marked-up web sites.
148 Markdown allows you to use these characters naturally, taking care of
149 all the necessary escaping for you. If you use an ampersand as part of
150 an HTML entity, it remains unchanged; otherwise it will be translated
153 So, if you want to include a copyright symbol in your article, you can write:
157 and Markdown will leave it alone. But if you write:
161 Markdown will translate it to:
165 Similarly, because Markdown supports [inline HTML](#html), if you use
166 angle brackets as delimiters for HTML tags, Markdown will treat them as
167 such. But if you write:
171 Markdown will translate it to:
175 However, inside Markdown code spans and blocks, angle brackets and
176 ampersands are *always* encoded automatically. This makes it easy to use
177 Markdown to write about HTML code. (As opposed to raw HTML, which is a
178 terrible format for writing about HTML syntax, because every single `<`
179 and `&` in your example code needs to be escaped.)
185 <h2 id="block">Block Elements</h2>
188 <h3 id="p">Paragraphs and Line Breaks</h3>
190 A paragraph is simply one or more consecutive lines of text, separated
191 by one or more blank lines. (A blank line is any line that looks like a
192 blank line -- a line containing nothing but spaces or tabs is considered
193 blank.) Normal paragraphs should not be intended with spaces or tabs.
195 The implication of the "one or more consecutive lines of text" rule is
196 that Markdown supports "hard-wrapped" text paragraphs. This differs
197 significantly from most other text-to-HTML formatters (including Movable
198 Type's "Convert Line Breaks" option) which translate every line break
199 character in a paragraph into a `<br />` tag.
201 When you *do* want to insert a `<br />` break tag using Markdown, you
202 end a line with two or more spaces, then type return.
204 Yes, this takes a tad more effort to create a `<br />`, but a simplistic
205 "every line break is a `<br />`" rule wouldn't work for Markdown.
206 Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l]
207 work best -- and look better -- when you format them with hard breaks.
214 <h3 id="header">Headers</h3>
216 Markdown supports two styles of headers, [Setext] [1] and [atx] [2].
218 Setext-style headers are "underlined" using equal signs (for first-level
219 headers) and dashes (for second-level headers). For example:
227 Any number of underlining `=`'s or `-`'s will work.
229 Atx-style headers use 1-6 hash characters at the start of the line,
230 corresponding to header levels 1-6. For example:
238 Optionally, you may "close" atx-style headers. This is purely
239 cosmetic -- you can use this if you think it looks better. The
240 closing hashes don't even need to match the number of hashes
241 used to open the header. (The number of opening hashes
242 determines the header level.) :
248 ### This is an H3 ######
251 <h3 id="blockquote">Blockquotes</h3>
253 Markdown uses email-style `>` characters for blockquoting. If you're
254 familiar with quoting passages of text in an email message, then you
255 know how to create a blockquote in Markdown. It looks best if you hard
256 wrap the text and put a `>` before every line:
258 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
259 > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
260 > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
262 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
263 > id sem consectetuer libero luctus adipiscing.
265 Markdown allows you to be lazy and only put the `>` before the first
266 line of a hard-wrapped paragraph:
268 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
269 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
270 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
272 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
273 id sem consectetuer libero luctus adipiscing.
275 Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
276 adding additional levels of `>`:
278 > This is the first level of quoting.
280 > > This is nested blockquote.
282 > Back to the first level.
284 Blockquotes can contain other Markdown elements, including headers, lists,
287 > ## This is a header.
289 > 1. This is the first list item.
290 > 2. This is the second list item.
292 > Here's some example code:
294 > return shell_exec("echo $input | $markdown_script");
296 Any decent text editor should make email-style quoting easy. For
297 example, with BBEdit, you can make a selection and choose Increase
298 Quote Level from the Text menu.
301 <h3 id="list">Lists</h3>
303 Markdown supports ordered (numbered) and unordered (bulleted) lists.
305 Unordered lists use asterisks, pluses, and hyphens -- interchangably
324 Ordered lists use numbers followed by periods:
330 It's important to note that the actual numbers you use to mark the
331 list have no effect on the HTML output Markdown produces. The HTML
332 Markdown produces from the above list is:
340 If you instead wrote the list in Markdown like this:
352 you'd get the exact same HTML output. The point is, if you want to,
353 you can use ordinal numbers in your ordered Markdown lists, so that
354 the numbers in your source match the numbers in your published HTML.
355 But if you want to be lazy, you don't have to.
357 If you do use lazy list numbering, however, you should still start the
358 list with the number 1. At some point in the future, Markdown may support
359 starting ordered lists at an arbitrary number.
361 List markers typically start at the left margin, but may be indented by
362 up to three spaces. List markers must be followed by one or more spaces
365 To make lists look nice, you can wrap items with hanging indents:
367 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
368 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
369 viverra nec, fringilla in, laoreet vitae, risus.
370 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
371 Suspendisse id sem consectetuer libero luctus adipiscing.
373 But if you want to be lazy, you don't have to:
375 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
376 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
377 viverra nec, fringilla in, laoreet vitae, risus.
378 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
379 Suspendisse id sem consectetuer libero luctus adipiscing.
381 If list items are separated by blank lines, Markdown will wrap the
382 items in `<p>` tags in the HTML output. For example, this input:
404 <li><p>Magic</p></li>
407 List items may consist of multiple paragraphs. Each subsequent
408 paragraph in a list item must be intended by either 4 spaces
411 1. This is a list item with two paragraphs. Lorem ipsum dolor
412 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
415 Vestibulum enim wisi, viverra nec, fringilla in, laoreet
416 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
419 2. Suspendisse id sem consectetuer libero luctus adipiscing.
421 It looks nice if you indent every line of the subsequent
422 paragraphs, but here again, Markdown will allow you to be
425 * This is a list item with two paragraphs.
427 This is the second paragraph in the list item. You're
428 only required to indent the first line. Lorem ipsum dolor
429 sit amet, consectetuer adipiscing elit.
431 * Another item in the same list.
433 To put a blockquote within a list item, the blockquote's `>`
434 delimiters need to be indented:
436 * A list item with a blockquote:
438 > This is a blockquote
439 > inside a list item.
441 To put a code block within a list item, the code block needs
442 to be indented *twice* -- 8 spaces or two tabs:
444 * A list item with a code block:
449 It's worth noting that it's possible to trigger an ordered list by
450 accident, by writing something like this:
452 1986. What a great season.
454 In other words, a *number-period-space* sequence at the beginning of a
455 line. To avoid this, you can backslash-escape the period:
457 1986\. What a great season.
461 <h3 id="precode">Code Blocks</h3>
463 Pre-formatted code blocks are used for writing about programming or
464 markup source code. Rather than forming normal paragraphs, the lines
465 of a code block are interpreted literally. Markdown wraps a code block
466 in both `<pre>` and `<code>` tags.
468 To produce a code block in Markdown, simply indent every line of the
469 block by at least 4 spaces or 1 tab. For example, given this input:
471 This is a normal paragraph:
473 This is a code block.
475 Markdown will generate:
477 <p>This is a normal paragraph:</p>
479 <pre><code>This is a code block.
482 One level of indentation -- 4 spaces or 1 tab -- is removed from each
483 line of the code block. For example, this:
485 Here is an example of AppleScript:
487 tell application "Foo"
493 <p>Here is an example of AppleScript:</p>
495 <pre><code>tell application "Foo"
500 A code block continues until it reaches a line that is not indented
501 (or the end of the article).
503 Within a code block, ampersands (`&`) and angle brackets (`<` and `>`)
504 are automatically converted into HTML entities. This makes it very
505 easy to include example HTML source code using Markdown -- just paste
506 it and indent it, and Markdown will handle the hassle of encoding the
507 ampersands and angle brackets. For example, this:
510 © 2004 Foo Corporation
515 <pre><code><div class="footer">
516 &copy; 2004 Foo Corporation
520 Regular Markdown syntax is not processed within code blocks. E.g.,
521 asterisks are just literal asterisks within a code block. This means
522 it's also easy to use Markdown to write about Markdown's own syntax.
526 <h3 id="hr">Horizontal Rules</h3>
528 You can produce a horizontal rule tag (`<hr />`) by placing three or
529 more hyphens, asterisks, or underscores on a line by themselves. If you
530 wish, you may use spaces between the hyphens or asterisks. Each of the
531 following lines will produce a horizontal rule:
541 ---------------------------------------
548 <h2 id="span">Span Elements</h2>
550 <h3 id="link">Links</h3>
552 Markdown supports two style of links: *inline* and *reference*.
554 In both styles, the link text is delimited by [square brackets].
556 To create an inline link, use a set of regular parentheses immediately
557 after the link text's closing square bracket. Inside the parentheses,
558 put the URL where you want the link to point, along with an *optional*
559 title for the link, surrounded in quotes. For example:
561 This is [an example](http://example.com/ "Title") inline link.
563 [This link](http://example.net/) has no title attribute.
567 <p>This is <a href="http://example.com/" title="Title">
568 an example</a> inline link.</p>
570 <p><a href="http://example.net/">This link</a> has no
573 If you're referring to a local resource on the same server, you can
576 See my [About](/about/) page for details.
578 Reference-style links use a second set of square brackets, inside
579 which you place a label of your choosing to identify the link:
581 This is [an example][id] reference-style link.
583 You can optionally use a space to separate the sets of brackets:
585 This is [an example] [id] reference-style link.
587 Then, anywhere in the document, you define your link label like this,
590 [id]: http://example.com/ "Optional Title Here"
594 * Square brackets containing the link identifier (optionally
595 indented from the left margin using up to three spaces);
596 * followed by a colon;
597 * followed by one or more spaces (or tabs);
598 * followed by the URL for the link;
599 * optionally followed by a title attribute for the link, enclosed
600 in double or single quotes.
602 The link URL may, optionally, be surrounded by angle brackets:
604 [id]: <http://example.com/> "Optional Title Here"
606 You can put the title attribute on the next line and use extra spaces
607 or tabs for padding, which tends to look better with longer URLs:
609 [id]: http://example.com/longish/path/to/resource/here
610 "Optional Title Here"
612 Link definitions are only used for creating links during Markdown
613 processing, and are stripped from your document in the HTML output.
615 Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are *not* case sensitive. E.g. these two links:
622 The *implicit link name* shortcut allows you to omit the name of the
623 link, in which case the link text itself is used as the name.
624 Just use an empty set of square brackets -- e.g., to link the word
625 "Google" to the google.com web site, you could simply write:
629 And then define the link:
631 [Google]: http://google.com/
633 Because link names may contain spaces, this shortcut even works for
634 multiple words in the link text:
636 Visit [Daring Fireball][] for more information.
638 And then define the link:
640 [Daring Fireball]: http://daringfireball.net/
642 Link definitions can be placed anywhere in your Markdown document. I
643 tend to put them immediately after each paragraph in which they're
644 used, but if you want, you can put them all at the end of your
645 document, sort of like footnotes.
647 Here's an example of reference links in action:
649 I get 10 times more traffic from [Google] [1] than from
650 [Yahoo] [2] or [MSN] [3].
652 [1]: http://google.com/ "Google"
653 [2]: http://search.yahoo.com/ "Yahoo Search"
654 [3]: http://search.msn.com/ "MSN Search"
656 Using the implicit link name shortcut, you could instead write:
658 I get 10 times more traffic from [Google][] than from
659 [Yahoo][] or [MSN][].
661 [google]: http://google.com/ "Google"
662 [yahoo]: http://search.yahoo.com/ "Yahoo Search"
663 [msn]: http://search.msn.com/ "MSN Search"
665 Both of the above examples will produce the following HTML output:
667 <p>I get 10 times more traffic from <a href="http://google.com/"
668 title="Google">Google</a> than from
669 <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
670 or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
672 For comparison, here is the same paragraph written using
673 Markdown's inline link style:
675 I get 10 times more traffic from [Google](http://google.com/ "Google")
676 than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
677 [MSN](http://search.msn.com/ "MSN Search").
679 The point of reference-style links is not that they're easier to
680 write. The point is that with reference-style links, your document
681 source is vastly more readable. Compare the above examples: using
682 reference-style links, the paragraph itself is only 81 characters
683 long; with inline-style links, it's 176 characters; and as raw HTML,
684 it's 234 characters. In the raw HTML, there's more markup than there
687 With Markdown's reference-style links, a source document much more
688 closely resembles the final output, as rendered in a browser. By
689 allowing you to move the markup-related metadata out of the paragraph,
690 you can add links without interrupting the narrative flow of your
694 <h3 id="em">Emphasis</h3>
696 Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
697 emphasis. Text wrapped with one `*` or `_` will be wrapped with an
698 HTML `<em>` tag; double `*`'s or `_`'s will be wrapped with an HTML
699 `<strong>` tag. E.g., this input:
707 __double underscores__
711 <em>single asterisks</em>
713 <em>single underscores</em>
715 <strong>double asterisks</strong>
717 <strong>double underscores</strong>
719 You can use whichever style you prefer; the lone restriction is that
720 the same character must be used to open and close an emphasis span.
722 Emphasis can be used in the middle of a word:
724 un*fucking*believable
726 But if you surround an `*` or `_` with spaces, it'll be treated as a
727 literal asterisk or underscore.
729 To produce a literal asterisk or underscore at a position where it
730 would otherwise be used as an emphasis delimiter, you can backslash
733 \*this text is surrounded by literal asterisks\*
737 <h3 id="code">Code</h3>
739 To indicate a span of code, wrap it with backtick quotes (`` ` ``).
740 Unlike a pre-formatted code block, a code span indicates code within a
741 normal paragraph. For example:
743 Use the `printf()` function.
747 <p>Use the <code>printf()</code> function.</p>
749 To include a literal backtick character within a code span, you can use
750 multiple backticks as the opening and closing delimiters:
752 ``There is a literal backtick (`) here.``
754 which will produce this:
756 <p><code>There is a literal backtick (`) here.</code></p>
758 The backtick delimiters surrounding a code span may include spaces --
759 one after the opening, one before the closing. This allows you to place
760 literal backtick characters at the beginning or end of a code span:
762 A single backtick in a code span: `` ` ``
764 A backtick-delimited string in a code span: `` `foo` ``
768 <p>A single backtick in a code span: <code>`</code></p>
770 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
772 With a code span, ampersands and angle brackets are encoded as HTML
773 entities automatically, which makes it easy to include example HTML
774 tags. Markdown will turn this:
776 Please don't use any `<blink>` tags.
780 <p>Please don't use any <code><blink></code> tags.</p>
784 `—` is the decimal-encoded equivalent of `—`.
788 <p><code>&#8212;</code> is the decimal-encoded
789 equivalent of <code>&mdash;</code>.</p>
793 <h3 id="img">Images</h3>
795 Admittedly, it's fairly difficult to devise a "natural" syntax for
796 placing images into a plain text document format.
798 Markdown uses an image syntax that is intended to resemble the syntax
799 for links, allowing for two styles: *inline* and *reference*.
801 Inline image syntax looks like this:
803 ![Alt text](/path/to/img.jpg)
805 ![Alt text](/path/to/img.jpg "Optional title")
809 * An exclamation mark: `!`;
810 * followed by a set of square brackets, containing the `alt`
811 attribute text for the image;
812 * followed by a set of parentheses, containing the URL or path to
813 the image, and an optional `title` attribute enclosed in double
816 Reference-style image syntax looks like this:
820 Where "id" is the name of a defined image reference. Image references
821 are defined using syntax identical to link references:
823 [id]: url/to/image "Optional title attribute"
825 As of this writing, Markdown has no syntax for specifying the
826 dimensions of an image; if this is important to you, you can simply
827 use regular HTML `<img>` tags.
833 <h2 id="misc">Miscellaneous</h2>
835 <h3 id="autolink">Automatic Links</h3>
837 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:
839 <http://example.com/>
841 Markdown will turn this into:
843 <a href="http://example.com/">http://example.com/</a>
845 Automatic links for email addresses work similarly, except that
846 Markdown will also perform a bit of randomized decimal and hex
847 entity-encoding to help obscure your address from address-harvesting
848 spambots. For example, Markdown will turn this:
850 <address@example.com>
852 into something like this:
854 <a href="mailto:addre
855 ss@example.co
856 m">address@exa
857 mple.com</a>
859 which will render in a browser as a clickable link to "address@example.com".
861 (This sort of entity-encoding trick will indeed fool many, if not
862 most, address-harvesting bots, but it definitely won't fool all of
863 them. It's better than nothing, but an address published in this way
864 will probably eventually start receiving spam.)
868 <h3 id="backslash">Backslash Escapes</h3>
870 Markdown allows you to use backslash escapes to generate literal
871 characters which would otherwise have special meaning in Markdown's
872 formatting syntax. For example, if you wanted to surround a word with
873 literal asterisks (instead of an HTML `<em>` tag), you can backslashes
874 before the asterisks, like this:
876 \*literal asterisks\*
878 Markdown provides backslash escapes for the following characters:
889 - minus sign (hyphen)