作者:无名 - 其它综合 -

markdown: syntax

  • main
  • basics
  • syntax
  • license
  • dingus
  • overview
    • philosophy
    • inline html
    • automatic escaping for special characters
  • block elements
    • paragraphs and line breaks
    • headers
    • blockquotes
    • lists
    • code blocks
    • horizontal rules
  • span elements
    • links
    • emphasis
    • code
    • images
  • miscellaneous
    • backslash escapes
    • automatic links

note: this document is itself written using markdown; you
can see the source for it by adding ‘.text‘ to the url.



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] 1, [atx] 2, [textile] 3, [restructuredtext] 4,
[grutatext] 5, and [ettext] 6 -- 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. lt;pgt;,
lt;tablegt;, lt;pregt;, lt;pgt;, 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) lt;pgt; tags around html block-level tags.

for example, to add an html table to a markdown article:

this is a regular paragraph.


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. lt;spangt;, lt;citegt;, or lt;delgt; -- 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 lt;agt; or lt;imggt; 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: lt;
and amp;. 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. amp;lt;, and

ampersands in particular are bedeviling for web writers. if you want to
write about ‘atamp;t‘, you need to write ‘atamp;amp;t‘. you even need to
escape ampersands within urls. thus, if you want to link to:;q=larry+bird

you need to encode the url as:;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;amp;.

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:


markdown will translate it to:


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 lt; 5

markdown will translate it to:

4 amp;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 lt;
and amp; 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 lt;br /gt; tag.

when you do want to insert a lt;br /gt; 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 lt;br /gt;, but a simplistic
every line break is a lt;br /gt; 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] 1 and [atx] 2.

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 ######


markdown uses email-style gt; 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 gt; before every line:

gt; this is a blockquote with two paragraphs. lorem ipsum dolor sit amet,
gt; consectetuer adipiscing elit. aliquam hendrerit mi posuere lectus.
gt; vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
gt; donec sit amet nisl. aliquam semper ipsum sit amet velit. suspendisse
gt; id sem consectetuer libero luctus adipiscing.

markdown allows you to be lazy and only put the gt; before the first
line of a hard-wrapped paragraph:

gt; 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.

gt; 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 gt;:

gt; this is the first level of quoting.
gt; gt; this is nested blockquote.
gt; back to the first level.

blockquotes can contain other markdown elements, including headers, lists,
and code blocks:

gt; ## this is a header.
gt; 1.   this is the first list item.
gt; 2.   this is the second list item.
gt; here#39;s some example code:
gt;     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.


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


-   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:


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 lt;pgt; tags in the html output. for example, this input:

*   bird
*   magic

will turn into:


but this:

*   bird

*   magic

will turn into:


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

*   this is a list item with two paragraphs.

    this is the second paragraph in the list item. you#39;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 gt;
delimiters need to be indented:

*   a list item with a blockquote:

    gt; this is a blockquote
    gt; 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:

        lt;code goes heregt;

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 lt;pregt; and lt;codegt; 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:

lt;pgt;this is a normal paragraph:lt;/pgt;

lt;pregt;lt;codegt;this is a code block.

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
    end tell

will turn into:

lt;pgt;here is an example of applescript:lt;/pgt;

lt;pregt;lt;codegt;tell application foo
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 (amp;) and angle brackets (lt; and gt;)
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:

    lt;p class=footergt;
        amp;copy; 2004 foo corporation

will turn into:

lt;pregt;lt;codegt;amp;lt;p class=footeramp;gt;
    amp;amp;copy; 2004 foo corporation

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 (lt;hr /gt;) 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]( title) inline link.

[this link]( has no title attribute.

will produce:

lt;pgt;this is lt;a href= title=titlegt;
an examplelt;/agt; inline;/pgt;

lt;pgt;lt;a href=;this linklt;/agt; has no

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]:  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]:  optional title here
[foo]:  #39;optional title here#39;
[foo]:  (optional title here)

note: there is a known bug in 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]: lt;;  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:

    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

[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 web site, you could simply write:


and then define the link:


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]:

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]:        google
  [2]:  yahoo search
  [3]:    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]:        google
  [yahoo]:  yahoo search
  [msn]:    msn search

both of the above examples will produce the following html output:

lt;pgt;i get 10 times more traffic from lt;a href=
title=googlegt;googlelt;/agt; than from
lt;a href= title=yahoo searchgt;yahoolt;/agt;
or lt;a href= title=msn searchgt;msnlt;/agt;.lt;/pgt;

for comparison, here is the same paragraph written using
markdown‘s inline link style:

i get 10 times more traffic from [google]( google)
than from [yahoo]( yahoo search) or
[msn]( 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


markdown treats asterisks (*) and underscores (_) as indicators of
emphasis. text wrapped with one * or _ will be wrapped with an
html lt;emgt; tag; double *‘s or _‘s will be wrapped with an html
lt;stronggt; tag. e.g., this input:

*single asterisks*

_single underscores_

**double asterisks**

__double underscores__

will produce:

lt;emgt;single asteriskslt;/emgt;

lt;emgt;single underscoreslt;/emgt;

lt;stronggt;double asteriskslt;/stronggt;

lt;stronggt;double underscoreslt;/stronggt;

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:


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\*


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:

lt;pgt;use the lt;codegt;printf()lt;/codegt;;/pgt;

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:

lt;pgt;lt;codegt;there is a literal backtick (`);/codegt;lt;/pgt;

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:

lt;pgt;a single backtick in a code span: lt;codegt;`lt;/codegt;lt;/pgt;

lt;pgt;a backtick-delimited string in a code span: lt;codegt;`foo`lt;/codegt;lt;/pgt;

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#39;t use any `lt;blinkgt;` tags.


lt;pgt;please don#39;t use any lt;codegt;amp;lt;blinkamp;gt;lt;/codegt;;/pgt;

you can write this:

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

to produce:

lt;pgt;lt;codegt;amp;amp;#8212;lt;/codegt; is the decimal-encoded
equivalent of lt;codegt;amp;amp;mdash;lt;/codegt;.lt;/pgt;


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 lt;imggt; tags.


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:


markdown will turn this into:

lt;a href=;;/agt;

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:


into something like this:

lt;a href=amp;#x6d;amp;#x61;iamp;#x6c;amp;#x74;amp;#x6f;:amp;#x61;amp;#x64;amp;#x64;amp;#x72;amp;#x65;

which will render in a browser as a clickable link to [email#160;protected].

(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 lt;emgt; 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

markdown: syntax


这篇内容就是由IT人知识库 小编为各位整理 原文链接:



1,下载nginx镜像 docker pull nginx 2,启动 docker run --name runo ...


前言: wepy小程序项目初始化的操作,官方文档看了好几遍,感觉写得不是很清楚。 这篇写得挺好的:小程序开发之wepy ...


this chapter concerns creating and destorying objects : wh ...


使用elementui时,tree遇到的坑 1、发现,this.$refs每次都是undefined; 问题原因:渲染组 ...


灯泡开关ii 现有一个房间,墙上挂有n只已经打开的灯泡和 4 个按钮。在进行了m次未知操作后,你需要返回这n只灯泡可能有 ...


package main import ( "fmt" "strings" ) //strfunc 字符串说明 ...


1.如何描述c#和.net的关系? .net的是平台,c#是为了微软公司为了.net平台开发的面向对象语言。 2.c# ...


一、re简介   正则表达式是一种对字符串(包括普通字符、非打印字符、通用字符(称为原子)、特殊字符(称为元字符))操作 ...


错误类型 1、语法错误 syntaxerror:代码拼写出错 attributeerror:属性异常 try: ...


在自然世界中,分层无处不在。大到社会阶层,小到细胞层次结构。 为什么会这样?因为复杂的事物组成复杂,完成的功能复杂,把所 ...


jsp九大内置对象 object findattribute(string name):依次在page、request ...


一、赋值对比1、列表l1=[1,2,3] l2=l1 l1.append(#39;a#39;) print(l1,l2) ...


1.概述 1. 必须使用lt;php gt; 或是lt;=gt;这两种标签 2. php代码中必须使用utf-8 wit ...


安装完后却不能运行hadoop,仔细查看日志信息,hadoop记录了详尽的日志信息,日志文件保存在logs文件夹内。 ...


string s = " test "; size_t n = s.find_last_not ...


(3)convert类型转换 1、类型如果相兼容的两个变量,可以使用自动类型转换或者显示类型转换。 但是如果两个类型的变 ...


1.求余 extern double fmod(double,double); fmod(10.2,3) =1.2 ...


adb的全称是android debug bridge,是用来管理模拟器和真机的通用调试工具。   开usb调试 ...


django ==gt; form 组件 目录: 1.基本使用 2.form中字段和插件 3.自定义验证规则 4.动态加 ...


注意:以下都是在mysql目录下的my.ini文件中改写(技术文)。 一、innodb内存优化 innodb用一块内存区 ...