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.

718 lines
31KB

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