git.iko.soy/typeable/pandoc
on e9dc5aa help sign in
1063 lines 41 kB history raw
1% Pandoc User's Guide
2% John MacFarlane
3% March 24, 2008
5Pandoc is a [Haskell] library for converting from one markup format to
6another, and a command-line tool that uses this library. It can read
7[markdown] and (subsets of) [reStructuredText], [HTML], and [LaTeX], and
8it can write [markdown], [reStructuredText], [HTML], [LaTeX], [ConTeXt],
9[RTF], [DocBook XML], [OpenDocument XML], [GNU Texinfo], [groff man]
10pages, and [S5] HTML slide shows. Pandoc's version of markdown contains
11some enhancements, like footnotes and embedded LaTeX.
13In contrast to existing tools for converting markdown to HTML, which
14use regex substitutions, Pandoc has a modular design: it consists of a
15set of readers, which parse text in a given format and produce a native
16representation of the document, and a set of writers, which convert
17this native representation into a target format. Thus, adding an input
18or output format requires only adding a reader or writer.
20[markdown]: http://daringfireball.net/projects/markdown/
21[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
22[S5]: http://meyerweb.com/eric/tools/s5/
23[HTML]: http://www.w3.org/TR/html40/
24[LaTeX]: http://www.latex-project.org/
25[ConTeXt]: http://www.pragma-ade.nl/
26[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
27[DocBook XML]: http://www.docbook.org/
28[OpenDocument XML]: http://opendocument.xml.org/
29[groff man]: http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man7/groff_man.7.html
30[Haskell]: http://www.haskell.org/
31[GNU Texinfo]: http://www.gnu.org/software/texinfo/
33© 2006-8 John MacFarlane (jgm at berkeley dot edu). Released under the
34[GPL], version 2 or greater. This software carries no warranty of
35any kind. (See COPYRIGHT for full copyright and warranty notices.)
36Contributors: Recai Oktaş (build system, debian package, wrapper
37scripts), Peter Wang (Texinfo writer), Andrea Rossato (OpenDocument writer).
39[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
41Using Pandoc
42============
44If you run `pandoc` without arguments, it will accept input from
45STDIN. If you run it with file names as arguments, it will take input
46from those files. By default, `pandoc` writes its output to STDOUT.
47If you want to write to a file, use the `-o` option:
49 pandoc -o hello.html hello.txt
51Note that you can specify multiple input files on the command line.
52`pandoc` will concatenate them all (with blank lines between them)
53before parsing:
55 pandoc -s ch1.txt ch2.txt refs.txt > book.html
57(The `-s` option here tells `pandoc` to produce a standalone HTML file,
58with a proper header, rather than a fragment. For more details on this
59and many other command-line options, see below.)
61The format of the input and output can be specified explicitly using
62command-line options. The input format can be specified using the
63`-r/--read` or `-f/--from` options, the output format using the
64`-w/--write` or `-t/--to` options. Thus, to convert `hello.txt` from
65markdown to LaTeX, you could type:
67 pandoc -f markdown -t latex hello.txt
69To convert `hello.html` from html to markdown:
71 pandoc -f html -t markdown hello.html
73Supported output formats include `markdown`, `latex`, `context`
74(ConTeXt), `html`, `rtf` (rich text format), `rst` (reStructuredText),
75`docbook` (DocBook XML), `opendocument` (OpenDocument XML), `texinfo`,
76`man` (groff man), and `s5` (which produces an HTML file that acts
77like powerpoint). Supported input formats include `markdown`, `html`,
78`latex`, and `rst`. Note that the `rst` reader only parses a subset of
79reStructuredText syntax. For example, it doesn't handle tables, option
80lists, or footnotes. But for simple documents it should be adequate. The
81`latex` and `html` readers are also limited in what they can do. Because
82the `html` reader is picky about the HTML it parses, it is recommended
83that you pipe HTML through [HTML Tidy] before sending it to `pandoc`, or
84use the `html2markdown` script described below.
86If you don't specify a reader or writer explicitly, `pandoc` will
87try to determine the input and output format from the extensions of
88the input and output filenames. Thus, for example,
90 pandoc -o hello.tex hello.txt
92will convert `hello.txt` from markdown to LaTeX. If no output file
93is specified (so that output goes to STDOUT), or if the output file's
94extension is unknown, the output format will default to HTML.
95If no input file is specified (so that input comes from STDIN), or
96if the input files' extensions are unknown, the input format will
97be assumed to be markdown unless explicitly specified.
99Character encodings
100-------------------
102All input is assumed to be in the UTF-8 encoding, and all output
103is in UTF-8. If your local character encoding is not UTF-8 and you use
104accented or foreign characters, you should pipe the input and output
105through [`iconv`]. For example,
107 iconv -t utf-8 source.txt | pandoc | iconv -f utf-8 > output.html
109will convert `source.txt` from the local encoding to UTF-8, then
110convert it to HTML, then convert back to the local encoding,
111putting the output in `output.html`.
113The shell scripts (described below) automatically convert the input
114from the local encoding to UTF-8 before running them through `pandoc`,
115then convert the output back to the local encoding.
117Shell scripts
118=============
120Four shell scripts, `markdown2pdf`, `markdown2odt`, `html2markdown`, and
121`hsmarkdown`, are included in the standard Pandoc installation. (They
122are not included in the Windows binary package, as they require a POSIX
123shell, but they may be used in Windows under Cygwin.)
1251. `markdown2pdf` produces a PDF file from markdown-formatted
126 text, using `pandoc` and `pdflatex`. The default
127 behavior of `markdown2pdf` is to create a file with the same
128 base name as the first argument and the extension `pdf`; thus,
129 for example,
131 markdown2pdf sample.txt endnotes.txt
133 will produce `sample.pdf`. (If `sample.pdf` exists already,
134 it will be backed up before being overwritten.) An output file
135 name can be specified explicitly using the `-o` option:
137 markdown2pdf -o book.pdf chap1 chap2
139 If no input file is specified, input will be taken from STDIN.
140 All of `pandoc`'s options will work with `markdown2pdf` as well.
142 `markdown2pdf` assumes that `pdflatex` is in the path. It also
143 assumes that the following LaTeX packages are available:
144 `unicode`, `fancyhdr` (if you have verbatim text in footnotes),
145 `graphicx` (if you use images), `array` (if you use tables),
146 and `ulem` (if you use strikeout text). If they are not already
147 included in your LaTeX distribution, you can get them from
148 [CTAN].
1502. `markdown2odt` produces an ODT file from markdown-formatted
151 text, using `pandoc` and `pdflatex`. (ODT is "OpenDocument
152 Text," the default format for the OpenOffice.org Writer.)
153 The default behavior of `markdown2odt` is to create a file with the
154 same base name as the first argument and the extension `odt`; thus,
155 for example,
157 markdown2odt sample.txt endnotes.txt
159 will produce `sample.odt`. (If `sample.odt` exists already,
160 it will be backed up before being overwritten.) An output file
161 name can be specified explicitly using the `-o` option:
163 markdown2odt -o book.odt chap1 chap2
165 If no input file is specified, input will be taken from STDIN.
166 All of `pandoc`'s options will work with `markdown2odt` as well.
168 `markdown2odt` requires `zip`, which must be in the path.
1703. `html2markdown` grabs a web page from a file or URL and converts
171 it to markdown-formatted text, using `tidy` and `pandoc`.
173 All of `pandoc`'s options will work with `html2markdown` as well.
174 In addition, the following special options may be used.
175 The special options must be separated from the `html2markdown`
176 command and any regular Pandoc options by the delimiter `--`:
178 html2markdown -o out.txt -- -e latin1 -g curl google.com
180 The `-e` or `--encoding` option specifies the character encoding
181 of the HTML input. If this option is not specified, and input
182 is not from STDIN, `html2markdown` will attempt to determine the
183 page's character encoding from the "Content-type" meta tag.
184 If this is not present, UTF-8 is assumed.
186 The `-g` or `--grabber` option specifies the command to be used to
187 fetch the contents of a URL:
189 html2markdown -g 'curl --user foo:bar' www.mysite.com
191 If this option is not specified, `html2markdown` searches for an
192 available program (`wget`, `curl`, or a text-mode browser) to fetch
193 the contents of a URL.
195 `html2markdown` requires [HTML Tidy], which must be in the path.
196 It uses [`iconv`] for character encoding conversions; if `iconv`
197 is absent, it will still work, but it will treat everything as UTF-8.
1994. `hsmarkdown` is designed to be used as a drop-in replacement for
200 `Markdown.pl`. It forces `pandoc` to convert from markdown to
201 HTML, and to use the `--strict` flag for maximal compliance with
202 official markdown syntax. (All of Pandoc's syntax extensions and
203 variants, described below, are disabled.) No other command-line
204 options are allowed. (In fact, options will be interpreted as
205 filenames.)
207 As an alternative to using the `hsmarkdown` shell script, the
208 user may create a symbolic link to `pandoc` called `hsmarkdown`.
209 When invoked under the name `hsmarkdown`, `pandoc` will behave
210 as if the `--strict` flag had been selected, and no command-line
211 options will be recognized. However, this approach does not work
212 under Cygwin, due to problems with its simulation of symbolic
213 links.
215[Cygwin]: http://www.cygwin.com/
216[HTML Tidy]: http://tidy.sourceforge.net/
217[`iconv`]: http://www.gnu.org/software/libiconv/
218[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
220Command-line options
221====================
223Various command-line options can be used to customize the output.
224For further documentation, see the `pandoc(1)` man page.
226`-f`, `--from`, `-r`, or `--read` *format*
227: specifies the input format (the format Pandoc will be converting
228 *from*). *format* can be `native`, `markdown`, `rst`, `html`, or
229 `latex`.
231`-t`, `--to`, `-w`, or `--write` *format*
232: specifies the output format -- the format Pandoc will
233 be converting *to*. *format* can be `native`, `html`, `s5`,
234 `docbook`, `opendocument`, `latex`, `context`, `markdown`, `man`,
235 `rst`, and `rtf`.
237`-s` or `--standalone`
238: indicates that a standalone document is to be produced (with
239 appropriate headers and footers), rather than a fragment.
241`-o` or `--output` *filename*
242: sends output to *filename*. If this option is not specified,
243 or if its argument is `-`, output will be sent to STDOUT.
245`-p` or `--preserve-tabs`
246: causes tabs in the source text to be preserved, rather than converted
247 to spaces (the default).
249`--tabstop` *tabstop*
250: sets the number of spaces per tab to *tabstop* (defaults to 4).
252`--strict`
253: specifies that strict markdown syntax is to be used, without
254 pandoc's usual extensions and variants (described below). When the
255 input format is HTML, this means that constructs that have no
256 equivalents in standard markdown (e.g. definition lists or strikeout
257 text) will be parsed as raw HTML.
259`--reference-links`
260: causes reference-style links to be used in markdown
261 and reStructuredText output. By default inline links are used.
263`-R` or `--parse-raw`
264: causes the HTML and LaTeX readers to parse HTML codes and LaTeX
265 environments that it can't translate as raw HTML or LaTeX. Raw HTML can
266 be printed in markdown, reStructuredText, HTML, and S5 output; raw LaTeX
267 can be printed in markdown, reStructuredText, LaTeX, and ConTeXt output.
268 The default is for the readers to omit untranslatable HTML codes and
269 LaTeX environments. (The LaTeX reader does pass through untranslatable
270 LaTeX *commands*, even if `-R` is not specified.)
272`-C` or `--custom-header` *filename*
273: can be used to specify a custom document header. To see the headers
274 used by default, use the `-D` option: for example, `pandoc -D html`
275 prints the default HTML header.
277`--toc` or `--table-of-contents`
278: includes an automatically generated table of contents (or, in the
279 case of `latex`, `context`, and `rst`, an instruction to create
280 one) in the output document. This option has no effect with `man`,
281 `docbook`, or `s5` output formats.
283`-c` or `--css` *filename*
284: allows the user to specify a custom stylesheet that will be linked to
285 in HTML and S5 output. This option can be used repeatedly to include
286 multiple stylesheets. They will be included in the order specified.
288`-H` or `--include-in-header` *filename*
289: includes the contents of *filename* (verbatim) at the end of the
290 document header. This can be used, for example, to include special
291 CSS or javascript in HTML documents. This option can be used
292 repeatedly to include multiple files in the header. They will be
293 included in the order specified.
295`-B` or `--include-before-body` *filename*
296: includes the contents of *filename* (verbatim) at the beginning of
297 the document body (e.g. after the `<body>` tag in HTML, or the
298 `\begin{document}` command in LaTeX). This can be used to include
299 navigation bars or banners in HTML documents. This option can be
300 used repeatedly to include multiple files. They will be included in
301 the order specified.
303`-A` or `--include-after-body` *filename*
304: includes the contents of *filename* (verbatim) at the end of
305 the document body (before the `</body>` tag in HTML, or the
306 `\end{document}` command in LaTeX). This option can be be used
307 repeatedly to include multiple files. They will be included in the
308 order specified.
310`-T` or `--title-prefix` *string*
311: includes *string* as a prefix at the beginning of the title that
312 appears in the HTML header (but not in the title as it appears at
313 the beginning of the HTML body). (See below on
314 [Title Blocks](#title-blocks).)
316`-S` or `--smart`
317: causes `pandoc` to produce typographically correct output, along the
318 lines of John Gruber's [Smartypants]. Straight quotes are converted
319 to curly quotes, `---` to dashes, and `...` to ellipses. Nonbreaking
320 spaces are inserted after certain abbreviations, such as "Mr."
321 (Note: This option is only significant when the input format is
322 `markdown`. It is selected automatically when the output format is
323 `latex` or `context`.)
325`-m`*[url]* or `--asciimathml`*[=url]*
326: causes `pandoc` to use Peter Jipsen's [ASCIIMathML] script to display
327 TeX math in HTML or S5. If a local copy of `ASCIIMathML.js` is
328 available on the webserver where the page will be viewed, provide a
329 *url* and a link will be inserted in the generated HTML or S5. If
330 no *url* is provided, the contents of the script will be inserted
331 directly; this provides portability at the price of efficiency. If
332 you plan to use math on several pages, it is much better to link to
333 a copy of `ASCIIMathML.js`, which can be cached. (See `--gladtex`
334 and `--mimetex` for alternative ways of dealing with math in HTML.)
336`--gladtex`*[=url]*
337: causes TeX formulas to be enclosed in `<eq>` tags in HTML or S5 output.
338 This output can then be processed by [gladTeX] to produce links to
339 images with the typeset formulas. (See `--asciimathml` and
340 `--mimetex` for alternative ways of dealing with math in HTML.)
342`--mimetex`*[=url]*
343: causes TeX formulas to be replaced by `<img>` tags linking to the
344 [mimeTeX] CGI script, which will produce images with the typeset
345 formulas. (See `--asciimathml` and `--mimetex` for alternative
346 ways of dealing with math in HTML.)
348`-i` or `--incremental`
349: causes all lists in S5 output to be displayed incrementally by
350 default (one item at a time). The normal default is for lists to be
351 displayed all at once.
353`-N` or `--number-sections`
354: causes sections to be numbered in LaTeX or ConTeXt output. By default,
355 sections are not numbered.
357`--no-wrap`
358: disables text-wrapping in output. By default, text is wrapped
359 appropriately for the output format.
361`--sanitize-html`
362: sanitizes HTML (in markdown or HTML input) using a whitelist.
363 Unsafe tags are replaced by HTML comments; unsafe attributes
364 are omitted. URIs in links and images are also checked against a
365 whitelist of URI schemes.
367`--dump-args`
368: is intended to make it easier to create wrapper scripts that use
369 Pandoc. It causes Pandoc to dump information about the arguments
370 with which it was called to STDOUT, then exit. The first line
371 printed is the name of the output file specified using the `-o`
372 or `--output` option, or `-` if output would go to STDOUT. The
373 remaining lines, if any, list command-line arguments. These will
374 include the names of input files and any special options passed
375 after ` -- ` on the command line. So, for example,
377: pandoc --dump-args -o foo.html -s foo.txt \
378 appendix.txt -- -e latin1
380: will cause the following to be printed to STDOUT:
382: foo.html foo.txt appendix.txt -e latin1
384`--ignore-args`
385: causes Pandoc to ignore all command-line arguments.
386 Regular Pandoc options are not ignored. Thus, for example,
388: pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
390: is equivalent to
392: pandoc -o foo.html -s
394`-v` or `--version`
395: prints the version number to STDERR.
397`-h` or `--help`
398: prints a usage message to STDERR.
400[Smartypants]: http://daringfireball.net/projects/smartypants/
401[ASCIIMathML]: http://www1.chapman.edu/~jipsen/mathml/asciimath.html
402[gladTeX]: http://www.math.uio.no/~martingu/gladtex/index.html
403[mimeTeX]: http://www.forkosh.com/mimetex.html
405Pandoc's markdown vs. standard markdown
406=======================================
408In parsing markdown, Pandoc departs from and extends [standard markdown]
409in a few respects. (To run Pandoc on the official markdown test suite,
410type `make test-markdown`.) Except where noted, these differences can
411be suppressed by specifying the `--strict` command-line option or by
412using the `hsmarkdown` wrapper.
414[standard markdown]: http://daringfireball.net/projects/markdown/syntax
415 "Markdown syntax description"
417Backslash escapes
418-----------------
420Except inside a code block or inline code, any punctuation or space
421character preceded by a backslash will be treated literally, even if it
422would normally indicate formatting. Thus, for example, if one writes
424 *\*hello\**
426one will get
428 <em>*hello*</em>
430instead of
432 <strong>hello</strong>
434This rule is easier to remember than standard markdown's rule,
435which allows only the following characters to be backslash-escaped:
437 \`*_{}[]()>#+-.!
439A backslash-escaped space is parsed as a nonbreaking space. It will
440appear in TeX output as '~' and in HTML and XML as '\&#160;' or '\&nbsp;'.
442Subscripts and superscripts
443---------------------------
445Superscripts may be written by surrounding the superscripted text by `^`
446characters; subscripts may be written by surrounding the subscripted
447text by `~` characters. Thus, for example,
449 H~2~O is a liquid. 2^10^ is 1024.
451If the superscripted or subscripted text contains spaces, these spaces
452must be escaped with backslashes. (This is to prevent accidental
453superscripting and subscripting through the ordinary use of `~` and `^`.)
454Thus, if you want the letter P with 'a cat' in subscripts, use
455`P~a\ cat~`, not `P~a cat~`.
457Strikeout
458---------
460To strikeout a section of text with a horizontal line, begin and end it
461with `~~`. Thus, for example,
463 This ~~is deleted text.~~
465Nested Lists
466------------
468Pandoc behaves differently from standard markdown on some "edge
469cases" involving lists. Consider this source:
471 1. First
472 2. Second:
473 - Fee
474 - Fie
475 - Foe
477 3. Third
479Pandoc transforms this into a "compact list" (with no `<p>` tags around
480"First", "Second", or "Third"), while markdown puts `<p>` tags around
481"Second" and "Third" (but not "First"), because of the blank space
482around "Third". Pandoc follows a simple rule: if the text is followed by
483a blank line, it is treated as a paragraph. Since "Second" is followed
484by a list, and not a blank line, it isn't treated as a paragraph. The
485fact that the list is followed by a blank line is irrelevant. (Note:
486Pandoc works this way even when the `--strict` option is specified. This
487behavior is consistent with the official markdown syntax description,
488even though it is different from that of `Markdown.pl`.)
490Ordered Lists
491-------------
493Unlike standard markdown, Pandoc allows ordered list items to be marked
494with uppercase and lowercase letters and roman numerals, in addition to
495arabic numerals. (This behavior can be turned off using the `--strict`
496option.) List markers may be enclosed in parentheses or followed by a
497single right-parentheses or period. They must be separated from the
498text that follows by at least one space, and, if the list marker is a
499capital letter with a period, by at least two spaces.[^2]
501[^2]: The point of this rule is to ensure that normal paragraphs
502 starting with people's initials, like
504 B. Russell was an English philosopher.
506 do not get treated as list items.
508 This rule will not prevent
510 (C) 2007 Joe Smith
512 from being interpreted as a list item. In this case, a backslash
513 escape can be used:
515 (C\) 2007 Joe Smith
517Pandoc also pays attention to the type of list marker used, and to the
518starting number, and both of these are preserved where possible in the
519output format. Thus, the following yields a list with numbers followed
520by a single parenthesis, starting with 9, and a sublist with lowercase
521roman numerals:
523 9) Ninth
524 10) Tenth
525 11) Eleventh
526 i. subone
527 ii. subtwo
528 iii. subthree
530Note that Pandoc pays attention only to the *starting* number in a list.
531So, the following yields a list numbered sequentially starting from 2:
533 (2) Two
534 (5) Three
535 (2) Four
537If default list markers are desired, use '`#.`':
539 #. one
540 #. two
541 #. three
543If you change list style in mid-list, Pandoc will notice and assume you
544are starting a sublist. So,
546 1. One
547 2. Two
548 A. Sub
549 B. Sub
550 3. Three
552gets treated as if it were
554 1. One
555 2. Two
556 A. Sub
557 B. Sub
558 3. Three
561Definition lists
562----------------
564Pandoc supports definition lists, using a syntax inspired by
565[PHP Markdown Extra] and [reStructuredText]:
567 [PHP Markdown Extra]: http://www.michelf.com/projects/php-markdown/extra/
569 Term 1
570 : Definition 1
572 Term 2
573 : Definition 2
575 : Second paragraph of definition 2.
577Each term must fit on one line. The definition must begin on the line
578after the term. The definition consists of one or more block elements
579(paragraph, code block, list, etc.), each beginning with a colon and
580(aside from the colon) indented one tab stop.
582 Term *with inline markup*
583 : Here is the definition. It may contain multiple blocks.
584 Here is some code:
586 : {* my code *}
588 : Here is the third paragraph of this definition.
590If you leave space after the definition (as in the first example above),
591the definitions will be considered paragraphs. In some output formats,
592this will mean greater spacing between term/definition pairs. For a
593compact definition list, do not leave space between the definition and
594the next term:
596 Term 1
597 : Definition 1
598 Term 2
599 : Definition 2
601Reference links
602---------------
604Pandoc allows implicit reference links with just a single set of
605brackets. So, the following links are equivalent:
607 1. Here's my [link]
608 2. Here's my [link][]
610 [link]: linky.com
612(Note: Pandoc works this way even if `--strict` is specified, because
613`Markdown.pl` 1.0.2b7 allows single-bracket links.)
615Footnotes
616---------
618Pandoc's markdown allows footnotes, using the following syntax:
620 Here is a footnote reference,[^1] and another.[^longnote]
622 [^1]: Here is the footnote.
624 [^longnote]: Here's one with multiple blocks.
626 Subsequent paragraphs are indented to show that they
627 belong to the previous footnote.
629 { some.code }
631 The whole paragraph can be indented, or just the first
632 line. In this way, multi-paragraph footnotes work like
633 multi-paragraph list items.
635 This paragraph won't be part of the note, because it isn't indented.
637The identifiers in footnote references may not contain spaces, tabs,
638or newlines. These identifiers are used only to correlate the
639footnote reference with the note itself; in the output, footnotes
640will be numbered sequentially.
642The footnotes themselves need not be placed at the end of the
643document. They may appear anywhere except inside other block elements
644(lists, block quotes, tables, etc.).
646Inline footnotes are also allowed (though, unlike regular notes,
647they cannot contain multiple paragraphs). The syntax is as follows:
649 Here is an inline note.^[Inlines notes are easier to write, since
650 you don't have to pick an identifier and move down to type the
651 note.]
653Inline and regular footnotes may be mixed freely.
655Tables
656------
658Two kinds of tables may be used. Both kinds presuppose the use of
659a fixed-width font, such as Courier.
661Simple tables look like this:
663 Right Left Center Default
664 ------- ------ ---------- -------
665 12 12 12 12
666 123 123 123 123
667 1 1 1 1
669 Table: Demonstration of simple table syntax.
671The headers and table rows must each fit on one line. Column
672alignments are determined by the position of the header text relative
673to the dashed line below it:[^1]
675 - If the dashed line is flush with the header text on the right side
676 but extends beyond it on the left, the column is right-aligned.
677 - If the dashed line is flush with the header text on the left side
678 but extends beyond it on the right, the column is left-aligned.
679 - If the dashed line extends beyond the header text on both sides,
680 the column is centered.
681 - If the dashed line is flush with the header text on both sides,
682 the default alignment is used (in most cases, this will be left).
684[^1]: This scheme is due to Michel Fortin, who proposed it on the
685 Markdown discussion list:
686 <http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html>.
688The table must end with a blank line. Optionally, a caption may be
689provided (as illustrated in the example above). A caption is a paragraph
690beginning with the string `Table:`, which will be stripped off.
692The table parser pays attention to the widths of the columns, and
693the writers try to reproduce these relative widths in the output.
694So, if you find that one of the columns is too narrow in the output,
695try widening it in the markdown source.
697Multiline tables allow headers and table rows to span multiple lines
698of text. Here is an example:
700 -------------------------------------------------------------
701 Centered Default Right Left
702 Header Aligned Aligned Aligned
703 ----------- ------- --------------- -------------------------
704 First row 12.0 Example of a row that
705 spans multiple lines.
707 Second row 5.0 Here's another one. Note
708 the blank line between
709 rows.
710 -------------------------------------------------------------
712 Table: Here's the caption. It, too, may span
713 multiple lines.
715These work like simple tables, but with the following differences:
717 - They must begin with a row of dashes, before the header text.
718 - They must end with a row of dashes, then a blank line.
719 - The rows must be separated by blank lines.
721Delimited Code blocks
722---------------------
724In addition to standard indented code blocks, Pandoc supports
725*delimited* code blocks. These begin with a row of three or more
726tildes (`~`) and end with a row of tildes that must be at least
727as long as the starting row. Everything between the tilde-lines
728is treated as code. No indentation is necessary:
730 ~~~~~~~
731 {code here}
732 ~~~~~~~
734If the code itself contains a row of tildes, just use a longer
735row of tildes at the start and end:
737 ~~~~~~~~~~~~~~~~
738 ~~~~~~~~~~
739 code including tildes
740 ~~~~~~~~~~
741 ~~~~~~~~~~~~~~~~
743Optionally, you may specify the language of the code block using
744this syntax:
746 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines}
747 qsort [] = []
748 qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
749 qsort (filter (>= x) xs)
750 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
752Some output formats can use this information to do syntax highlighting.
753Currently, the only output format that uses this information is HTML.
755If pandoc has been compiled with syntax highlighting support, then the
756code block above will appear highlighted, with numbered lines. (To see
757which languages are supported, do `pandoc --version`.)
759If pandoc has not been compiled with syntax highlighting support, the
760code block above will appear as follows:
762 <pre class="haskell">
763 <code>
764 ...
765 </code>
766 </pre>
768Title blocks
769------------
771If the file begins with a title block
773 % title
774 % author(s) (separated by commas)
775 % date
777it will be parsed as bibliographic information, not regular text. (It
778will be used, for example, in the title of standalone LaTeX or HTML
779output.) The block may contain just a title, a title and an author,
780or all three lines. Each must begin with a % and fit on one line.
781The title may contain standard inline formatting. If you want to
782include an author but no title, or a title and a date but no author,
783you need a blank line:
785 % My title
786 %
787 % June 15, 2006
789Titles will be written only when the `--standalone` (`-s`) option is
790chosen. In HTML output, titles will appear twice: once in the
791document head -- this is the title that will appear at the top of the
792window in a browser -- and once at the beginning of the document body.
793The title in the document head can have an optional prefix attached
794(`--title-prefix` or `-T` option). The title in the body appears as
795an H1 element with class "title", so it can be suppressed or
796reformatted with CSS. If a title prefix is specified with `-T` and no
797title block appears in the document, the title prefix will be used by
798itself as the HTML title.
800The man page writer extracts a title, man page section number, and
801other header and footer information from the title line. The title
802is assumed to be the first word on the title line, which may optionally
803end with a (single-digit) section number in parentheses. (There should
804be no space between the title and the parentheses.) Anything after
805this is assumed to be additional footer and header text. A single pipe
806character (`|`) should be used to separate the footer text from the header
807text. Thus,
809 % PANDOC(1)
811will yield a man page with the title `PANDOC` and section 1.
813 % PANDOC(1) Pandoc User Manuals
815will also have "Pandoc User Manuals" in the footer.
817 % PANDOC(1) Pandoc User Manuals | Version 4.0
819will also have "Version 4.0" in the header.
821Markdown in HTML blocks
822-----------------------
824While standard markdown leaves HTML blocks exactly as they are, Pandoc
825treats text between HTML tags as markdown. Thus, for example, Pandoc
826will turn
828 <table>
829 <tr>
830 <td>*one*</td>
831 <td>[a link](http://google.com)</td>
832 </tr>
833 </table>
835into
837 <table>
838 <tr>
839 <td><em>one</em></td>
840 <td><a href="http://google.com">a link</a></td>
841 </tr>
842 </table>
844whereas `Markdown.pl` will preserve it as is.
846There is one exception to this rule: text between `<script>` and
847`</script>` tags is not interpreted as markdown.
849This departure from standard markdown should make it easier to mix
850markdown with HTML block elements. For example, one can surround
851a block of markdown text with `<div>` tags without preventing it
852from being interpreted as markdown.
854Header identifiers in HTML
855--------------------------
857Each header element in pandoc's HTML output is given a unique
858identifier. This identifier is based on the text of the header. To
859derive the identifier from the header text,
861 - Remove all formatting, links, etc.
862 - Remove all punctuation, except dashes and hyphens.
863 - Replace all spaces, dashes, newlines, and hyphens with hyphens.
864 - Convert all alphabetic characters to lowercase.
865 - Remove everything up to the first letter (identifiers may
866 not begin with a number or punctuation mark).
867 - If nothing is left after this, use the identifier `section`.
869Thus, for example,
871 Header Identifier
872 ------------------------------------- ---------------------------
873 Header identifiers in HTML `header-identifiers-in-html`
874 *Dogs*?--in *my* house? `dogs--in-my-house`
875 [HTML], [S5], or [RTF]? `html-s5-or-rtf`
876 3. Applications `applications`
877 33 `section`
879These rules should, in most cases, allow one to determine the identifier
880from the header text. The exception is when several headers have the
881same text; in this case, the first will get an identifier as described
882above; the second will get the same identifier with `-1` appended; the
883third with `-2`; and so on.
885These identifiers are used to provide link targets in the table of
886contents generated by the `--toc|--table-of-contents` option. They
887also make it easy to provide links from one section of a document to
888another. A link to this section, for example, might look like this:
890 See the section on [header identifiers](#header-identifiers-in-html).
892Note, however, that this method of providing links to sections works
893only in HTML.
895Blank lines before headers and blockquotes
896------------------------------------------
898Standard markdown syntax does not require a blank line before a header
899or blockquote. Pandoc does require this (except, of course, at the
900beginning of the document). The reason for the requirement is that
901it is all too easy for a `>` or `#` to end up at the beginning of a
902line by accident (perhaps through line wrapping). Consider, for
903example:
905 I like several of their flavors of ice cream: #22, for example, and
906 #5.
908Math
909----
911Anything between two $ characters will be treated as TeX math. The
912opening $ must have a character immediately to its right, while the
913closing $ must have a character immediately to its left. Thus,
914`$20,000 and $30,000` won't parse as math. If for some reason
915you need to enclose text in literal $ characters, backslash-escape
916them and they won't be treated as math delimiters.
918TeX math will be printed in all output formats. In Markdown,
919reStructuredText, LaTeX, and ConTeXt output, it will appear verbatim
920between $ characters.
922In reStructuredText output, it will be rendered using an interpreted
923text role `:math:`, as described
924[here](http://www.american.edu/econ/itex2mml/mathhack.rst).
926In Texinfo output, it will be rendered inside a `@math` command.
928In groff man output, it will be rendered verbatim without $'s.
930In RTF, Docbook, and OpenDocument output, it will be rendered, as far as
931possible, using unicode characters, and will otherwise appear verbatim.
932Unknown commands and symbols, and commands that cannot be dealt with
933this way (like `\frac`), will be rendered verbatim. So the results may
934be a mix of raw TeX code and properly rendered unicode math.
936In HTML and S5 output, the way math is rendered will depend on the
937command-line options selected:
9391. The default is to render TeX math as far as possible using unicode
940 characters, as with RTF, Docbook, and OpenDocument output. Formulas
941 are put inside a `span` with `class="math"`, so that they may be
942 styled differently from the surrounding text if needed.
9442. If the `--asciimathml` option is used, TeX math will be displayed
945 between $ characters, as in LaTeX, and the [ASCIIMathML] script will
946 be used to render it as formulas. (This trick does not work in all
947 browsers, but it works in Firefox. In browsers that do not support
948 ASCIIMathML, TeX math will appear verbatim between $ characters.)
9503. If the `--mimetex` option is used, the [mimeTeX] CGI script will
951 be called to generate images for each TeX formula. This should
952 work in all browsers. The `--mimetex` option takes an optional URL
953 as argument. If no URL is specified, it will be assumed that the
954 mimeTeX CGI script is at `/cgi-bin/mimetex.cgi`.
9564. If the `--gladtex` option is used, TeX formulas will be enclosed
957 in `<eq>` tags in the HTML output. The resulting `htex` file may then
958 be processed by [gladTeX], which will produce image files for each
959 formula and an `html` file with links to these images. So, the
960 procedure is:
962 pandoc -s --gladtex myfile.txt -o myfile.htex
963 gladtex -d myfile-images myfile.htex # produces myfile.html
964 # and images in myfile-images
966Inline TeX
967----------
969Inline TeX commands will be preserved and passed unchanged to the
970LaTeX and ConTeXt writers. Thus, for example, you can use LaTeX to
971include BibTeX citations:
973 This result was proved in \cite{jones.1967}.
975Note that in LaTeX environments, like
977 \begin{tabular}{|l|l|}\hline
978 Age & Frequency \\ \hline
979 18--25 & 15 \\
980 26--35 & 33 \\
981 36--45 & 22 \\ \hline
982 \end{tabular}
984the material between the begin and end tags will be interpreted as raw
985LaTeX, not as markdown.
987Inline LaTeX is ignored in output formats other than Markdown, LaTeX,
988and ConTeXt.
990Custom headers
991==============
993When run with the "standalone" option (`-s`), `pandoc` creates a
994standalone file, complete with an appropriate header. To see the
995default headers used for html and latex, use the following commands:
997 pandoc -D html
999 pandoc -D latex
1001If you want to use a different header, just create a file containing
1002it and specify it on the command line as follows:
1004 pandoc --header=MyHeaderFile
1006Producing S5 with Pandoc
1007========================
1009Producing an [S5] web-based slide show with Pandoc is easy. A title
1010page is constructed automatically from the document's title block (see
1011above). Each section (with a level-one header) produces a single slide.
1012(Note that if the section is too big, the slide will not fit on the page;
1013S5 is not smart enough to produce multiple pages.)
1015Here's the markdown source for a simple slide show, `eating.txt`:
1017 % Eating Habits
1018 % John Doe
1019 % March 22, 2005
1021 # In the morning
1023 - Eat eggs
1024 - Drink coffee
1026 # In the evening
1028 - Eat spaghetti
1029 - Drink wine
1031To produce the slide show, simply type
1033 pandoc -w s5 -s eating.txt > eating.html
1035and open up `eating.html` in a browser.
1037Note that by default, the S5 writer produces lists that display
1038"all at once." If you want your lists to display incrementally
1039(one item at a time), use the `-i` option. If you want a
1040particular list to depart from the default (that is, to display
1041incrementally without the `-i` option and all at once with the
1042`-i` option), put it in a block quote:
1044 > - Eat spaghetti
1045 > - Drink wine
1047In this way incremental and nonincremental lists can be mixed in
1048a single document.
1050Note: the S5 file produced by pandoc with the `-s/--standalone` option
1051embeds the javascript and CSS required to show the slides. Thus it
1052does not depend on any additional files: you can send the HTML file to
1053others, and they will be able to view the slide show just by opening
1054it. However, if you intend to produce several S5 slide shows, and you
1055are displaying them on your own website, it is better to keep the S5
1056javascript and CSS files separate from the slide shows themselves, so
1057that they may be cached. The best approach in this case is to use pandoc
1058without the `-s` option to produce the body of the S5 document, which
1059can then be inserted into an HTML template that links to the javascript
1060and CSS files required by S5. (See the instructions on the S5 website.)
1061Alternatively, you may use `-s` together with the `-H/--custom-header`
1062option.