Title photo
Ode is simple! (Simple means that you know how it works.)

Hello, and welcome to news.ode-is-simple.com.

This is a weblog dedicated to Ode (ode-is-simple.com) and other topics relevant to the project.

If you're looking for general info about Ode you may want to start at the project homepage at ode.simple.com/home

To stay up to date with the newest news and info related to Ode, subscribe to this site's RSS 2.0 using Google Reader or your preferred feed reader.

Posts

Thu, 22 Apr 2010

Kevin Yank’s JavaScript LIVE (starting April 26th 2010)

Javascript will allow you to greatly expand what you can do w Ode. @sitepointdotcom offers to teach you in 21 days for $9.95.

Let me list in order the set of skills that will allow you to take maximum advantage of Ode so that you can get the most out of your web site

  1. HTML and CSS
  2. Perl
  3. Javascript
  4. Everything else

Honestly it's hard to say which is more important, Javascript or Perl, because the answer depends on your interests. If you want to write your own Ode addins and contribute to the development of this platform, then you'll want to know Perl. If you're more interested in adding interactive behaviors to your site then Javascript may be what you want. Both Perl and Javascript are useful beyond Ode.

Read the rest of this post

O'Reilly Earth Day ebook sale 2010 (buy 1 get 1 free)

Buy 1 get 1 free ebooks from @OReillyMedia until 2010/0430. Pick up Learning Perl along with another book you've wanted.

O'Reilly is offering a buy 1 get 1 free ebook sale through next Friday (April 30, 2010). For every ebook you buy they will give you one for free with no limit on the total number of books you can buy (buy 2 get 2, buy 3 get 3, ..., buy 50 get 50). This beats their standing Buy 2 get 1 free offer (code OPC10).

Read the rest of this post

Tue, 26 Jan 2010

Friend: ExpanDrive (Mac and Windows)

Friend: ExpanDrive Mac and Windows: 'Ridiculously simple SFTP/FTP/S3 drive access'

I will be describing ExpanDrive for the Mac but there is also a Windows version available.

Before I talk about ExpanDrive I want to be sure to say that there are any number of applications that work much like ExpanDrive. In fact ExpanDrive is based on the open-source MacFuse project and Macfusion is one freely available open-source front-end. There are options available for other platforms as well. (I've already mentioned the Windows version of ExpanDrive.)

The utility allows you to define connections to remote servers (using SFTP, FTP, or Amazon's S3 online storage service) and then mount and access those connections in the same way that you would a locally mounted volume (a volume on a locally attached USB hard drive for example.) This means that you can interact with files on a remote server as you would local files and folders, both in the Finder and other applications. For an Ode user, this means that you can manage your site as if you were working with a collection of files and folder on your computer, without the need to explicitly push anything to the server. It's an intuitive, efficient and elegant solution. What's more because working with an Ode site primarily involves text files, which are relatively small in size, ExpanDrive and Ode work work beautifully together (in terms of responsiveness and performance). ExpanDrive itself seems remarkably fast, in comparison to other, similar products. According to the developers 'the SFTP core' has been rewritten for version 2.0. This means that uploading photos, videos and other media (and even playing these files directly from the mounted volume through ExpanDrive) should be quick and efficient too.

!--jump--!

Other features:

Any connection can be configured to reconnect automatically...

...so that it seems as if the remote drives are always available. From the website

'Our robust networking core ensures that if a connection is available, your drive is available'.

Easy install

Download the .dmg from the website. Mount the disk image (which should happen automatically, or you can double-click the downloaded file). Drag the app itself to the Applications folder.

Configuration is as straightforward as it can be.

Enter your login credentials for the remote server and you're done.

Localizations

According to the website, ExpanDrive is available in: Deutsch, Nederlands, Français, Español, 日本語, 中文, Dansk, Norsk, Svenska, Suomi, Română, Lietuvių kalba, and Tiếng Việt.

If you're interested in ExpanDrive, I recommend taking a look at the short video introduction/demo on the product website.

ExpanDrive is not free, though there are free alternatives. A single user license is not especially cheap at $39.95. There is a 30 day unrestricted demo available.

Sat, 16 Jan 2010

Friend: Sarcastic Robot monospaced handwriting font by Chank Co

There's a lot to like about Sarcastic Robot a monospaced handwriting font by @chankfonts.

As you probably know, I like to say, 'Ode is simple'. More than a promotional tease, 'simple' is an inspiration, and the project's primary design principle.

Among other goals, I hope that keeping Ode simple means blurring the distinction between developer and end user.

Moreover, Ode is intended to allow us to take advantage the capabilities of modern text editors - some of the most sublime (robust, and polished) software applications ever written. With Ode, we use a text editor to manage all aspects of your site(s) (content management, design, and development).

When it comes to writing code, including markup languages like HTML, a monospaced font is your best friend - which is certainly not to suggest that they are not useful for any number of other purposes as well.

!--jump--!

Chank Co, an independent type foundry specializing in 'cool fonts for smart designers and free fonts for instant download' (as well as custom fonts), has a brilliant monospace font called Sarcastic Robot which I highly recommend. It's available now for the bargain price of only $1.99.

It's not going to replace Monaco in terms of utility, but there is a lot to like about it. For all it's zaniness, straight characters are straight, curvy characters are (extra) curvy, and all are easily distinguishable.

Some notes:

Great letter heights (in my opinion)

Doesn't work well at very small size (12 pt is perfectly legible/and plenty small for most purposes)

Character set is western languages only, and (maybe) somewhat limited

sarcastic robot char set

Wed, 14 Jan 2009

Markdown: Syntax

Markdown: Syntax


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. &lt;, and &amp;.

Ampersands in particular are bedeviling for web writers. If you want to write about 'AT&T', you need to write 'AT&amp;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&amp;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 &amp;.

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

&copy;

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

AT&T

Markdown will translate it to:

AT&amp;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 &lt; 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.

Markdown supports two styles of headers, Setext and atx.

Setext-style headers are "underlined" using equal signs (for first-level headers) and dashes (for second-level headers). For example:

This is an H1
=============

This is an H2
-------------

Any number of underlining ='s or -'s will work.

Atx-style headers use 1-6 hash characters at the start of the line, corresponding to header levels 1-6. For example:

# This is an H1

## This is an H2

###### This is an H6

Optionally, you may "close" atx-style headers. This is purely cosmetic -- you can use this if you think it looks better. The closing hashes don't even need to match the number of hashes used to open the header. (The number of opening hashes determines the header level.) :

# This is an H1 #

## This is an H2 ##

### This is an H3 ######

Blockquotes

Markdown uses email-style > characters for blockquoting. If you're familiar with quoting passages of text in an email message, then you know how to create a blockquote in Markdown. It looks best if you hard wrap the text and put a > before every line:

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
> 
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.

Markdown allows you to be lazy and only put the > before the first line of a hard-wrapped paragraph:

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.

Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by adding additional levels of >:

> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.

Blockquotes can contain other Markdown elements, including headers, lists, and code blocks:

> ## This is a header.
> 
> 1.   This is the first list item.
> 2.   This is the second list item.
> 
> Here's some example code:
> 
>     return shell_exec("echo $input | $markdown_script");

Any decent text editor should make email-style quoting easy. For example, with BBEdit, you can make a selection and choose Increase Quote Level from the Text menu.

Lists

Markdown supports ordered (numbered) and unordered (bulleted) lists.

Unordered lists use asterisks, pluses, and hyphens -- interchangably -- as list markers:

*   Red
*   Green
*   Blue

is equivalent to:

+   Red
+   Green
+   Blue

and:

-   Red
-   Green
-   Blue

Ordered lists use numbers followed by periods:

1.  Bird
2.  McHale
3.  Parish

It's important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. The HTML Markdown produces from the above list is:

<ol>
<li>Bird</li>
<li>McHale</li>
<li>Parish</li>
</ol>

If you instead wrote the list in Markdown like this:

1.  Bird
1.  McHale
1.  Parish

or even:

3. Bird
1. McHale
8. Parish

you'd get the exact same HTML output. The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don't have to.

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.

List markers typically start at the left margin, but may be indented by up to three spaces. List markers must be followed by one or more spaces or a tab.

To make lists look nice, you can wrap items with hanging indents:

*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
    viverra nec, fringilla in, laoreet vitae, risus.
*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
    Suspendisse id sem consectetuer libero luctus adipiscing.

But if you want to be lazy, you don't have to:

*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.

If list items are separated by blank lines, Markdown will wrap the items in <p> tags in the HTML output. For example, this input:

*   Bird
*   Magic

will turn into:

<ul>
<li>Bird</li>
<li>Magic</li>
</ul>

But this:

*   Bird

*   Magic

will turn into:

<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>

List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab:

1.  This is a list item with two paragraphs. Lorem ipsum dolor
    sit amet, consectetuer adipiscing elit. Aliquam hendrerit
    mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet
    vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
    sit amet velit.

2.  Suspendisse id sem consectetuer libero luctus adipiscing.

It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy:

*   This is a list item with two paragraphs.

    This is the second paragraph in the list item. You're
only required to indent the first line. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit.

*   Another item in the same list.

To put a blockquote within a list item, the blockquote's > delimiters need to be indented:

*   A list item with a blockquote:

    > This is a blockquote
    > inside a list item.

To put a code block within a list item, the code block needs to be indented twice -- 8 spaces or two tabs:

*   A list item with a code block:

        <code goes here>

It's worth noting that it's possible to trigger an ordered list by accident, by writing something like this:

1986. What a great season.

In other words, a number-period-space sequence at the beginning of a line. To avoid this, you can backslash-escape the period:

1986\. What a great season.

Code Blocks

Pre-formatted code blocks are used for writing about programming or markup source code. Rather than forming normal paragraphs, the lines of a code block are interpreted literally. Markdown wraps a code block in both <pre> and <code> tags.

To produce a code block in Markdown, simply indent every line of the block by at least 4 spaces or 1 tab. For example, given this input:

This is a normal paragraph:

    This is a code block.

Markdown will generate:

<p>This is a normal paragraph:</p>

<pre><code>This is a code block.
</code></pre>

One level of indentation -- 4 spaces or 1 tab -- is removed from each line of the code block. For example, this:

Here is an example of AppleScript:

    tell application "Foo"
        beep
    end tell

will turn into:

<p>Here is an example of AppleScript:</p>

<pre><code>tell application "Foo"
    beep
end tell
</code></pre>

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">
        &copy; 2004 Foo Corporation
    </div>

will turn into:

<pre><code>&lt;div class="footer"&gt;
    &amp;copy; 2004 Foo Corporation
&lt;/div&gt;
</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.

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 consist 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*frigging*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>&lt;blink&gt;</code> tags.</p>

You can write this:

`&#8212;` is the decimal-encoded equivalent of `&mdash;`.

to produce:

<p><code>&amp;#8212;</code> is the decimal-encoded
equivalent of <code>&amp;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="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
&#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
&#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</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 use 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
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