The Great Markdown Test Page

Markdown: Syntax

Note: This document is itself written using Markdown; you
can see the source for it by adding '.text' to the URL.


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.

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.

Headers

Markdown supports two styles of headers, [Setext] [1] and [atx] [2].

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.)

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:

is equivalent to:

and:

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:

If you instead wrote the list in Markdown like this:

  1. Bird
  2. McHale
  3. Parish

or even:

  1. Bird
  2. McHale
  3. 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.

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

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

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:

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.

This is a normal paragraph:

This is a code block.

Here is an example of AppleScript:

tell application "Foo"
beep
end tell

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:

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.

tell application "Foo"
    beep
end tell

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 inline link.

This link has no title attribute.

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

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.


Markdown:语法

注意: 本文档本身就是用 Markdown 编写的;你可以在 URL 后加上 '.text' 来查看其源码。


概述

设计理念

Markdown 的目标是尽可能地易读易写。

其中,可读性被置于最高优先级。一篇 Markdown 格式的文档应该能够直接以纯文本形式发布,而不会让人觉得它被标签或格式指令填满。Markdown 的语法受到了多种现有文本转 HTML 过滤器的影响——包括 SetextatxTextilereStructuredTextGrutatextEtText——但对 Markdown 语法影响最大的灵感来源,是纯文本电子邮件的格式。

块级元素

段落与换行

段落就是由一个或多个连续文本行组成的内容,段落之间由一个或多个空行分隔。(空行指看起来是空的行——只包含空格或制表符的行也被视为空行。)普通段落不应该用空格或制表符缩进。

"一个或多个连续文本行"这条规则意味着 Markdown 支持"硬换行"段落。这与大多数其他文本转 HTML 格式化工具(包括 Movable Type 的"Convert Line Breaks"选项)有显著不同,那些工具会将段落中的每个换行符转换为 <br /> 标签。

如果你_确实_想在 Markdown 中插入 <br /> 换行标签,只需在行尾加上两个或更多空格,然后回车即可。

标题

Markdown 支持两种风格的标题:[Setext][1] 和 [atx][2]。

你也可以选择"闭合" atx 风格的标题,这纯粹是装饰性的——如果你觉得这样看起来更好看,可以这样做。结尾的井号数量甚至不需要与开头的井号数量匹配。(标题级别由开头的井号数量决定。)

引用块

Markdown 使用电子邮件风格的 > 字符来创建引用块。如果你熟悉在邮件中引用段落的方式,那你就知道如何在 Markdown 中创建引用块了。最佳实践是对文本进行硬换行,并在每一行前加上 >

这是一个包含两个段落的引用块。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 也允许你偷懒,只在硬换行段落的第一行前加 >

这是一个包含两个段落的引用块。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 元素,包括标题、列表和代码块:

这是一个标题。

  1. 这是第一个列表项。
  2. 这是第二个列表项。

这是一些示例代码:

return shell_exec("echo $input | $markdown_script");

任何像样的文本编辑器都应该能轻松实现电子邮件风格的引用。例如,在 BBEdit 中,你可以选中文本,然后从 Text 菜单中选择 Increase Quote Level。