Title photo
Ode is simple! (Simple means that you know how it works.)
Start of execution (Good luck).

Site Message

Hi and welcome to Ode (pronounced oh-dee). Glad you stopped by.

Important: Ode is very new.

In the coming weeks I intend to post a lot of information to this site, and of course the complete project (including a set of sample themes and documentation) will be available for you to download.

Please do check back or subscribe to this site's feed if you're interested.

-Rob

Posts

Subscribe (this category):  Subscribe to RSS2.0 Feed button

Thu, 08 Jan 2009

Markdown: Syntax

Index

Paragraphs and Line Breaks

To create a new paragraph - type a blank line

back to index

More Info

Create your first paragraph simply start typing. To end the paragraph and start a new one, insert one or more blank lines. The number of blank lines you add is unimportant. A single blank line is enough to start a new paragraph and adding additional blank lines has no effect.

Note that a blank line is a line containing only whitespace. If you finish typing a line of text press the return key to type only spaces and tabs, press the return key again and start typing text again, you've just created a new paragraph. On the other hand, if you typed even a single character other than a space, tab or return then you're continuing the same paragraph.

Extraneous spaces and tabs are ignored (i.e. they collapse to a single space).

So something like this:

 words     scattered  
                    around  
          like so

Becomes this:

words scattered around like so

Paragraphs should not be indented with spaces or tabs unless you are trying to do something special (e.g. create a pre-formatted block like the one above).

back to index

Headings

Two styles of specifying headings are supported.

Style 1 (Setext-style)

You can produce (only) first and second level headings (H1 and H2) using Setext-style markup.

  • First-level heading - underline the heading text with (one or more) equal signs (=).
  • Second-level heading - underline the heading text with (one or more) dashes (-).

Style 2 (atx-style)

You can produce level 1 - 6 headings (H1 - H6) using atx-style markup.

Start the line containing the heading text with the number of hash characters (# - also referred to as pound signs) corresponding to the desired heading level.

  • First-level heading - # heading text
  • Second-level heading - ## heading text
  • ...
  • Sixth-level heading - ###### heading text

You can optionally add an equal number of trailing hashes at the end of the line. There is no functional advantage to adding the trauling hash characters, but doing so may improve the readability of the source document (i.e. the document as it appears in a text editor).

  • Sixth level heading (with trailing hashes) - ###### heading text ######

back to index

More Info

Keep in mind that headings are primarily structural elements of a page. You should not use headings simply as a way of emphasizing text, forcing breaks, or in any other inappropriate way.

From the [W3C]'s(w3c) HTML 4.01 Specifiication document

A heading element briefly describes the topic of the section it introduces. Heading information may be used by user agents, for example, to construct a table of contents for a document automatically.

There are six levels of headings in HTML with H1 as the most important and H6 as the least. Visual browsers usually render more important headings in larger fonts than less important ones.

Style 1 (Setext-style)

First-level heading - underline the heading text with (one or more) equal signs (=).

For example

My First-level Heading
=

or alternatively

My First-level Heading
======================

The number of equal signs you use is unimportant. The rule is 'one or more' equal signs (and nothing else) on the line immediately following the heading text. Underlining the entire heading with equal signs is arguably easier to read than the 'just enough to get the job done' alternative with only a single equal sign.

Second-level heading - underline the heading text with (one or more) dashes (-).

For example

My Second-level Heading
-

or alternatively

My Second-level Heading
-----------------------

Again, the number of dashes you use is unimportant. The rule is 'one or more' dashes (and nothing else) on the line immediately following the heading text. Underlining the entire heading with dashes is arguably easier to read than the 'just enough to get the job done' alternative with only a single dash.

For H3 - H6 headings you must use atx-style headings (described next).

Style 2 (atx-style)

You must use atx-style headings to produce H3 - H6 headings. Of course, you can also use atx-style markup for H1 and H3 headings. So if you only want to commit one of these two heading styles to memory then stick to the atx-style.

The good news is that atx-style headings are relatively intutive and easy to remember.

  • Simply start the line with your heading text with 1 to 6 hash characters corresponding to heading levels H1 - H6, then
  • type the heading text, and
  • optionally end the line with a number of hash characters equal to the number you used at the beginning of the line.

For example, this markup:

# First-level heading
## Second-level heading ##
### Third-level heading
#### Fourth-level heading ####
##### Fifth-level heading
###### Sixth-level heading ######

Results in this:

First-level heading

Second-level heading

Third-level heading

Fourth-level heading

Fifth-level heading
Sixth-level heading

back to index

Blockquotes

To add a blockquote - Start one or more consecutive lines with a '>' character.

Note that this is the same as how you might quote a block of text in an email message.

markdown allows you to use only a single '>' at the start of the quote. All consecutive lines are quoted until the first newline. Alternatively you can start each line of the blockquote with it's own '>' character. Consecutive lines will contribute to a single blockquote.

back to index

More Info

Blcokquoting couldn't be any easier than it is with markdown. Futhermore, blockquotes in markdown while easy to produce do not lose any of their sophistication.

Because of the combination of it's simple inspired inspired syntax maybe no other element captures the spirit of markdown as well as blockquotes.

To create a blockquote simply start a line with a greater than symbol, '>'. Without doing anything else, all consecutive lines are included in the quote.

For example:

> Lorem ipsum dolor sit amet, consectetur adipiscing elit,
set eiusmod tempor incidunt et labore et dolore magna aliquam.
Ut enim unt ut labore et dolore magna aliqua.
Ut enim ad trenz ucu hugh ipsum monugor.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

Alternatively, you can start each line with it's own '>' character. All of the consecutive lines taken together still constitute a single blockquote.

For example:

> Lorem ipsum dolor sit amet, consectetur adipiscing elit,
> set eiusmod tempor incidunt et labore et dolore magna aliquam.
> Ut enim unt ut labore et dolore magna aliqua.
> Ut enim ad trenz ucu hugh ipsum monugor.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

Note that in the block qbove all of the lines are hard-wrapped (i.e. all end in a return). You are free to wrap the text wherever it looks best to you. Remember that returns do not translate to paragraph or line breaks with markdown. So though you may wrap the text of a blockquote to improve the readability of the source document, you do not need to worry about how those return will affect the look at the blockquoted passage in a web browser.

I said that blockquotes did not lose any of their sophistication in markdown. More specifically, you can include markdown text inside a blockquote and it will be interpreted exactly as it would be normally (i.e. outside of a blockquote). You can even have a blockquote within a blockquote (nested quotes) by using more than one '>' character.

For example

> Lorem ipsum dolor sit amet, consectetur adipiscing elit,
> set eiusmod tempor incidunt et labore et dolore magna aliquam.

> > Lorem ipsum dolor sit amet, consectetur adipiscing elit,
> > set eiusmod tempor incidunt et labore et dolore magna aliquam.
> > Ut enim unt ut labore et dolore magna aliqua.
> > Ut enim ad trenz ucu hugh ipsum monugor.

> Ut enim unt ut labore et dolore magna aliqua.
> Ut enim ad trenz ucu hugh ipsum monugor.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

Again this is exactly how quoting is handled in email.

To make the use of blockquoting even easier, keep in mind that many text editors are capable of helping you with this style of quoting (search the menus for items titled something similar to 'increase quote level' and 'decrease quote level').

back to index

Lists

HTML supports two types of lists

  • unordered (in which list items are not numbered but may be indicated with some other symbol).
  • ordered (in which list items are numbered)

Markdown allows you to specify either type.

Unordered lists

Specify unordered lists as a series of consecutive lines, where each line is a separate list item, and each line begins with an asterisk ('*'), plus ('+'), or hyphen ('-').

For example:

* item one
* item two
* item three

Unordered lists

Specify ordered lists as a series of consecutive lines, where each line is a separate list item and each line begins with a number and a period (e.g. '1.').

Important: The numbers used are unimportant in that they have no effect on how the rendered list is interpreted by markdown.

For example the following are all equivalent:

Example 1

1. item one
2. item two
3. item three

Example 2

1. item one
1. item two
1. item three

Example 3

6. item one
5. item two
9. item three

back to index

More Info

General Comments About Lists

List markers typically start at the left margin, but may be indented by up to three spaces.

Compare:

* item one (w/o indentation)
* item two (w/o indentation)
* item three (w/o indentation)

Which results in the following list:

  • item one (w/o indentation)
  • item two (w/o indentation)
  • item three (w/o indentation)

with

   * item one (indented three spaces)
   * item two (indented three spaces)
   * item three (indented three spaces)

Which results in the following list:

  • item one (indented three spaces)
  • item two (indented three spaces)
  • item three (indented three spaces)

Note: Don't mix different levels of indentation within the same list unless you are intending to create a nested list.

For example:

* item one (w/o indentation)
  * item two (indented two spaces)
 * item three (indented one space)

Results in the folllowing list:

  • item one (w/o indentation)
    • item two (indented two spaces)
    • item three (indented one space)

Where items two and three are placed in a second unordered list which is an item of the first unordered list.

<ul>
  <li>item one (w/o indentation)</li>
  <li>
    <ul>
      <il>item two (indented two spaces)</il>
      <il>item three (indented two spaces)</il>
    </ul>
  </li>
</ul>

This sort of construction can be useful but it is not a simple list of three items.

List markers must be followed by one or more spaces or a tab.

So this for example is not a valid list

1.item one
2.item two
3.item three

Compare that with the following (which is valid)

1. item one
2.         item two
3.    item three

Note that the number of spaces or tabs following the list marker is not significant.

When your list items span multiple lines, you may choose to indent all of the lines after the first.

For example:

*  Lorem ipsum dolor sit amet, consectetur adipiscing elit,
   set eiusmod tempor incidunt et labore et dolore magna aliquam.
   Ut enim unt ut labore et dolore magna aliqua.
   Ut enim ad trenz ucu hugh ipsum monugor.
*  Lorem ipsum dolor sit amet, consectetur adipiscing elit,
   set eiusmod tempor incidunt et labore et dolore magna aliquam.
   Ut enim unt ut labore et dolore magna aliqua.
   Ut enim ad trenz ucu hugh ipsum monugor.

But this isn't required.

The following is also valid:

*  Lorem ipsum dolor sit amet, consectetur adipiscing elit,
set eiusmod tempor incidunt et labore et dolore magna aliquam.
Ut enim unt ut labore et dolore magna aliqua.
Ut enim ad trenz ucu hugh ipsum monugor.
*  Lorem ipsum dolor sit amet, consectetur adipiscing elit,
set eiusmod tempor incidunt et labore et dolore magna aliquam.
Ut enim unt ut labore et dolore magna aliqua.
Ut enim ad trenz ucu hugh ipsum monugor.

The first of the two examples above is arguably easier to read.

If list items are separated by blank lines, markdown will wrap each list item in a paragraph tag in the resulting HTML markup.

Compare

* item one
* item two
* item three

with

* item one

* item two

* item three

The first results in the following HTML markup

<ul>
  <li>item one</li>
  <li>item two</li>
  <li>item three</li>
</ul>

The second results in the following HTML

<ul>
  <li><p>item one</p></li>
  <li><p>item two</p></li>
  <li><p>item three</p></li>
</ul>

List items may consist of multiple paragraphs. To accomplish this, each paragraph after the first must be indented by at least 4 spaces or a single tab.

Just as we saw with list items spanning multiple lines, every line in these additional paragraphs may be indented but this is not required.

Compare

1.   Lorem ipsum dolor sit amet, consectetur adipiscing elit,
     set eiusmod tempor incidunt et labore et dolore magna aliquam.
     Ut enim unt ut labore et dolore magna aliqua.
     Ut enim ad trenz ucu hugh ipsum monugor.

     Lorem ipsum dolor sit amet, consectetur adipiscing elit,
     set eiusmod tempor incidunt et labore et dolore magna aliquam.
     Ut enim unt ut labore et dolore magna aliqua.
     Ut enim ad trenz ucu hugh ipsum monugor.

2.   Lorem ipsum dolor sit amet, consectetur adipiscing elit,
     set eiusmod tempor incidunt et labore et dolore magna aliquam.
     Ut enim unt ut labore et dolore magna aliqua.
     Ut enim ad trenz ucu hugh ipsum monugor.

     Lorem ipsum dolor sit amet, consectetur adipiscing elit,
     set eiusmod tempor incidunt et labore et dolore magna aliquam.
     Ut enim unt ut labore et dolore magna aliqua.
     Ut enim ad trenz ucu hugh ipsum monugor.

with

1.   Lorem ipsum dolor sit amet, consectetur adipiscing elit,
set eiusmod tempor incidunt et labore et dolore magna aliquam.
Ut enim unt ut labore et dolore magna aliqua.
Ut enim ad trenz ucu hugh ipsum monugor.

     Lorem ipsum dolor sit amet, consectetur adipiscing elit,
set eiusmod tempor incidunt et labore et dolore magna aliquam.
Ut enim unt ut labore et dolore magna aliqua.
Ut enim ad trenz ucu hugh ipsum monugor.

2.   Lorem ipsum dolor sit amet, consectetur adipiscing elit,
set eiusmod tempor incidunt et labore et dolore magna aliquam.
Ut enim unt ut labore et dolore magna aliqua.
Ut enim ad trenz ucu hugh ipsum monugor.

     Lorem ipsum dolor sit amet, consectetur adipiscing elit,
set eiusmod tempor incidunt et labore et dolore magna aliquam.
Ut enim unt ut labore et dolore magna aliqua.
Ut enim ad trenz ucu hugh ipsum monugor.

The first of the two examples above is arguably easier to read but they will be interpreted identically. Either will produce the following list:

  1. Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

  2. Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

We can use markdown within lists. Just like blockquotes, the synax is interpreted as it normally is within a list, however it's important to note that any feature that requires that text be indented (for example preformatted text - discussed below), we must first indent for the list and then again for the feature included in the list.

For example, pre-formatted text requires that each line of the block be indented by at least four spaces or one tab. To include a pre-formatted block within a list, the block must first be indented by four spaces or one tab to indicate that it is part of a list item, and indented four more spaces or another tab so that it will be interpreted as a preformatted block (a total of 8 spaces).

We'll end the discussion of list syntax with a couple a warning (or two).

First, it is possible to create a list unintentionally. Remember that any series of digits followed immediately by a period and then any number of spaces or tabs (at least one) will be interpreted as a list item and result in the creation of a list.

For example (example taken from markdown's own website:

1986. was an important year

which is interpreted as:

  1. was an important year

To avoid this being mistaken for a list, backslash-escape the period.

1986\. was an important year

In general 'escaping' a special characters is a way to tell an interpreter, like markdown interpreter, to disregard the characters special function (Use of escape sequences is discussed elsewhere in this document - refer to the index).

Finally, we have this warning from the developer of the markdown syntax:

If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number.

This is telling us that if we choose to number an ordered list out of sequence,

for example

6. item one
5. item two
9. item three

or

2. item one
2. item two
2. item three

We should always start the list with '1.'. So, those two examples should b rewritten as:

1. item one
5. item two
9. item three

and

1. item one
1. item two
1. item three

This is not because the current version of markdown will misinterpret the list but to accomodate a potential future revision of the syntax.

back to index

Preformatted Text and Code Blocks

Preformatted blocks are useful for writing about markup, programming languages, or other very structured block of text that should be interpreted literally (i.e. left untouched).

To produce a preformatted block, indent every line of the block by at least 4 spaces or one tab.

back to index

More Info

Preformatted code blocks are the answer to the otherwise insoluble riddle, 'how do you write about a markup syntax, exposing the syntax itself, using the syntax you are writing about without it being interpreted?'

For example, it is not very useful to do something like...

Use the following syntax to create a blockquote:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim unt ut labore et dolore magna aliqua. Ut enim ad trenz ucu hugh ipsum monugor.

Huh? What was that?

I can see the blockquote but not the syntax that is responsible for creating the blockquote. What's worse, if I look at the source code for the page in my browser all I'll see is the HTML resulting from the markdown syntax I was to create the blockquote (not the markdown syntax itself).

What I wanted to do was this...

Use the following syntax to create a blockquote:

> Lorem ipsum dolor sit amet, consectetur adipiscing elit,
> set eiusmod tempor incidunt et labore et dolore magna aliquam.
> Ut enim unt ut labore et dolore magna aliqua.
> Ut enim ad trenz ucu hugh ipsum monugor.

And preformatted code blocks make that possible.

The [W3C]'s(w3c) HTML 4.01 Specifiication document tells us this about preformatted blocks:

The PRE element tells visual user agents that the enclosed text is "preformatted". When handling preformatted text, visual user agents:

May leave white space intact. May render text with a fixed-pitch font. May disable automatic word wrap. Must not disable bidirectional processing.

To produce a preformatted code block in markdown, indent every line of the block by at least 4 spaces or one tab.

In response, markdown wraps the block in both <pre> and <code> tags.

For example:

This is a line of normal text.

It is wrapped in <p> (paragraph) tags in the resulting HTML by markdown, which looks like this:

<p>This is a line of normal text.</p>

For comparison the same line as preformatted text (indented by at least four spaces or one tab) is wrapped in <pre> and <code> tags, which looks like this:

<pre><code>This is a line of preformatted text.</code></pre>

Because preformatted blocks leave whitespace intact (i.e. consecutive whitespace is not collapsed down to a single space as it normally is) and can be rendered using a monospaced font, these blocks are very useful for representing source code in which spacing and indentation is crucially important to communicating the structure of the code which determines how the code is executed.

There is one subtly here. Because we must indent each line of the block by at least 4 spaces or one tab to indicate to markdown that we want a preformatted code block, markdown removes 4 spaces or one tabe from each line (keep in mind that whitespace is not removed from the block itself). This means that the structure of the block remains intact.

For example the following simple structured block:

    loop
        first statement in the loop
        second statement in the loop
        third statement in the loop
    end loop

Will be rendered as:

loop
    first statement in the loop
    second statement in the loop
    third statement in the loop
end loop

Notice that the indentation is preserved. The first four spaces are stripped from every line leaving the nested structure intact. Though this is a simple example, it does illustrate the idea. Your more complicated code blocks will behave the same way.

Keep in mind that a code block continues until the first line encountered that is not indented.

back to index

A code block continues until it reaches a line that is not indented (or the end of the article).

Within a code block, ampersands (&) and angle brackets (< and >) are automatically converted into HTML entities. This makes it very easy to include example HTML source code using Markdown -- just paste it and indent it, and Markdown will handle the hassle of encoding the ampersands and angle brackets. For example, this:

    <div class="footer">
        © 2004 Foo Corporation
    </div>

will turn into:

<pre><code><div class="footer">
    &copy; 2004 Foo Corporation
</div>
</code></pre>

Regular Markdown syntax is not processed within code blocks. E.g., asterisks are just literal asterisks within a code block. This means it's also easy to use Markdown to write about Markdown's own syntax.

The implication of the "one or more consecutive lines of text" rule is
that Markdown supports "hard-wrapped" text paragraphs. This differs
significantly from most other text-to-HTML formatters (including Movable
Type's "Convert Line Breaks" option) which translate every line break
character in a paragraph into a `<br />` tag.

When you *do* want to insert a `<br />` break tag using Markdown, you
end a line with two or more spaces, then type return.

Yes, this takes a tad more effort to create a `<br />`, but a simplistic
"every line break is a `<br />`" rule wouldn't work for Markdown.
Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l]
work best -- and look better -- when you format them with hard breaks.

  [bq]: #blockquote
  [l]:  #list

Overview

Philosophy

Markdown is intended to be as easy-to-read and easy-to-write as is feasible.

Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it's been marked up with tags or formatting instructions. While Markdown's syntax has been influenced by several existing text-to-HTML filters -- including Setext, atx, Textile, reStructuredText, Grutatext, and EtText -- the single biggest source of inspiration for Markdown's syntax is the format of plain text email.

To this end, Markdown's syntax is comprised entirely of punctuation characters, which punctuation characters have been carefully chosen so as to look like what they mean. E.g., asterisks around a word actually look like *emphasis*. Markdown lists look like, well, lists. Even blockquotes look like quoted passages of text, assuming you've ever used email.

Inline HTML

Markdown's syntax is intended for one purpose: to be used as a format for writing for the web.

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown's formatting syntax only addresses issues that can be conveyed in plain text.

For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags.

The only restrictions are that block-level HTML elements -- e.g. <div>, <table>, <pre>, <p>, etc. -- must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) <p> tags around HTML block-level tags.

For example, to add an HTML table to a Markdown article:

This is a regular paragraph.

<table>
    <tr>
        <td>Foo</td>
    </tr>
</table>

This is another regular paragraph.

Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can't use Markdown-style *emphasis* inside an HTML block.

Span-level HTML tags -- e.g. <span>, <cite>, or <del> -- can be used anywhere in a Markdown paragraph, list item, or header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you'd prefer to use HTML <a> or <img> tags instead of Markdown's link or image syntax, go right ahead.

Unlike block-level HTML tags, Markdown syntax is processed within span-level tags.

Automatic Escaping for Special Characters

In HTML, there are two characters that demand special treatment: < and &. Left angle brackets are used to start tags; ampersands are used to denote HTML entities. If you want to use them as literal characters, you must escape them as entities, e.g. <, and &.

Ampersands in particular are bedeviling for web writers. If you want to write about 'AT&T', you need to write 'AT&T'. You even need to escape ampersands within URLs. Thus, if you want to link to:

http://images.google.com/images?num=30&q=larry+bird

you need to encode the URL as:

http://images.google.com/images?num=30&q=larry+bird

in your anchor tag href attribute. Needless to say, this is easy to forget, and is probably the single most common source of HTML validation errors in otherwise well-marked-up web sites.

Markdown allows you to use these characters naturally, taking care of all the necessary escaping for you. If you use an ampersand as part of an HTML entity, it remains unchanged; otherwise it will be translated into &.

So, if you want to include a copyright symbol in your article, you can write:

©

and Markdown will leave it alone. But if you write:

AT&T

Markdown will translate it to:

AT&T

Similarly, because Markdown supports inline HTML, if you use angle brackets as delimiters for HTML tags, Markdown will treat them as such. But if you write:

4 < 5

Markdown will translate it to:

4 < 5

However, inside Markdown code spans and blocks, angle brackets and ampersands are always encoded automatically. This makes it easy to use Markdown to write about HTML code. (As opposed to raw HTML, which is a terrible format for writing about HTML syntax, because every single < and & in your example code needs to be escaped.)


Block Elements

Paragraphs and Line Breaks

A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.

The implication of the "one or more consecutive lines of text" rule is that Markdown supports "hard-wrapped" text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type's "Convert Line Breaks" option) which translate every line break character in a paragraph into a <br /> tag.

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Yes, this takes a tad more effort to create a <br />, but a simplistic "every line break is a <br />" rule wouldn't work for Markdown. Markdown's email-style blockquoting and multi-paragraph list items work best -- and look better -- when you format them with hard breaks.

Horizontal Rules

You can produce a horizontal rule tag (<hr />) by placing three or more hyphens, asterisks, or underscores on a line by themselves. If you wish, you may use spaces between the hyphens or asterisks. Each of the following lines will produce a horizontal rule:

* * *

***

*****

- - -

---------------------------------------

Span Elements

Markdown supports two style of links: inline and reference.

In both styles, the link text is delimited by [square brackets].

To create an inline link, use a set of regular parentheses immediately after the link text's closing square bracket. Inside the parentheses, put the URL where you want the link to point, along with an optional title for the link, surrounded in quotes. For example:

This is [an example](http://example.com/ "Title") inline link.

[This link](http://example.net/) has no title attribute.

Will produce:

<p>This is <a href="http://example.com/" title="Title">
an example</a> inline link.</p>

<p><a href="http://example.net/">This link</a> has no
title attribute.</p>

If you're referring to a local resource on the same server, you can use relative paths:

See my [About](/about/) page for details.

Reference-style links use a second set of square brackets, inside which you place a label of your choosing to identify the link:

This is [an example][id] reference-style link.

You can optionally use a space to separate the sets of brackets:

This is [an example] [id] reference-style link.

Then, anywhere in the document, you define your link label like this, on a line by itself:

[id]: http://example.com/  "Optional Title Here"

That is:

  • Square brackets containing the link identifier (optionally indented from the left margin using up to three spaces);
  • followed by a colon;
  • followed by one or more spaces (or tabs);
  • followed by the URL for the link;
  • optionally followed by a title attribute for the link, enclosed in double or single quotes, or enclosed in parentheses.

The following three link definitions are equivalent:

[foo]: http://example.com/  "Optional Title Here"
[foo]: http://example.com/  'Optional Title Here'
[foo]: http://example.com/  (Optional Title Here)

Note: There is a known bug in Markdown.pl 1.0.1 which prevents single quotes from being used to delimit link titles.

The link URL may, optionally, be surrounded by angle brackets:

[id]: <http://example.com/>  "Optional Title Here"

You can put the title attribute on the next line and use extra spaces or tabs for padding, which tends to look better with longer URLs:

[id]: http://example.com/longish/path/to/resource/here
    "Optional Title Here"

Link definitions are only used for creating links during Markdown processing, and are stripped from your document in the HTML output.

Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are not case sensitive. E.g. these two links:

[link text][a]
[link text][A]

are equivalent.

The implicit link name shortcut allows you to omit the name of the link, in which case the link text itself is used as the name. Just use an empty set of square brackets -- e.g., to link the word "Google" to the google.com web site, you could simply write:

[Google][]

And then define the link:

[Google]: http://google.com/

Because link names may contain spaces, this shortcut even works for multiple words in the link text:

Visit [Daring Fireball][] for more information.

And then define the link:

[Daring Fireball]: http://daringfireball.net/

Link definitions can be placed anywhere in your Markdown document. I tend to put them immediately after each paragraph in which they're used, but if you want, you can put them all at the end of your document, sort of like footnotes.

Here's an example of reference links in action:

I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].

  [1]: http://google.com/        "Google"
  [2]: http://search.yahoo.com/  "Yahoo Search"
  [3]: http://search.msn.com/    "MSN Search"

Using the implicit link name shortcut, you could instead write:

I get 10 times more traffic from [Google][] than from
[Yahoo][] or [MSN][].

  [google]: http://google.com/        "Google"
  [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
  [msn]:    http://search.msn.com/    "MSN Search"

Both of the above examples will produce the following HTML output:

<p>I get 10 times more traffic from <a href="http://google.com/"
title="Google">Google</a> than from
<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>

For comparison, here is the same paragraph written using Markdown's inline link style:

I get 10 times more traffic from [Google](http://google.com/ "Google")
than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
[MSN](http://search.msn.com/ "MSN Search").

The point of reference-style links is not that they're easier to write. The point is that with reference-style links, your document source is vastly more readable. Compare the above examples: using reference-style links, the paragraph itself is only 81 characters long; with inline-style links, it's 176 characters; and as raw HTML, it's 234 characters. In the raw HTML, there's more markup than there is text.

With Markdown's reference-style links, a source document much more closely resembles the final output, as rendered in a browser. By allowing you to move the markup-related metadata out of the paragraph, you can add links without interrupting the narrative flow of your prose.

Emphasis

Markdown treats asterisks (*) and underscores (_) as indicators of emphasis. Text wrapped with one * or _ will be wrapped with an HTML <em> tag; double *'s or _'s will be wrapped with an HTML <strong> tag. E.g., this input:

*single asterisks*

_single underscores_

**double asterisks**

__double underscores__

will produce:

<em>single asterisks</em>

<em>single underscores</em>

<strong>double asterisks</strong>

<strong>double underscores</strong>

You can use whichever style you prefer; the lone restriction is that the same character must be used to open and close an emphasis span.

Emphasis can be used in the middle of a word:

un*fucking*believable

But if you surround an * or _ with spaces, it'll be treated as a literal asterisk or underscore.

To produce a literal asterisk or underscore at a position where it would otherwise be used as an emphasis delimiter, you can backslash escape it:

\*this text is surrounded by literal asterisks\*

Code

To indicate a span of code, wrap it with backtick quotes (`). Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example:

Use the `printf()` function.

will produce:

<p>Use the <code>printf()</code> function.</p>

To include a literal backtick character within a code span, you can use multiple backticks as the opening and closing delimiters:

``There is a literal backtick (`) here.``

which will produce this:

<p><code>There is a literal backtick (`) here.</code></p>

The backtick delimiters surrounding a code span may include spaces -- one after the opening, one before the closing. This allows you to place literal backtick characters at the beginning or end of a code span:

A single backtick in a code span: `` ` ``

A backtick-delimited string in a code span: `` `foo` ``

will produce:

<p>A single backtick in a code span: <code>`</code></p>

<p>A backtick-delimited string in a code span: <code>`foo`</code></p>

With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags. Markdown will turn this:

Please don't use any `<blink>` tags.

into:

<p>Please don't use any <code><blink></code> tags.</p>

You can write this:

`—` is the decimal-encoded equivalent of `—`.

to produce:

<p><code>&#8212;</code> is the decimal-encoded
equivalent of <code>&mdash;</code>.</p>

Images

Admittedly, it's fairly difficult to devise a "natural" syntax for placing images into a plain text document format.

Markdown uses an image syntax that is intended to resemble the syntax for links, allowing for two styles: inline and reference.

Inline image syntax looks like this:

![Alt text](/path/to/img.jpg)

![Alt text](/path/to/img.jpg "Optional title")

That is:

  • An exclamation mark: !;
  • followed by a set of square brackets, containing the alt attribute text for the image;
  • followed by a set of parentheses, containing the URL or path to the image, and an optional title attribute enclosed in double or single quotes.

Reference-style image syntax looks like this:

![Alt text][id]

Where "id" is the name of a defined image reference. Image references are defined using syntax identical to link references:

[id]: url/to/image  "Optional title attribute"

As of this writing, Markdown has no syntax for specifying the dimensions of an image; if this is important to you, you can simply use regular HTML <img> tags.


Miscellaneous

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:

<http://example.com/>

Markdown will turn this into:

<a href="http://example.com/">http://example.com/</a>

Automatic links for email addresses work similarly, except that Markdown will also perform a bit of randomized decimal and hex entity-encoding to help obscure your address from address-harvesting spambots. For example, Markdown will turn this:

<address@example.com>

into something like this:

<a href="mailto:addre
ss@example.co
m">address@exa
mple.com</a>

which will render in a browser as a clickable link to "address@example.com".

(This sort of entity-encoding trick will indeed fool many, if not most, address-harvesting bots, but it definitely won't fool all of them. It's better than nothing, but an address published in this way will probably eventually start receiving spam.)

Backslash Escapes

Markdown allows you to use backslash escapes to generate literal characters which would otherwise have special meaning in Markdown's formatting syntax. For example, if you wanted to surround a word with literal asterisks (instead of an HTML <em> tag), you can backslashes before the asterisks, like this:

\*literal asterisks\*

Markdown provides backslash escapes for the following characters:

\   backslash
`   backtick
*   asterisk
_   underscore
{}  curly braces
[]  square brackets
()  parentheses
#   hash mark
+   plus sign
-   minus sign (hyphen)
.   dot
!   exclamation mark