You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

specs.md 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. Markdown: Syntax
  2. ================
  3. <ul id="ProjectSubmenu">
  4. <li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
  5. <li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
  6. <li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
  7. <li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
  8. <li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
  9. </ul>
  10. * [Overview](#overview)
  11. * [Philosophy](#philosophy)
  12. * [Inline HTML](#html)
  13. * [Automatic Escaping for Special Characters](#autoescape)
  14. * [Block Elements](#block)
  15. * [Paragraphs and Line Breaks](#p)
  16. * [Headers](#header)
  17. * [Blockquotes](#blockquote)
  18. * [Lists](#list)
  19. * [Code Blocks](#precode)
  20. * [Horizontal Rules](#hr)
  21. * [Span Elements](#span)
  22. * [Links](#link)
  23. * [Emphasis](#em)
  24. * [Code](#code)
  25. * [Images](#img)
  26. * [Miscellaneous](#misc)
  27. * [Backslash Escapes](#backslash)
  28. * [Automatic Links](#autolink)
  29. **Note:** This document is itself written using Markdown; you
  30. can [see the source for it by adding '.text' to the URL][src].
  31. [src]: /projects/markdown/syntax.text
  32. * * *
  33. <h2 id="overview">Overview</h2>
  34. <h3 id="philosophy">Philosophy</h3>
  35. Markdown is intended to be as easy-to-read and easy-to-write as is feasible.
  36. Readability, however, is emphasized above all else. A Markdown-formatted
  37. document should be publishable as-is, as plain text, without looking
  38. like it's been marked up with tags or formatting instructions. While
  39. Markdown's syntax has been influenced by several existing text-to-HTML
  40. filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4],
  41. [Grutatext] [5], and [EtText] [6] -- the single biggest source of
  42. inspiration for Markdown's syntax is the format of plain text email.
  43. [1]: http://docutils.sourceforge.net/mirror/setext.html
  44. [2]: http://www.aaronsw.com/2002/atx/
  45. [3]: http://textism.com/tools/textile/
  46. [4]: http://docutils.sourceforge.net/rst.html
  47. [5]: http://www.triptico.com/software/grutatxt.html
  48. [6]: http://ettext.taint.org/doc/
  49. To this end, Markdown's syntax is comprised entirely of punctuation
  50. characters, which punctuation characters have been carefully chosen so
  51. as to look like what they mean. E.g., asterisks around a word actually
  52. look like \*emphasis\*. Markdown lists look like, well, lists. Even
  53. blockquotes look like quoted passages of text, assuming you've ever
  54. used email.
  55. <h3 id="html">Inline HTML</h3>
  56. Markdown's syntax is intended for one purpose: to be used as a
  57. format for *writing* for the web.
  58. Markdown is not a replacement for HTML, or even close to it. Its
  59. syntax is very small, corresponding only to a very small subset of
  60. HTML tags. The idea is *not* to create a syntax that makes it easier
  61. to insert HTML tags. In my opinion, HTML tags are already easy to
  62. insert. The idea for Markdown is to make it easy to read, write, and
  63. edit prose. HTML is a *publishing* format; Markdown is a *writing*
  64. format. Thus, Markdown's formatting syntax only addresses issues that
  65. can be conveyed in plain text.
  66. For any markup that is not covered by Markdown's syntax, you simply
  67. use HTML itself. There's no need to preface it or delimit it to
  68. indicate that you're switching from Markdown to HTML; you just use
  69. the tags.
  70. The only restrictions are that block-level HTML elements -- e.g. `<div>`,
  71. `<table>`, `<pre>`, `<p>`, etc. -- must be separated from surrounding
  72. content by blank lines, and the start and end tags of the block should
  73. not be indented with tabs or spaces. Markdown is smart enough not
  74. to add extra (unwanted) `<p>` tags around HTML block-level tags.
  75. For example, to add an HTML table to a Markdown article:
  76. This is a regular paragraph.
  77. <table>
  78. <tr>
  79. <td>Foo</td>
  80. </tr>
  81. </table>
  82. This is another regular paragraph.
  83. Note that Markdown formatting syntax is not processed within block-level
  84. HTML tags. E.g., you can't use Markdown-style `*emphasis*` inside an
  85. HTML block.
  86. Span-level HTML tags -- e.g. `<span>`, `<cite>`, or `<del>` -- can be
  87. used anywhere in a Markdown paragraph, list item, or header. If you
  88. want, you can even use HTML tags instead of Markdown formatting; e.g. if
  89. you'd prefer to use HTML `<a>` or `<img>` tags instead of Markdown's
  90. link or image syntax, go right ahead.
  91. Unlike block-level HTML tags, Markdown syntax *is* processed within
  92. span-level tags.
  93. <h3 id="autoescape">Automatic Escaping for Special Characters</h3>
  94. In HTML, there are two characters that demand special treatment: `<`
  95. and `&`. Left angle brackets are used to start tags; ampersands are
  96. used to denote HTML entities. If you want to use them as literal
  97. characters, you must escape them as entities, e.g. `&lt;`, and
  98. `&amp;`.
  99. Ampersands in particular are bedeviling for web writers. If you want to
  100. write about 'AT&T', you need to write '`AT&amp;T`'. You even need to
  101. escape ampersands within URLs. Thus, if you want to link to:
  102. http://images.google.com/images?num=30&q=larry+bird
  103. you need to encode the URL as:
  104. http://images.google.com/images?num=30&amp;q=larry+bird
  105. in your anchor tag `href` attribute. Needless to say, this is easy to
  106. forget, and is probably the single most common source of HTML validation
  107. errors in otherwise well-marked-up web sites.
  108. Markdown allows you to use these characters naturally, taking care of
  109. all the necessary escaping for you. If you use an ampersand as part of
  110. an HTML entity, it remains unchanged; otherwise it will be translated
  111. into `&amp;`.
  112. So, if you want to include a copyright symbol in your article, you can write:
  113. &copy;
  114. and Markdown will leave it alone. But if you write:
  115. AT&T
  116. Markdown will translate it to:
  117. AT&amp;T
  118. Similarly, because Markdown supports [inline HTML](#html), if you use
  119. angle brackets as delimiters for HTML tags, Markdown will treat them as
  120. such. But if you write:
  121. 4 < 5
  122. Markdown will translate it to:
  123. 4 &lt; 5
  124. However, inside Markdown code spans and blocks, angle brackets and
  125. ampersands are *always* encoded automatically. This makes it easy to use
  126. Markdown to write about HTML code. (As opposed to raw HTML, which is a
  127. terrible format for writing about HTML syntax, because every single `<`
  128. and `&` in your example code needs to be escaped.)
  129. * * *
  130. <h2 id="block">Block Elements</h2>
  131. <h3 id="p">Paragraphs and Line Breaks</h3>
  132. A paragraph is simply one or more consecutive lines of text, separated
  133. by one or more blank lines. (A blank line is any line that looks like a
  134. blank line -- a line containing nothing but spaces or tabs is considered
  135. blank.) Normal paragraphs should not be indented with spaces or tabs.
  136. The implication of the "one or more consecutive lines of text" rule is
  137. that Markdown supports "hard-wrapped" text paragraphs. This differs
  138. significantly from most other text-to-HTML formatters (including Movable
  139. Type's "Convert Line Breaks" option) which translate every line break
  140. character in a paragraph into a `<br />` tag.
  141. When you *do* want to insert a `<br />` break tag using Markdown, you
  142. end a line with two or more spaces, then type return.
  143. Yes, this takes a tad more effort to create a `<br />`, but a simplistic
  144. "every line break is a `<br />`" rule wouldn't work for Markdown.
  145. Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l]
  146. work best -- and look better -- when you format them with hard breaks.
  147. [bq]: #blockquote
  148. [l]: #list
  149. <h3 id="header">Headers</h3>
  150. Markdown supports two styles of headers, [Setext] [1] and [atx] [2].
  151. Setext-style headers are "underlined" using equal signs (for first-level
  152. headers) and dashes (for second-level headers). For example:
  153. This is an H1
  154. =============
  155. This is an H2
  156. -------------
  157. Any number of underlining `=`'s or `-`'s will work.
  158. Atx-style headers use 1-6 hash characters at the start of the line,
  159. corresponding to header levels 1-6. For example:
  160. # This is an H1
  161. ## This is an H2
  162. ###### This is an H6
  163. Optionally, you may "close" atx-style headers. This is purely
  164. cosmetic -- you can use this if you think it looks better. The
  165. closing hashes don't even need to match the number of hashes
  166. used to open the header. (The number of opening hashes
  167. determines the header level.) :
  168. # This is an H1 #
  169. ## This is an H2 ##
  170. ### This is an H3 ######
  171. <h3 id="blockquote">Blockquotes</h3>
  172. Markdown uses email-style `>` characters for blockquoting. If you're
  173. familiar with quoting passages of text in an email message, then you
  174. know how to create a blockquote in Markdown. It looks best if you hard
  175. wrap the text and put a `>` before every line:
  176. > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
  177. > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
  178. > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
  179. >
  180. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
  181. > id sem consectetuer libero luctus adipiscing.
  182. Markdown allows you to be lazy and only put the `>` before the first
  183. line of a hard-wrapped paragraph:
  184. > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
  185. consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
  186. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
  187. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
  188. id sem consectetuer libero luctus adipiscing.
  189. Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
  190. adding additional levels of `>`:
  191. > This is the first level of quoting.
  192. >
  193. > > This is nested blockquote.
  194. >
  195. > Back to the first level.
  196. Blockquotes can contain other Markdown elements, including headers, lists,
  197. and code blocks:
  198. > ## This is a header.
  199. >
  200. > 1. This is the first list item.
  201. > 2. This is the second list item.
  202. >
  203. > Here's some example code:
  204. >
  205. > return shell_exec("echo $input | $markdown_script");
  206. Any decent text editor should make email-style quoting easy. For
  207. example, with BBEdit, you can make a selection and choose Increase
  208. Quote Level from the Text menu.
  209. <h3 id="list">Lists</h3>
  210. Markdown supports ordered (numbered) and unordered (bulleted) lists.
  211. Unordered lists use asterisks, pluses, and hyphens -- interchangably
  212. -- as list markers:
  213. * Red
  214. * Green
  215. * Blue
  216. is equivalent to:
  217. + Red
  218. + Green
  219. + Blue
  220. and:
  221. - Red
  222. - Green
  223. - Blue
  224. Ordered lists use numbers followed by periods:
  225. 1. Bird
  226. 2. McHale
  227. 3. Parish
  228. It's important to note that the actual numbers you use to mark the
  229. list have no effect on the HTML output Markdown produces. The HTML
  230. Markdown produces from the above list is:
  231. <ol>
  232. <li>Bird</li>
  233. <li>McHale</li>
  234. <li>Parish</li>
  235. </ol>
  236. If you instead wrote the list in Markdown like this:
  237. 1. Bird
  238. 1. McHale
  239. 1. Parish
  240. or even:
  241. 3. Bird
  242. 1. McHale
  243. 8. Parish
  244. you'd get the exact same HTML output. The point is, if you want to,
  245. you can use ordinal numbers in your ordered Markdown lists, so that
  246. the numbers in your source match the numbers in your published HTML.
  247. But if you want to be lazy, you don't have to.
  248. If you do use lazy list numbering, however, you should still start the
  249. list with the number 1. At some point in the future, Markdown may support
  250. starting ordered lists at an arbitrary number.
  251. List markers typically start at the left margin, but may be indented by
  252. up to three spaces. List markers must be followed by one or more spaces
  253. or a tab.
  254. To make lists look nice, you can wrap items with hanging indents:
  255. * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  256. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
  257. viverra nec, fringilla in, laoreet vitae, risus.
  258. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
  259. Suspendisse id sem consectetuer libero luctus adipiscing.
  260. But if you want to be lazy, you don't have to:
  261. * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  262. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
  263. viverra nec, fringilla in, laoreet vitae, risus.
  264. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
  265. Suspendisse id sem consectetuer libero luctus adipiscing.
  266. If list items are separated by blank lines, Markdown will wrap the
  267. items in `<p>` tags in the HTML output. For example, this input:
  268. * Bird
  269. * Magic
  270. will turn into:
  271. <ul>
  272. <li>Bird</li>
  273. <li>Magic</li>
  274. </ul>
  275. But this:
  276. * Bird
  277. * Magic
  278. will turn into:
  279. <ul>
  280. <li><p>Bird</p></li>
  281. <li><p>Magic</p></li>
  282. </ul>
  283. List items may consist of multiple paragraphs. Each subsequent
  284. paragraph in a list item must be indented by either 4 spaces
  285. or one tab:
  286. 1. This is a list item with two paragraphs. Lorem ipsum dolor
  287. sit amet, consectetuer adipiscing elit. Aliquam hendrerit
  288. mi posuere lectus.
  289. Vestibulum enim wisi, viverra nec, fringilla in, laoreet
  290. vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
  291. sit amet velit.
  292. 2. Suspendisse id sem consectetuer libero luctus adipiscing.
  293. It looks nice if you indent every line of the subsequent
  294. paragraphs, but here again, Markdown will allow you to be
  295. lazy:
  296. * This is a list item with two paragraphs.
  297. This is the second paragraph in the list item. You're
  298. only required to indent the first line. Lorem ipsum dolor
  299. sit amet, consectetuer adipiscing elit.
  300. * Another item in the same list.
  301. To put a blockquote within a list item, the blockquote's `>`
  302. delimiters need to be indented:
  303. * A list item with a blockquote:
  304. > This is a blockquote
  305. > inside a list item.
  306. To put a code block within a list item, the code block needs
  307. to be indented *twice* -- 8 spaces or two tabs:
  308. * A list item with a code block:
  309. <code goes here>
  310. It's worth noting that it's possible to trigger an ordered list by
  311. accident, by writing something like this:
  312. 1986. What a great season.
  313. In other words, a *number-period-space* sequence at the beginning of a
  314. line. To avoid this, you can backslash-escape the period:
  315. 1986\. What a great season.
  316. <h3 id="precode">Code Blocks</h3>
  317. Pre-formatted code blocks are used for writing about programming or
  318. markup source code. Rather than forming normal paragraphs, the lines
  319. of a code block are interpreted literally. Markdown wraps a code block
  320. in both `<pre>` and `<code>` tags.
  321. To produce a code block in Markdown, simply indent every line of the
  322. block by at least 4 spaces or 1 tab. For example, given this input:
  323. This is a normal paragraph:
  324. This is a code block.
  325. Markdown will generate:
  326. <p>This is a normal paragraph:</p>
  327. <pre><code>This is a code block.
  328. </code></pre>
  329. One level of indentation -- 4 spaces or 1 tab -- is removed from each
  330. line of the code block. For example, this:
  331. Here is an example of AppleScript:
  332. tell application "Foo"
  333. beep
  334. end tell
  335. will turn into:
  336. <p>Here is an example of AppleScript:</p>
  337. <pre><code>tell application "Foo"
  338. beep
  339. end tell
  340. </code></pre>
  341. A code block continues until it reaches a line that is not indented
  342. (or the end of the article).
  343. Within a code block, ampersands (`&`) and angle brackets (`<` and `>`)
  344. are automatically converted into HTML entities. This makes it very
  345. easy to include example HTML source code using Markdown -- just paste
  346. it and indent it, and Markdown will handle the hassle of encoding the
  347. ampersands and angle brackets. For example, this:
  348. <div class="footer">
  349. &copy; 2004 Foo Corporation
  350. </div>
  351. will turn into:
  352. <pre><code>&lt;div class="footer"&gt;
  353. &amp;copy; 2004 Foo Corporation
  354. &lt;/div&gt;
  355. </code></pre>
  356. Regular Markdown syntax is not processed within code blocks. E.g.,
  357. asterisks are just literal asterisks within a code block. This means
  358. it's also easy to use Markdown to write about Markdown's own syntax.
  359. <h3 id="hr">Horizontal Rules</h3>
  360. You can produce a horizontal rule tag (`<hr />`) by placing three or
  361. more hyphens, asterisks, or underscores on a line by themselves. If you
  362. wish, you may use spaces between the hyphens or asterisks. Each of the
  363. following lines will produce a horizontal rule:
  364. * * *
  365. ***
  366. *****
  367. - - -
  368. ---------------------------------------
  369. _ _ _
  370. * * *
  371. <h2 id="span">Span Elements</h2>
  372. <h3 id="link">Links</h3>
  373. Markdown supports two style of links: *inline* and *reference*.
  374. In both styles, the link text is delimited by [square brackets].
  375. To create an inline link, use a set of regular parentheses immediately
  376. after the link text's closing square bracket. Inside the parentheses,
  377. put the URL where you want the link to point, along with an *optional*
  378. title for the link, surrounded in quotes. For example:
  379. This is [an example](http://example.com/ "Title") inline link.
  380. [This link](http://example.net/) has no title attribute.
  381. Will produce:
  382. <p>This is <a href="http://example.com/" title="Title">
  383. an example</a> inline link.</p>
  384. <p><a href="http://example.net/">This link</a> has no
  385. title attribute.</p>
  386. If you're referring to a local resource on the same server, you can
  387. use relative paths:
  388. See my [About](/about/) page for details.
  389. Reference-style links use a second set of square brackets, inside
  390. which you place a label of your choosing to identify the link:
  391. This is [an example][id] reference-style link.
  392. You can optionally use a space to separate the sets of brackets:
  393. This is [an example] [id] reference-style link.
  394. Then, anywhere in the document, you define your link label like this,
  395. on a line by itself:
  396. [id]: http://example.com/ "Optional Title Here"
  397. That is:
  398. * Square brackets containing the link identifier (optionally
  399. indented from the left margin using up to three spaces);
  400. * followed by a colon;
  401. * followed by one or more spaces (or tabs);
  402. * followed by the URL for the link;
  403. * optionally followed by a title attribute for the link, enclosed
  404. in double or single quotes, or enclosed in parentheses.
  405. The following three link definitions are equivalent:
  406. [foo]: http://example.com/ "Optional Title Here"
  407. [foo]: http://example.com/ 'Optional Title Here'
  408. [foo]: http://example.com/ (Optional Title Here)
  409. **Note:** There is a known bug in Markdown.pl 1.0.1 which prevents
  410. single quotes from being used to delimit link titles.
  411. The link URL may, optionally, be surrounded by angle brackets:
  412. [id]: <http://example.com/> "Optional Title Here"
  413. You can put the title attribute on the next line and use extra spaces
  414. or tabs for padding, which tends to look better with longer URLs:
  415. [id]: http://example.com/longish/path/to/resource/here
  416. "Optional Title Here"
  417. Link definitions are only used for creating links during Markdown
  418. processing, and are stripped from your document in the HTML output.
  419. Link definition names may consist of letters, numbers, spaces, and
  420. punctuation -- but they are *not* case sensitive. E.g. these two
  421. links:
  422. [link text][a]
  423. [link text][A]
  424. are equivalent.
  425. The *implicit link name* shortcut allows you to omit the name of the
  426. link, in which case the link text itself is used as the name.
  427. Just use an empty set of square brackets -- e.g., to link the word
  428. "Google" to the google.com web site, you could simply write:
  429. [Google][]
  430. And then define the link:
  431. [Google]: http://google.com/
  432. Because link names may contain spaces, this shortcut even works for
  433. multiple words in the link text:
  434. Visit [Daring Fireball][] for more information.
  435. And then define the link:
  436. [Daring Fireball]: http://daringfireball.net/
  437. Link definitions can be placed anywhere in your Markdown document. I
  438. tend to put them immediately after each paragraph in which they're
  439. used, but if you want, you can put them all at the end of your
  440. document, sort of like footnotes.
  441. Here's an example of reference links in action:
  442. I get 10 times more traffic from [Google] [1] than from
  443. [Yahoo] [2] or [MSN] [3].
  444. [1]: http://google.com/ "Google"
  445. [2]: http://search.yahoo.com/ "Yahoo Search"
  446. [3]: http://search.msn.com/ "MSN Search"
  447. Using the implicit link name shortcut, you could instead write:
  448. I get 10 times more traffic from [Google][] than from
  449. [Yahoo][] or [MSN][].
  450. [google]: http://google.com/ "Google"
  451. [yahoo]: http://search.yahoo.com/ "Yahoo Search"
  452. [msn]: http://search.msn.com/ "MSN Search"
  453. Both of the above examples will produce the following HTML output:
  454. <p>I get 10 times more traffic from <a href="http://google.com/"
  455. title="Google">Google</a> than from
  456. <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
  457. or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
  458. For comparison, here is the same paragraph written using
  459. Markdown's inline link style:
  460. I get 10 times more traffic from [Google](http://google.com/ "Google")
  461. than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
  462. [MSN](http://search.msn.com/ "MSN Search").
  463. The point of reference-style links is not that they're easier to
  464. write. The point is that with reference-style links, your document
  465. source is vastly more readable. Compare the above examples: using
  466. reference-style links, the paragraph itself is only 81 characters
  467. long; with inline-style links, it's 176 characters; and as raw HTML,
  468. it's 234 characters. In the raw HTML, there's more markup than there
  469. is text.
  470. With Markdown's reference-style links, a source document much more
  471. closely resembles the final output, as rendered in a browser. By
  472. allowing you to move the markup-related metadata out of the paragraph,
  473. you can add links without interrupting the narrative flow of your
  474. prose.
  475. <h3 id="em">Emphasis</h3>
  476. Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
  477. emphasis. Text wrapped with one `*` or `_` will be wrapped with an
  478. HTML `<em>` tag; double `*`'s or `_`'s will be wrapped with an HTML
  479. `<strong>` tag. E.g., this input:
  480. *single asterisks*
  481. _single underscores_
  482. **double asterisks**
  483. __double underscores__
  484. will produce:
  485. <em>single asterisks</em>
  486. <em>single underscores</em>
  487. <strong>double asterisks</strong>
  488. <strong>double underscores</strong>
  489. You can use whichever style you prefer; the lone restriction is that
  490. the same character must be used to open and close an emphasis span.
  491. Emphasis can be used in the middle of a word:
  492. un*frigging*believable
  493. But if you surround an `*` or `_` with spaces, it'll be treated as a
  494. literal asterisk or underscore.
  495. To produce a literal asterisk or underscore at a position where it
  496. would otherwise be used as an emphasis delimiter, you can backslash
  497. escape it:
  498. \*this text is surrounded by literal asterisks\*
  499. <h3 id="code">Code</h3>
  500. To indicate a span of code, wrap it with backtick quotes (`` ` ``).
  501. Unlike a pre-formatted code block, a code span indicates code within a
  502. normal paragraph. For example:
  503. Use the `printf()` function.
  504. will produce:
  505. <p>Use the <code>printf()</code> function.</p>
  506. To include a literal backtick character within a code span, you can use
  507. multiple backticks as the opening and closing delimiters:
  508. ``There is a literal backtick (`) here.``
  509. which will produce this:
  510. <p><code>There is a literal backtick (`) here.</code></p>
  511. The backtick delimiters surrounding a code span may include spaces --
  512. one after the opening, one before the closing. This allows you to place
  513. literal backtick characters at the beginning or end of a code span:
  514. A single backtick in a code span: `` ` ``
  515. A backtick-delimited string in a code span: `` `foo` ``
  516. will produce:
  517. <p>A single backtick in a code span: <code>`</code></p>
  518. <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
  519. With a code span, ampersands and angle brackets are encoded as HTML
  520. entities automatically, which makes it easy to include example HTML
  521. tags. Markdown will turn this:
  522. Please don't use any `<blink>` tags.
  523. into:
  524. <p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
  525. You can write this:
  526. `&#8212;` is the decimal-encoded equivalent of `&mdash;`.
  527. to produce:
  528. <p><code>&amp;#8212;</code> is the decimal-encoded
  529. equivalent of <code>&amp;mdash;</code>.</p>
  530. <h3 id="img">Images</h3>
  531. Admittedly, it's fairly difficult to devise a "natural" syntax for
  532. placing images into a plain text document format.
  533. Markdown uses an image syntax that is intended to resemble the syntax
  534. for links, allowing for two styles: *inline* and *reference*.
  535. Inline image syntax looks like this:
  536. ![Alt text](/path/to/img.jpg)
  537. ![Alt text](/path/to/img.jpg "Optional title")
  538. That is:
  539. * An exclamation mark: `!`;
  540. * followed by a set of square brackets, containing the `alt`
  541. attribute text for the image;
  542. * followed by a set of parentheses, containing the URL or path to
  543. the image, and an optional `title` attribute enclosed in double
  544. or single quotes.
  545. Reference-style image syntax looks like this:
  546. ![Alt text][id]
  547. Where "id" is the name of a defined image reference. Image references
  548. are defined using syntax identical to link references:
  549. [id]: url/to/image "Optional title attribute"
  550. As of this writing, Markdown has no syntax for specifying the
  551. dimensions of an image; if this is important to you, you can simply
  552. use regular HTML `<img>` tags.
  553. * * *
  554. <h2 id="misc">Miscellaneous</h2>
  555. <h3 id="autolink">Automatic Links</h3>
  556. 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:
  557. <http://example.com/>
  558. Markdown will turn this into:
  559. <a href="http://example.com/">http://example.com/</a>
  560. Automatic links for email addresses work similarly, except that
  561. Markdown will also perform a bit of randomized decimal and hex
  562. entity-encoding to help obscure your address from address-harvesting
  563. spambots. For example, Markdown will turn this:
  564. <address@example.com>
  565. into something like this:
  566. <a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
  567. &#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
  568. &#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
  569. &#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
  570. which will render in a browser as a clickable link to "address@example.com".
  571. (This sort of entity-encoding trick will indeed fool many, if not
  572. most, address-harvesting bots, but it definitely won't fool all of
  573. them. It's better than nothing, but an address published in this way
  574. will probably eventually start receiving spam.)
  575. <h3 id="backslash">Backslash Escapes</h3>
  576. Markdown allows you to use backslash escapes to generate literal
  577. characters which would otherwise have special meaning in Markdown's
  578. formatting syntax. For example, if you wanted to surround a word
  579. with literal asterisks (instead of an HTML `<em>` tag), you can use
  580. backslashes before the asterisks, like this:
  581. \*literal asterisks\*
  582. Markdown provides backslash escapes for the following characters:
  583. \ backslash
  584. ` backtick
  585. * asterisk
  586. _ underscore
  587. {} curly braces
  588. [] square brackets
  589. () parentheses
  590. # hash mark
  591. + plus sign
  592. - minus sign (hyphen)
  593. . dot
  594. ! exclamation mark