syntax.text 27 KB

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