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