aboutsummaryrefslogtreecommitdiff
path: root/oldtests/Original/Markdown_Documentation_Syntax.html
blob: f379dcf8baba154fe120535a1bf52e3f54d83003 (plain)
  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>
  11. <ul>
  12. <li><a href="#philosophy">Philosophy</a></li>
  13. <li><a href="#html">Inline HTML</a></li>
  14. <li><a href="#autoescape">Automatic Escaping for Special Characters</a></li>
  15. </ul></li>
  16. <li><a href="#block">Block Elements</a>
  17. <ul>
  18. <li><a href="#p">Paragraphs and Line Breaks</a></li>
  19. <li><a href="#header">Headers</a></li>
  20. <li><a href="#blockquote">Blockquotes</a></li>
  21. <li><a href="#list">Lists</a></li>
  22. <li><a href="#precode">Code Blocks</a></li>
  23. <li><a href="#hr">Horizontal Rules</a></li>
  24. </ul></li>
  25. <li><a href="#span">Span Elements</a>
  26. <ul>
  27. <li><a href="#link">Links</a></li>
  28. <li><a href="#em">Emphasis</a></li>
  29. <li><a href="#code">Code</a></li>
  30. <li><a href="#img">Images</a></li>
  31. </ul></li>
  32. <li><a href="#misc">Miscellaneous</a>
  33. <ul>
  34. <li><a href="#backslash">Backslash Escapes</a></li>
  35. <li><a href="#autolink">Automatic Links</a></li>
  36. </ul></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 intended with spaces or tabs.</p>
  146. <p>The implication of the &quot;one or more consecutive lines of text&quot; rule is
  147. that Markdown supports &quot;hard-wrapped&quot; text paragraphs. This differs
  148. significantly from most other text-to-HTML formatters (including Movable
  149. Type's &quot;Convert Line Breaks&quot; 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. &quot;every line break is a <code>&lt;br /&gt;</code>&quot; 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 &quot;underlined&quot; 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 &quot;close&quot; 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(&quot;echo $input | $markdown_script&quot;);
  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 intended 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 &quot;Foo&quot;
  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 &quot;Foo&quot;
  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=&quot;footer&quot;&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=&quot;footer&quot;&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/ &quot;Title&quot;) 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=&quot;http://example.com/&quot; title=&quot;Title&quot;&gt;
  425. an example&lt;/a&gt; inline link.&lt;/p&gt;
  426. &lt;p&gt;&lt;a href=&quot;http://example.net/&quot;&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/ &quot;Optional Title Here&quot;
  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.</li>
  453. </ul>
  454. <p>The link URL may, optionally, be surrounded by angle brackets:</p>
  455. <pre><code>[id]: &lt;http://example.com/&gt; &quot;Optional Title Here&quot;
  456. </code></pre>
  457. <p>You can put the title attribute on the next line and use extra spaces
  458. or tabs for padding, which tends to look better with longer URLs:</p>
  459. <pre><code>[id]: http://example.com/longish/path/to/resource/here
  460. &quot;Optional Title Here&quot;
  461. </code></pre>
  462. <p>Link definitions are only used for creating links during Markdown
  463. processing, and are stripped from your document in the HTML output.</p>
  464. <p>Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are <em>not</em> case sensitive. E.g. these two links:</p>
  465. <pre><code>[link text][a]
  466. [link text][A]
  467. </code></pre>
  468. <p>are equivalent.</p>
  469. <p>The <em>implicit link name</em> shortcut allows you to omit the name of the
  470. link, in which case the link text itself is used as the name.
  471. Just use an empty set of square brackets -- e.g., to link the word
  472. &quot;Google&quot; to the google.com web site, you could simply write:</p>
  473. <pre><code>[Google][]
  474. </code></pre>
  475. <p>And then define the link:</p>
  476. <pre><code>[Google]: http://google.com/
  477. </code></pre>
  478. <p>Because link names may contain spaces, this shortcut even works for
  479. multiple words in the link text:</p>
  480. <pre><code>Visit [Daring Fireball][] for more information.
  481. </code></pre>
  482. <p>And then define the link:</p>
  483. <pre><code>[Daring Fireball]: http://daringfireball.net/
  484. </code></pre>
  485. <p>Link definitions can be placed anywhere in your Markdown document. I
  486. tend to put them immediately after each paragraph in which they're
  487. used, but if you want, you can put them all at the end of your
  488. document, sort of like footnotes.</p>
  489. <p>Here's an example of reference links in action:</p>
  490. <pre><code>I get 10 times more traffic from [Google] [1] than from
  491. [Yahoo] [2] or [MSN] [3].
  492. [1]: http://google.com/ &quot;Google&quot;
  493. [2]: http://search.yahoo.com/ &quot;Yahoo Search&quot;
  494. [3]: http://search.msn.com/ &quot;MSN Search&quot;
  495. </code></pre>
  496. <p>Using the implicit link name shortcut, you could instead write:</p>
  497. <pre><code>I get 10 times more traffic from [Google][] than from
  498. [Yahoo][] or [MSN][].
  499. [google]: http://google.com/ &quot;Google&quot;
  500. [yahoo]: http://search.yahoo.com/ &quot;Yahoo Search&quot;
  501. [msn]: http://search.msn.com/ &quot;MSN Search&quot;
  502. </code></pre>
  503. <p>Both of the above examples will produce the following HTML output:</p>
  504. <pre><code>&lt;p&gt;I get 10 times more traffic from &lt;a href=&quot;http://google.com/&quot;
  505. title=&quot;Google&quot;&gt;Google&lt;/a&gt; than from
  506. &lt;a href=&quot;http://search.yahoo.com/&quot; title=&quot;Yahoo Search&quot;&gt;Yahoo&lt;/a&gt;
  507. or &lt;a href=&quot;http://search.msn.com/&quot; title=&quot;MSN Search&quot;&gt;MSN&lt;/a&gt;.&lt;/p&gt;
  508. </code></pre>
  509. <p>For comparison, here is the same paragraph written using
  510. Markdown's inline link style:</p>
  511. <pre><code>I get 10 times more traffic from [Google](http://google.com/ &quot;Google&quot;)
  512. than from [Yahoo](http://search.yahoo.com/ &quot;Yahoo Search&quot;) or
  513. [MSN](http://search.msn.com/ &quot;MSN Search&quot;).
  514. </code></pre>
  515. <p>The point of reference-style links is not that they're easier to
  516. write. The point is that with reference-style links, your document
  517. source is vastly more readable. Compare the above examples: using
  518. reference-style links, the paragraph itself is only 81 characters
  519. long; with inline-style links, it's 176 characters; and as raw HTML,
  520. it's 234 characters. In the raw HTML, there's more markup than there
  521. is text.</p>
  522. <p>With Markdown's reference-style links, a source document much more
  523. closely resembles the final output, as rendered in a browser. By
  524. allowing you to move the markup-related metadata out of the paragraph,
  525. you can add links without interrupting the narrative flow of your
  526. prose.</p>
  527. <h3 id="em">Emphasis</h3>
  528. <p>Markdown treats asterisks (<code>*</code>) and underscores (<code>_</code>) as indicators of
  529. emphasis. Text wrapped with one <code>*</code> or <code>_</code> will be wrapped with an
  530. HTML <code>&lt;em&gt;</code> tag; double <code>*</code>'s or <code>_</code>'s will be wrapped with an HTML
  531. <code>&lt;strong&gt;</code> tag. E.g., this input:</p>
  532. <pre><code>*single asterisks*
  533. _single underscores_
  534. **double asterisks**
  535. __double underscores__
  536. </code></pre>
  537. <p>will produce:</p>
  538. <pre><code>&lt;em&gt;single asterisks&lt;/em&gt;
  539. &lt;em&gt;single underscores&lt;/em&gt;
  540. &lt;strong&gt;double asterisks&lt;/strong&gt;
  541. &lt;strong&gt;double underscores&lt;/strong&gt;
  542. </code></pre>
  543. <p>You can use whichever style you prefer; the lone restriction is that
  544. the same character must be used to open and close an emphasis span.</p>
  545. <p>Emphasis can be used in the middle of a word:</p>
  546. <pre><code>un*fucking*believable
  547. </code></pre>
  548. <p>But if you surround an <code>*</code> or <code>_</code> with spaces, it'll be treated as a
  549. literal asterisk or underscore.</p>
  550. <p>To produce a literal asterisk or underscore at a position where it
  551. would otherwise be used as an emphasis delimiter, you can backslash
  552. escape it:</p>
  553. <pre><code>\*this text is surrounded by literal asterisks\*
  554. </code></pre>
  555. <h3 id="code">Code</h3>
  556. <p>To indicate a span of code, wrap it with backtick quotes (<code>`</code>).
  557. Unlike a pre-formatted code block, a code span indicates code within a
  558. normal paragraph. For example:</p>
  559. <pre><code>Use the `printf()` function.
  560. </code></pre>
  561. <p>will produce:</p>
  562. <pre><code>&lt;p&gt;Use the &lt;code&gt;printf()&lt;/code&gt; function.&lt;/p&gt;
  563. </code></pre>
  564. <p>To include a literal backtick character within a code span, you can use
  565. multiple backticks as the opening and closing delimiters:</p>
  566. <pre><code>``There is a literal backtick (`) here.``
  567. </code></pre>
  568. <p>which will produce this:</p>
  569. <pre><code>&lt;p&gt;&lt;code&gt;There is a literal backtick (`) here.&lt;/code&gt;&lt;/p&gt;
  570. </code></pre>
  571. <p>The backtick delimiters surrounding a code span may include spaces --
  572. one after the opening, one before the closing. This allows you to place
  573. literal backtick characters at the beginning or end of a code span:</p>
  574. <pre><code>A single backtick in a code span: `` ` ``
  575. A backtick-delimited string in a code span: `` `foo` ``
  576. </code></pre>
  577. <p>will produce:</p>
  578. <pre><code>&lt;p&gt;A single backtick in a code span: &lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
  579. &lt;p&gt;A backtick-delimited string in a code span: &lt;code&gt;`foo`&lt;/code&gt;&lt;/p&gt;
  580. </code></pre>
  581. <p>With a code span, ampersands and angle brackets are encoded as HTML
  582. entities automatically, which makes it easy to include example HTML
  583. tags. Markdown will turn this:</p>
  584. <pre><code>Please don't use any `&lt;blink&gt;` tags.
  585. </code></pre>
  586. <p>into:</p>
  587. <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;
  588. </code></pre>
  589. <p>You can write this:</p>
  590. <pre><code>`&amp;#8212;` is the decimal-encoded equivalent of `&amp;mdash;`.
  591. </code></pre>
  592. <p>to produce:</p>
  593. <pre><code>&lt;p&gt;&lt;code&gt;&amp;amp;#8212;&lt;/code&gt; is the decimal-encoded
  594. equivalent of &lt;code&gt;&amp;amp;mdash;&lt;/code&gt;.&lt;/p&gt;
  595. </code></pre>
  596. <h3 id="img">Images</h3>
  597. <p>Admittedly, it's fairly difficult to devise a &quot;natural&quot; syntax for
  598. placing images into a plain text document format.</p>
  599. <p>Markdown uses an image syntax that is intended to resemble the syntax
  600. for links, allowing for two styles: <em>inline</em> and <em>reference</em>.</p>
  601. <p>Inline image syntax looks like this:</p>
  602. <pre><code>![Alt text](/path/to/img.jpg)
  603. ![Alt text](/path/to/img.jpg &quot;Optional title&quot;)
  604. </code></pre>
  605. <p>That is:</p>
  606. <ul>
  607. <li>An exclamation mark: <code>!</code>;</li>
  608. <li>followed by a set of square brackets, containing the <code>alt</code>
  609. attribute text for the image;</li>
  610. <li>followed by a set of parentheses, containing the URL or path to
  611. the image, and an optional <code>title</code> attribute enclosed in double
  612. or single quotes.</li>
  613. </ul>
  614. <p>Reference-style image syntax looks like this:</p>
  615. <pre><code>![Alt text][id]
  616. </code></pre>
  617. <p>Where &quot;id&quot; is the name of a defined image reference. Image references
  618. are defined using syntax identical to link references:</p>
  619. <pre><code>[id]: url/to/image &quot;Optional title attribute&quot;
  620. </code></pre>
  621. <p>As of this writing, Markdown has no syntax for specifying the
  622. dimensions of an image; if this is important to you, you can simply
  623. use regular HTML <code>&lt;img&gt;</code> tags.</p>
  624. <hr />
  625. <h2 id="misc">Miscellaneous</h2>
  626. <h3 id="autolink">Automatic Links</h3>
  627. <p>Markdown supports a shortcut style for creating &quot;automatic&quot; 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>
  628. <pre><code>&lt;http://example.com/&gt;
  629. </code></pre>
  630. <p>Markdown will turn this into:</p>
  631. <pre><code>&lt;a href=&quot;http://example.com/&quot;&gt;http://example.com/&lt;/a&gt;
  632. </code></pre>
  633. <p>Automatic links for email addresses work similarly, except that
  634. Markdown will also perform a bit of randomized decimal and hex
  635. entity-encoding to help obscure your address from address-harvesting
  636. spambots. For example, Markdown will turn this:</p>
  637. <pre><code>&lt;address@example.com&gt;
  638. </code></pre>
  639. <p>into something like this:</p>
  640. <pre><code>&lt;a href=&quot;&amp;#x6D;&amp;#x61;i&amp;#x6C;&amp;#x74;&amp;#x6F;:&amp;#x61;&amp;#x64;&amp;#x64;&amp;#x72;&amp;#x65;
  641. &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;
  642. &amp;#109;&quot;&gt;&amp;#x61;&amp;#x64;&amp;#x64;&amp;#x72;&amp;#x65;&amp;#115;&amp;#115;&amp;#64;&amp;#101;&amp;#120;&amp;#x61;
  643. &amp;#109;&amp;#x70;&amp;#x6C;e&amp;#x2E;&amp;#99;&amp;#111;&amp;#109;&lt;/a&gt;
  644. </code></pre>
  645. <p>which will render in a browser as a clickable link to &quot;address@example.com&quot;.</p>
  646. <p>(This sort of entity-encoding trick will indeed fool many, if not
  647. most, address-harvesting bots, but it definitely won't fool all of
  648. them. It's better than nothing, but an address published in this way
  649. will probably eventually start receiving spam.)</p>
  650. <h3 id="backslash">Backslash Escapes</h3>
  651. <p>Markdown allows you to use backslash escapes to generate literal
  652. characters which would otherwise have special meaning in Markdown's
  653. formatting syntax. For example, if you wanted to surround a word with
  654. literal asterisks (instead of an HTML <code>&lt;em&gt;</code> tag), you can backslashes
  655. before the asterisks, like this:</p>
  656. <pre><code>\*literal asterisks\*
  657. </code></pre>
  658. <p>Markdown provides backslash escapes for the following characters:</p>
  659. <pre><code>\ backslash
  660. ` backtick
  661. * asterisk
  662. _ underscore
  663. {} curly braces
  664. [] square brackets
  665. () parentheses
  666. # hash mark
  667. + plus sign
  668. - minus sign (hyphen)
  669. . dot
  670. ! exclamation mark
  671. </code></pre>