Text::Markdown::Discount
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.

1020 lines
29 KiB

  1. .\"
  2. .Dd Dec 22, 2007
  3. .Dt MARKDOWN 7
  4. .Os MASTODON
  5. .Sh NAME
  6. .Nm Markdown
  7. .Nd The Markdown text formatting syntax
  8. .Sh DESCRIPTION
  9. .Ss Philosophy
  10. .Nm Markdown
  11. is intended to be as easy-to-read and easy-to-write as is feasible.
  12. .Pp
  13. Readability, however, is emphasized above all else. A Markdown-formatted
  14. document should be publishable as-is, as plain text, without looking
  15. like it's been marked up with tags or formatting instructions. While
  16. Markdown's syntax has been influenced by several existing text-to-HTML
  17. filters -- including
  18. .Em Setext ,
  19. .Em atx ,
  20. .Em Textile ,
  21. .Em reStructuredText ,
  22. .Em Grutatext ,
  23. and
  24. .Em EtText
  25. \-\- the single biggest source of
  26. inspiration for
  27. Markdown's
  28. syntax is the format of plain text email.
  29. .Pp
  30. To this end, Markdown's syntax is comprised entirely of punctuation
  31. characters, which punctuation characters have been carefully chosen so
  32. as to look like what they mean. E.g., asterisks around a word actually
  33. look like *emphasis*. Markdown lists look like, well, lists. Even
  34. blockquotes look like quoted passages of text, assuming you've ever
  35. used email.
  36. .Ss Inline HTML
  37. Markdown's syntax is intended for one purpose: to be used as a
  38. format for
  39. .Em writing
  40. for the web.
  41. .Pp
  42. .Nm
  43. is not a replacement for HTML, or even close to it. Its
  44. syntax is very small, corresponding only to a very small subset of
  45. HTML tags. The idea is
  46. .Em not
  47. to create a syntax that makes it easier
  48. to insert HTML tags. In my opinion, HTML tags are already easy to
  49. insert. The idea for Markdown is to make it easy to read, write, and
  50. edit prose. HTML is a
  51. .Em publishing
  52. format; Markdown is a
  53. .Em writing
  54. format. Thus, Markdown's formatting syntax only addresses issues that
  55. can be conveyed in plain text.
  56. .Pp
  57. For any markup that is not covered by Markdown's syntax, you simply
  58. use HTML itself. There's no need to preface it or delimit it to
  59. indicate that you're switching from Markdown to HTML; you just use
  60. the tags.
  61. .Pp
  62. The only restrictions are that block-level HTML elements -- e.g.
  63. .Li \<div> ,
  64. .Li \<table> ,
  65. .Li \<pre> ,
  66. .Li \<p> ,
  67. etc. -- must be separated from surrounding
  68. content by blank lines, and the start and end tags of the block should
  69. not be indented with tabs or spaces. Markdown is smart enough not
  70. to add extra (unwanted)
  71. .Li \<p>
  72. tags around HTML block-level tags.
  73. .Pp
  74. For example, to add an HTML table to a Markdown article:
  75. .Bd -literal -offset indent
  76. This is a regular paragraph.
  77. <table>
  78. <tr>
  79. <td>Foo</td>
  80. </tr>
  81. </table>
  82. This is another regular paragraph.
  83. .Ed
  84. .Pp
  85. Note that Markdown formatting syntax is not processed within block-level
  86. HTML tags. E.g., you can't use Markdown-style
  87. .Li *emphasis*
  88. inside an HTML block.
  89. .Pp
  90. Span-level HTML tags -- e.g.
  91. .Li \<span> ,
  92. .Li \<cite> ,
  93. or
  94. .Li \<del>
  95. \-\- can be
  96. used anywhere in a Markdown paragraph, list item, or header. If you
  97. want, you can even use HTML tags instead of Markdown formatting; e.g. if
  98. you'd prefer to use HTML
  99. .Li \<a>
  100. or
  101. .Li \<img>
  102. tags instead of Markdown's
  103. link or image syntax, go right ahead.
  104. .Pp
  105. Unlike block-level HTML tags, Markdown syntax *is* processed within
  106. span-level tags.
  107. .Ss Automatic Escaping for Special Characters
  108. In HTML, there are two characters that demand special treatment: `<`
  109. and `&`. Left angle brackets are used to start tags; ampersands are
  110. used to denote HTML entities. If you want to use them as literal
  111. characters, you must escape them as entities, e.g. `&lt;`, and
  112. `&amp;`.
  113. .Pp
  114. Ampersands in particular are bedeviling for web writers. If you want to
  115. write about 'AT&T', you need to write '`AT&amp;T`'. You even need to
  116. escape ampersands within URLs. Thus, if you want to link to:
  117. .Bd -literal -offset indent
  118. http://images.google.com/images?num=30&q=larry+bird
  119. .Ed
  120. .Pp
  121. you need to encode the URL as:
  122. .Bd -literal -offset indent
  123. http://images.google.com/images?num=30&amp;q=larry+bird
  124. .Ed
  125. .Pp
  126. in your anchor tag `href` attribute. Needless to say, this is easy to
  127. forget, and is probably the single most common source of HTML validation
  128. errors in otherwise well-marked-up web sites.
  129. .Pp
  130. .Nm
  131. allows you to use these characters naturally, taking care of
  132. all the necessary escaping for you. If you use an ampersand as part of
  133. an HTML entity, it remains unchanged; otherwise it will be translated
  134. into `&amp;`.
  135. .Pp
  136. So, if you want to include a copyright symbol in your article, you can write:
  137. .Bd -literal -offset indent
  138. &copy;
  139. .Ed
  140. .Pp
  141. and Markdown will leave it alone. But if you write:
  142. .Bd -literal -offset indent
  143. AT&T
  144. .Ed
  145. .Pp
  146. .Nm
  147. will translate it to:
  148. .Bd -literal -offset indent
  149. AT&amp;T
  150. .Ed
  151. .Pp
  152. Similarly, because Markdown supports inline HTML, if you use
  153. angle brackets as delimiters for HTML tags, Markdown will treat them as
  154. such. But if you write:
  155. .Bd -literal -offset indent
  156. 4 < 5
  157. .Ed
  158. .Pp
  159. .Nm
  160. will translate it to:
  161. .Bd -literal -offset indent
  162. 4 &lt; 5
  163. .Ed
  164. .Pp
  165. However, inside Markdown code spans and blocks, angle brackets and
  166. ampersands are *always* encoded automatically. This makes it easy to use
  167. Markdown to write about HTML code. (As opposed to raw HTML, which is a
  168. terrible format for writing about HTML syntax, because every single `<`
  169. and `&` in your example code needs to be escaped.)
  170. .Sh Block Elements
  171. .Ss Paragraphs and Line Breaks
  172. .Pp
  173. A paragraph is simply one or more consecutive lines of text, separated
  174. by one or more blank lines. (A blank line is any line that looks like a
  175. blank line -- a line containing nothing but spaces or tabs is considered
  176. blank.) Normal paragraphs should not be indented with spaces or tabs.
  177. .Pp
  178. The implication of the
  179. .Qq one or more consecutive lines of text
  180. rule is
  181. that Markdown supports
  182. .Qq hard-wrapped
  183. Dtext paragraphs. This differs
  184. significantly from most other text-to-HTML formatters (including Movable
  185. Type's
  186. .Qq Convert Line Breaks
  187. option) which translate every line break
  188. character in a paragraph into a `<br />` tag.
  189. .Pp
  190. When you *do* want to insert a `<br />` break tag using Markdown, you
  191. end a line with two or more spaces, then type return.
  192. .Pp
  193. Yes, this takes a tad more effort to create a `<br />`, but a simplistic
  194. "every line break is a `<br />`" rule wouldn't work for Markdown.
  195. Markdown's email-style
  196. .Sx blockquoting
  197. and multi-paragraph
  198. .Sx list items
  199. work best -- and look better -- when you format them with hard breaks.
  200. .Ss Headers
  201. .Nm
  202. supports two styles of headers,
  203. .Em Setext
  204. and
  205. .Em atx .
  206. .Pp
  207. Setext-style headers are
  208. .Sq underlined
  209. using equal signs (for first-level
  210. headers) and dashes (for second-level headers). For example:
  211. .Bd -literal -offset indent
  212. This is an H1
  213. =============
  214. This is an H2
  215. -------------
  216. .Ed
  217. .Pp
  218. Any number of underlining `=`'s or `-`'s will work.
  219. .Pp
  220. Atx-style headers use 1-6 hash characters at the start of the line,
  221. corresponding to header levels 1-6. For example:
  222. .Bd -literal -offset indent
  223. # This is an H1
  224. ## This is an H2
  225. ###### This is an H6
  226. .Ed
  227. .Pp
  228. Optionally, you may
  229. .Qq close
  230. atx-style headers. This is purely
  231. cosmetic -- you can use this if you think it looks better. The
  232. closing hashes don't even need to match the number of hashes
  233. used to open the header. (The number of opening hashes
  234. determines the header level.) :
  235. .Bd -literal -offset indent
  236. # This is an H1 #
  237. ## This is an H2 ##
  238. ### This is an H3 ######
  239. .Ed
  240. .Pp
  241. .Ss Blockquotes
  242. .Nm
  243. uses email-style `>` characters for blockquoting. If you're
  244. familiar with quoting passages of text in an email message, then you
  245. know how to create a blockquote in Markdown. It looks best if you hard
  246. wrap the text and put a `>` before every line:
  247. .Bd -literal -offset indent
  248. > This is a blockquote with two paragraphs. Lorem ipsum
  249. > dolor sit amet, consectetuer adipiscing elit. Aliquam
  250. > hendrerit mi posuere lectus. Vestibulum enim wisi,
  251. > viverra nec, fringilla in, laoreet vitae, risus.
  252. >
  253. > Donec sit amet nisl. Aliquam semper ipsum sit amet
  254. > velit. Suspendisse id sem consectetuer libero luctus
  255. > adipiscing.
  256. .Ed
  257. .Pp
  258. .Nm
  259. allows you to be lazy and only put the `>` before the first
  260. line of a hard-wrapped paragraph:
  261. .Bd -literal -offset indent
  262. > This is a blockquote with two paragraphs. Lorem ipsum
  263. dolor sit amet, consectetuer adipiscing elit. Aliquam
  264. hendrerit mi posuere lectus. Vestibulum enim wisi,
  265. viverra nec, fringilla in, laoreet vitae, risus.
  266. > Donec sit amet nisl. Aliquam semper ipsum sit amet
  267. velit. Suspendisse id sem consectetuer libero luctus
  268. adipiscing.
  269. .Ed
  270. .Pp
  271. Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
  272. adding additional levels of `>`:
  273. .Bd -literal -offset indent
  274. > This is the first level of quoting.
  275. >
  276. > > This is nested blockquote.
  277. >
  278. > Back to the first level.
  279. .Ed
  280. .Pp
  281. Blockquotes can contain other Markdown elements, including headers, lists,
  282. and code blocks:
  283. .Bd -literal -offset indent
  284. > ## This is a header.
  285. >
  286. > 1. This is the first list item.
  287. > 2. This is the second list item.
  288. >
  289. > Here's some example code:
  290. >
  291. > return shell_exec("echo $input | $markdown_script");
  292. .Ed
  293. .Pp
  294. Any decent text editor should make email-style quoting easy. For
  295. example, with BBEdit, you can make a selection and choose Increase
  296. Quote Level from the Text menu.
  297. .Ss Lists
  298. .Nm
  299. supports ordered (numbered) and unordered (bulleted) lists.
  300. .Pp
  301. Unordered lists use asterisks, pluses, and hyphens -- interchangably
  302. \-- as list markers:
  303. .Bd -literal -offset indent
  304. * Red
  305. * Green
  306. * Blue
  307. .Ed
  308. .Pp
  309. is equivalent to:
  310. .Bd -literal -offset indent
  311. + Red
  312. + Green
  313. + Blue
  314. .Ed
  315. .Pp
  316. and:
  317. .Bd -literal -offset indent
  318. - Red
  319. - Green
  320. - Blue
  321. .Ed
  322. .Pp
  323. Ordered lists use numbers followed by periods:
  324. .Bd -literal -offset indent
  325. 1. Bird
  326. 2. McHale
  327. 3. Parish
  328. .Ed
  329. .Pp
  330. It's important to note that the actual numbers you use to mark the
  331. list have no effect on the HTML output Markdown produces. The HTML
  332. Markdown produces from the above list is:
  333. .Bd -literal -offset indent
  334. <ol>
  335. <li>Bird</li>
  336. <li>McHale</li>
  337. <li>Parish</li>
  338. </ol>
  339. .Ed
  340. .Pp
  341. If you instead wrote the list in Markdown like this:
  342. .Bd -literal -offset indent
  343. 1. Bird
  344. 1. McHale
  345. 1. Parish
  346. .Ed
  347. .Pp
  348. or even:
  349. .Bd -literal -offset indent
  350. 3. Bird
  351. 1. McHale
  352. 8. Parish
  353. .Ed
  354. .Pp
  355. you'd get the exact same HTML output. The point is, if you want to,
  356. you can use ordinal numbers in your ordered Markdown lists, so that
  357. the numbers in your source match the numbers in your published HTML.
  358. But if you want to be lazy, you don't have to.
  359. .Pp
  360. If you do use lazy list numbering, however, you should still start the
  361. list with the number 1. At some point in the future, Markdown may support
  362. starting ordered lists at an arbitrary number.
  363. .Pp
  364. List markers typically start at the left margin, but may be indented by
  365. up to three spaces. List markers must be followed by one or more spaces
  366. or a tab.
  367. .Pp
  368. To make lists look nice, you can wrap items with hanging indents:
  369. .Bd -literal -offset indent
  370. * Lorem ipsum dolor sit amet, consectetuer adipiscing
  371. elit. Aliquam hendrerit mi posuere lectus. Vestibulum
  372. enim wisi, viverra nec, fringilla in, laoreet vitae,
  373. risus.
  374. * Donec sit amet nisl. Aliquam semper ipsum sit amet
  375. velit. Suspendisse id sem consectetuer libero luctus
  376. adipiscing.
  377. .Ed
  378. .Pp
  379. But if you want to be lazy, you don't have to:
  380. .Bd -literal -offset indent
  381. * Lorem ipsum dolor sit amet, consectetuer adipiscing
  382. elit. Aliquam hendrerit mi posuere lectus. Vestibulum
  383. enim wisi, viverra nec, fringilla in, laoreet vitae,
  384. risus.
  385. * Donec sit amet nisl. Aliquam semper ipsum sit amet
  386. velit. Suspendisse id sem consectetuer libero luctus
  387. adipiscing.
  388. .Ed
  389. .Pp
  390. If list items are separated by blank lines, Markdown will wrap the
  391. items in `<p>` tags in the HTML output. For example, this input:
  392. .Bd -literal -offset indent
  393. * Bird
  394. * Magic
  395. .Ed
  396. .Pp
  397. will turn into:
  398. .Bd -literal -offset indent
  399. <ul>
  400. <li>Bird</li>
  401. <li>Magic</li>
  402. </ul>
  403. .Ed
  404. .Pp
  405. But this:
  406. .Bd -literal -offset indent
  407. * Bird
  408. * Magic
  409. .Ed
  410. .Pp
  411. will turn into:
  412. .Bd -literal -offset indent
  413. <ul>
  414. <li><p>Bird</p></li>
  415. <li><p>Magic</p></li>
  416. </ul>
  417. .Ed
  418. .Pp
  419. List items may consist of multiple paragraphs. Each subsequent
  420. paragraph in a list item must be intended by either 4 spaces
  421. or one tab:
  422. .Bd -literal -offset indent
  423. 1. This is a list item with two paragraphs. Lorem ipsum
  424. dolor sit amet, consectetuer adipiscing elit. Aliquam
  425. hendrerit mi posuere lectus.
  426. Vestibulum enim wisi, viverra nec, fringilla in,
  427. laoreet vitae, risus. Donec sit amet nisl. Aliquam
  428. semper ipsum sit amet velit.
  429. 2. Suspendisse id sem consectetuer libero luctus
  430. adipiscing.
  431. .Ed
  432. .Pp
  433. It looks nice if you indent every line of the subsequent
  434. paragraphs, but here again, Markdown will allow you to be
  435. lazy:
  436. .Bd -literal -offset indent
  437. * This is a list item with two paragraphs.
  438. This is the second paragraph in the list item.
  439. You're only required to indent the first line. Lorem
  440. ipsum dolor sit amet, consectetuer adipiscing elit.
  441. * Another item in the same list.
  442. .Ed
  443. .Pp
  444. To put a blockquote within a list item, the blockquote's `>`
  445. delimiters need to be indented:
  446. .Bd -literal -offset indent
  447. * A list item with a blockquote:
  448. > This is a blockquote
  449. > inside a list item.
  450. .Ed
  451. .Pp
  452. To put a code block within a list item, the code block needs
  453. to be indented *twice* -- 8 spaces or two tabs:
  454. .Bd -literal -offset indent
  455. * A list item with a code block:
  456. <code goes here>
  457. .Ed
  458. .Pp
  459. It's worth noting that it's possible to trigger an ordered list by
  460. accident, by writing something like this:
  461. .Bd -literal -offset indent
  462. 1986. What a great season.
  463. .Ed
  464. .Pp
  465. In other words, a *number-period-space* sequence at the beginning of a
  466. line. To avoid this, you can backslash-escape the period:
  467. .Bd -literal -offset indent
  468. 1986\\. What a great season.
  469. .Ed
  470. .Pp
  471. .Ss Code Blocks
  472. Pre-formatted code blocks are used for writing about programming or
  473. markup source code. Rather than forming normal paragraphs, the lines
  474. of a code block are interpreted literally. Markdown wraps a code block
  475. in both `<pre>` and `<code>` tags.
  476. .Pp
  477. To produce a code block in Markdown, simply indent every line of the
  478. block by at least 4 spaces or 1 tab. For example, given this input:
  479. .Bd -literal -offset indent
  480. This is a normal paragraph:
  481. This is a code block.
  482. .Ed
  483. .Pp
  484. .Nm
  485. will generate:
  486. .Bd -literal -offset indent
  487. <p>This is a normal paragraph:</p>
  488. <pre><code>This is a code block.
  489. </code></pre>
  490. .Ed
  491. .Pp
  492. One level of indentation -- 4 spaces or 1 tab -- is removed from each
  493. line of the code block. For example, this:
  494. .Bd -literal -offset indent
  495. Here is an example of AppleScript:
  496. tell application "Foo"
  497. beep
  498. end tell
  499. .Ed
  500. .Pp
  501. will turn into:
  502. .Bd -literal -offset indent
  503. <p>Here is an example of AppleScript:</p>
  504. <pre><code>tell application "Foo"
  505. beep
  506. end tell
  507. </code></pre>
  508. .Ed
  509. .Pp
  510. A code block continues until it reaches a line that is not indented
  511. (or the end of the article).
  512. .Pp
  513. Within a code block, ampersands (`&`) and angle brackets (`<` and `>`)
  514. are automatically converted into HTML entities. This makes it very
  515. easy to include example HTML source code using Markdown -- just paste
  516. it and indent it, and Markdown will handle the hassle of encoding the
  517. ampersands and angle brackets. For example, this:
  518. .Bd -literal -offset indent
  519. <div class="footer">
  520. &copy; 2004 Foo Corporation
  521. </div>
  522. .Ed
  523. .Pp
  524. will turn into:
  525. .Bd -literal -offset indent
  526. <pre><code>&lt;div class="footer"&gt;
  527. &amp;copy; 2004 Foo Corporation
  528. &lt;/div&gt;
  529. </code></pre>
  530. .Ed
  531. .Pp
  532. Regular Markdown syntax is not processed within code blocks. E.g.,
  533. asterisks are just literal asterisks within a code block. This means
  534. it's also easy to use Markdown to write about Markdown's own syntax.
  535. .Ss Horizontal Rules
  536. You can produce a horizontal rule tag (`<hr />`) by placing three or
  537. more hyphens, asterisks, or underscores on a line by themselves. If you
  538. wish, you may use spaces between the hyphens or asterisks. Each of the
  539. following lines will produce a horizontal rule:
  540. .Bd -literal -offset indent
  541. * * *
  542. ***
  543. *****
  544. - - -
  545. ---------------------------------------
  546. .Ed
  547. .Pp
  548. .Sh Span Elements
  549. .Ss Links
  550. .Nm
  551. supports two style of links:
  552. .Em inline
  553. and
  554. .Em reference .
  555. .Pp
  556. In both styles, the link text is delimited by [square brackets].
  557. .Pp
  558. To create an inline link, use a set of regular parentheses immediately
  559. after the link text's closing square bracket. Inside the parentheses,
  560. put the URL where you want the link to point, along with an *optional*
  561. title for the link, surrounded in quotes. For example:
  562. .Bd -literal -offset indent
  563. This is [an example](http://example.com/ "Title") inline link.
  564. [This link](http://example.net/) has no title attribute.
  565. .Ed
  566. .Pp
  567. Will produce:
  568. .Bd -literal -offset indent
  569. <p>This is <a href="http://example.com/" title="Title">
  570. an example</a> inline link.</p>
  571. <p><a href="http://example.net/">This link</a> has no
  572. title attribute.</p>
  573. .Ed
  574. .Pp
  575. If you're referring to a local resource on the same server, you can
  576. use relative paths:
  577. .Bd -literal -offset indent
  578. See my [About](/about/) page for details.
  579. .Ed
  580. .Pp
  581. Reference-style links use a second set of square brackets, inside
  582. which you place a label of your choosing to identify the link:
  583. .Bd -literal -offset indent
  584. This is [an example][id] reference-style link.
  585. .Ed
  586. .Pp
  587. You can optionally use a space to separate the sets of brackets:
  588. .Bd -literal -offset indent
  589. This is [an example] [id] reference-style link.
  590. .Ed
  591. .Pp
  592. Then, anywhere in the document, you define your link label like this,
  593. on a line by itself:
  594. .Bd -literal -offset indent
  595. [id]: http://example.com/ "Optional Title Here"
  596. .Ed
  597. .Pp
  598. That is:
  599. .Bl -bullet
  600. .It
  601. Square brackets containing the link identifier (optionally
  602. indented from the left margin using up to three spaces);
  603. .It
  604. followed by a colon;
  605. .It
  606. followed by one or more spaces (or tabs);
  607. .It
  608. followed by the URL for the link;
  609. .It
  610. optionally followed by a title attribute for the link, enclosed
  611. in double or single quotes, or enclosed in parentheses.
  612. .El
  613. .Pp
  614. The following three link definitions are equivalent:
  615. .Bd -literal -offset indent
  616. [foo]: http://example.com/ "Optional Title Here"
  617. [foo]: http://example.com/ 'Optional Title Here'
  618. [foo]: http://example.com/ (Optional Title Here)
  619. .Ed
  620. .Pp
  621. .Em Note :
  622. There is a known bug in Markdown.pl 1.0.1 which prevents
  623. single quotes from being used to delimit link titles.
  624. .Pp
  625. The link URL may, optionally, be surrounded by angle brackets:
  626. .Bd -literal -offset indent
  627. [id]: <http://example.com/> "Optional Title Here"
  628. .Ed
  629. .Pp
  630. You can put the title attribute on the next line and use extra spaces
  631. or tabs for padding, which tends to look better with longer URLs:
  632. .Bd -literal -offset indent
  633. [id]: http://example.com/longish/path/to/resource/here
  634. "Optional Title Here"
  635. .Ed
  636. .Pp
  637. Link definitions are only used for creating links during Markdown
  638. processing, and are stripped from your document in the HTML output.
  639. .Pp
  640. Link definition names may constist of letters, numbers, spaces, and
  641. punctuation -- but they are
  642. .Em not
  643. case sensitive. E.g. these two
  644. links:
  645. .Bd -literal -offset indent
  646. [link text][a]
  647. [link text][A]
  648. .Ed
  649. .Pp
  650. are equivalent.
  651. .Pp
  652. The
  653. .Em implicit link name
  654. shortcut allows you to omit the name of the
  655. link, in which case the link text itself is used as the name.
  656. Just use an empty set of square brackets -- e.g., to link the word
  657. .Qq Google
  658. to the google.com web site, you could simply write:
  659. .Bd -literal -offset indent
  660. [Google][]
  661. .Ed
  662. .Pp
  663. And then define the link:
  664. .Bd -literal -offset indent
  665. [Google]: http://google.com/
  666. .Ed
  667. .Pp
  668. Because link names may contain spaces, this shortcut even works for
  669. multiple words in the link text:
  670. .Bd -literal -offset indent
  671. Visit [Daring Fireball][] for more information.
  672. .Ed
  673. .Pp
  674. And then define the link:
  675. .Bd -literal -offset indent
  676. [Daring Fireball]: http://daringfireball.net/
  677. .Ed
  678. .Pp
  679. Link definitions can be placed anywhere in your Markdown document. I
  680. tend to put them immediately after each paragraph in which they're
  681. used, but if you want, you can put them all at the end of your
  682. document, sort of like footnotes.
  683. .Pp
  684. Here's an example of reference links in action:
  685. .Bd -literal -offset indent
  686. I get 10 times more traffic from [Google] [1] than from
  687. [Yahoo] [2] or [MSN] [3].
  688. [1]: http://google.com/ "Google"
  689. [2]: http://search.yahoo.com/ "Yahoo Search"
  690. [3]: http://search.msn.com/ "MSN Search"
  691. .Ed
  692. .Pp
  693. Using the implicit link name shortcut, you could instead write:
  694. .Bd -literal -offset indent
  695. I get 10 times more traffic from [Google][] than from
  696. [Yahoo][] or [MSN][].
  697. [google]: http://google.com/ "Google"
  698. [yahoo]: http://search.yahoo.com/ "Yahoo Search"
  699. [msn]: http://search.msn.com/ "MSN Search"
  700. .Ed
  701. .Pp
  702. Both of the above examples will produce the following HTML output:
  703. .Bd -literal -offset indent
  704. <p>I get 10 times more traffic from <a href="http://google.com/"
  705. title="Google">Google</a> than from
  706. <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
  707. or
  708. <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
  709. .Ed
  710. .Pp
  711. For comparison, here is the same paragraph written using
  712. Markdown's inline link style:
  713. .Bd -literal -offset indent
  714. I get 10 times more traffic from
  715. [Google](http://google.com/ "Google") than from
  716. [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
  717. [MSN](http://search.msn.com/ "MSN Search").
  718. .Ed
  719. .Pp
  720. The point of reference-style links is not that they're easier to
  721. write. The point is that with reference-style links, your document
  722. source is vastly more readable. Compare the above examples: using
  723. reference-style links, the paragraph itself is only 81 characters
  724. long; with inline-style links, it's 176 characters; and as raw HTML,
  725. it's 234 characters. In the raw HTML, there's more markup than there
  726. is text.
  727. .Pp
  728. With Markdown's reference-style links, a source document much more
  729. closely resembles the final output, as rendered in a browser. By
  730. allowing you to move the markup-related metadata out of the paragraph,
  731. you can add links without interrupting the narrative flow of your
  732. prose.
  733. .Ss Emphasis
  734. Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
  735. emphasis. Text wrapped with one `*` or `_` will be wrapped with an
  736. HTML `<em>` tag; double `*`'s or `_`'s will be wrapped with an HTML
  737. `<strong>` tag. E.g., this input:
  738. .Bd -literal -offset indent
  739. *single asterisks*
  740. _single underscores_
  741. **double asterisks**
  742. __double underscores__
  743. .Ed
  744. .Pp
  745. will produce:
  746. .Bd -literal -offset indent
  747. <em>single asterisks</em>
  748. <em>single underscores</em>
  749. <strong>double asterisks</strong>
  750. <strong>double underscores</strong>
  751. .Ed
  752. .Pp
  753. You can use whichever style you prefer; the lone restriction is that
  754. the same character must be used to open and close an emphasis span.
  755. .Pp
  756. Emphasis can be used in the middle of a word:
  757. .Bd -literal -offset indent
  758. un*fucking*believable
  759. .Ed
  760. .Pp
  761. But if you surround an `*` or `_` with spaces, it'll be treated as a
  762. literal asterisk or underscore.
  763. .Pp
  764. To produce a literal asterisk or underscore at a position where it
  765. would otherwise be used as an emphasis delimiter, you can backslash
  766. escape it:
  767. .Bd -literal -offset indent
  768. \\*this text is surrounded by literal asterisks\\*
  769. .Ed
  770. .Pp
  771. .Ss Code
  772. To indicate a span of code, wrap it with backtick quotes (`` ` ``).
  773. Unlike a pre-formatted code block, a code span indicates code within a
  774. normal paragraph. For example:
  775. .Bd -literal -offset indent
  776. Use the `printf()` function.
  777. .Ed
  778. .Pp
  779. will produce:
  780. .Bd -literal -offset indent
  781. <p>Use the <code>printf()</code> function.</p>
  782. .Ed
  783. .Pp
  784. To include a literal backtick character within a code span, you can use
  785. multiple backticks as the opening and closing delimiters:
  786. .Bd -literal -offset indent
  787. ``There is a literal backtick (`) here.``
  788. .Ed
  789. .Pp
  790. which will produce this:
  791. .Bd -literal -offset indent
  792. <p><code>There is a literal backtick (`) here.</code></p>
  793. .Ed
  794. .Pp
  795. The backtick delimiters surrounding a code span may include spaces --
  796. one after the opening, one before the closing. This allows you to place
  797. literal backtick characters at the beginning or end of a code span:
  798. .Bd -literal -offset indent
  799. A single backtick in a code span: `` ` ``
  800. A backtick-delimited string in a code span: `` `foo` ``
  801. .Ed
  802. .Pp
  803. will produce:
  804. .Bd -literal -offset indent
  805. <p>A single backtick in a code span: <code>`</code></p>
  806. <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
  807. .Ed
  808. .Pp
  809. With a code span, ampersands and angle brackets are encoded as HTML
  810. entities automatically, which makes it easy to include example HTML
  811. tags. Markdown will turn this:
  812. .Bd -literal -offset indent
  813. Please don't use any `<blink>` tags.
  814. .Ed
  815. .Pp
  816. into:
  817. .Bd -literal -offset indent
  818. <p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
  819. .Ed
  820. .Pp
  821. You can write this:
  822. .Bd -literal -offset indent
  823. `&#8212;` is the decimal-encoded equivalent of `&mdash;`.
  824. .Ed
  825. .Pp
  826. to produce:
  827. .Bd -literal -offset indent
  828. <p><code>&amp;#8212;</code> is the decimal-encoded
  829. equivalent of <code>&amp;mdash;</code>.</p>
  830. .Ed
  831. .Pp
  832. .Ss Images
  833. Admittedly, it's fairly difficult to devise a
  834. .Qq natural
  835. syntax for placing images into a plain text document format.
  836. .Pp
  837. Markdown uses an image syntax that is intended to resemble the syntax
  838. for links, allowing for two styles:
  839. .Em inline
  840. and
  841. .Em reference .
  842. .Pp
  843. Inline image syntax looks like this:
  844. .Bd -literal -offset indent
  845. ![Alt text](/path/to/img.jpg)
  846. ![Alt text](/path/to/img.jpg =Optional size "Optional title")
  847. .Ed
  848. .Pp
  849. That is:
  850. .Bl -bullet
  851. .It
  852. An exclamation mark: `!`;
  853. .It
  854. followed by a set of square brackets, containing the `alt`
  855. attribute text for the image;
  856. .It
  857. followed by a set of parentheses, containing the URL or path to
  858. the image, an optional `size` attribute (in
  859. .Ar width Li c Ar height
  860. format) prefixed with a `=`,
  861. and an optional `title` attribute enclosed in double
  862. or single quotes.
  863. .El
  864. .Pp
  865. Reference-style image syntax looks like this:
  866. .Bd -literal -offset indent
  867. ![Alt text][id]
  868. .Ed
  869. .Pp
  870. Where
  871. .Qq id
  872. is the name of a defined image reference. Image references
  873. are defined using syntax identical to link references:
  874. .Bd -literal -offset indent
  875. [id]: url/to/image =Optional size "Optional title attribute"
  876. .Ed
  877. .Pp
  878. .Sh Miscellaneous
  879. .Ss Automatic Links
  880. .Nm
  881. supports a shortcut style for creating
  882. .Qq automatic
  883. links for URLs and email addresses: simply surround the URL or email
  884. address with angle brackets. What this means is that if you want to
  885. show the actual text of a URL or email address, and also have it be
  886. a clickable link, you can do this:
  887. .Bd -literal -offset indent
  888. <http://example.com/>
  889. .Ed
  890. .Pp
  891. .Nm
  892. will turn this into:
  893. .Bd -literal -offset indent
  894. <a href="http://example.com/">http://example.com/</a>
  895. .Ed
  896. .Pp
  897. Automatic links for email addresses work similarly, except that
  898. Markdown will also perform a bit of randomized decimal and hex
  899. entity-encoding to help obscure your address from address-harvesting
  900. spambots. For example, Markdown will turn this:
  901. .Bd -literal -offset indent
  902. <address@example.com>
  903. .Ed
  904. .Pp
  905. into something like this:
  906. .Bd -literal -offset indent
  907. <a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
  908. &#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
  909. &#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
  910. &#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
  911. .Ed
  912. .Pp
  913. which will render in a browser as a clickable link to
  914. .Qq address@example.com .
  915. .Pp
  916. (This sort of entity-encoding trick will indeed fool many, if not
  917. most, address-harvesting bots, but it definitely won't fool all of
  918. them. It's better than nothing, but an address published in this way
  919. will probably eventually start receiving spam.)
  920. .Ss Backslash Escapes
  921. .Nm
  922. allows you to use backslash escapes to generate literal
  923. characters which would otherwise have special meaning in Markdown's
  924. formatting syntax. For example, if you wanted to surround a word with
  925. literal asterisks (instead of an HTML `<em>` tag), you add backslashes
  926. before the asterisks, like this:
  927. .Bd -literal -offset indent
  928. \\*literal asterisks\\*
  929. .Ed
  930. .Pp
  931. .Nm
  932. provides backslash escapes for the following characters:
  933. .Bl -tag -compact
  934. .It \&\
  935. backslash
  936. .It \`
  937. backtick
  938. .It *
  939. asterisk
  940. .It _
  941. underscore
  942. .It \{\}
  943. curly braces
  944. .It []
  945. square brackets
  946. .It ()
  947. parentheses
  948. .It #
  949. hash mark
  950. .It +
  951. plus sign
  952. .It \-
  953. minus sign (hyphen)
  954. .It \.
  955. dot
  956. .It \!
  957. exclamation mark
  958. .El
  959. .Sh BUGS
  960. .Nm
  961. assumes that tabs are set to 4 spaces.
  962. .Sh AUTHOR
  963. John Gruber
  964. .%T http://daringfireball.net/
  965. .Sh SEE ALSO
  966. .Xr markdown 1 ,
  967. .Xr markdown 3 ,
  968. .Xr mkd-callbacks 3 ,
  969. .Xr mkd-functions 3 ,
  970. .Xr mkd-extensions 7 .
  971. .Pp
  972. .%T http://daringfireball.net/projects/markdown
  973. .br
  974. .%T http://docutils.sourceforge.net/mirror/setext.html
  975. .br
  976. .%T http://www.aaronsw.com/2002/atx/
  977. .br
  978. .%T http://textism.com/tools/textile/
  979. .br
  980. .%T http://docutils.sourceforge.net/rst.html
  981. .br
  982. .%T http://www.triptico.com/software/grutatxt.html
  983. .br
  984. .%T http://ettext.taint.org/doc/