git.iko.soy/typeable/pandoc
on a1eadcd help sign in
1335 lines 52 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], [ODT], [GNU Texinfo],
10[MediaWiki markup], [groff man] pages, and [S5] HTML slide shows.
11Pandoc's enhanced version of markdown includes syntax for footnotes,
12tables, flexible ordered lists, definition lists, delimited code blocks,
13superscript, subscript, strikeout, title blocks, automatic tables of
14contents, embedded LaTeX math, and markdown inside HTML block elements.
15(These enhancements can be disabled if a drop-in replacement for
16`Markdown.pl` is desired.)
18In contrast to most existing tools for converting markdown to HTML, which
19use regex substitutions, Pandoc has a modular design: it consists of a
20set of readers, which parse text in a given format and produce a native
21representation of the document, and a set of writers, which convert
22this native representation into a target format. Thus, adding an input
23or output format requires only adding a reader or writer.
25[markdown]: http://daringfireball.net/projects/markdown/
26[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
27[S5]: http://meyerweb.com/eric/tools/s5/
28[HTML]: http://www.w3.org/TR/html40/
29[LaTeX]: http://www.latex-project.org/
30[ConTeXt]: http://www.pragma-ade.nl/
31[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
32[DocBook XML]: http://www.docbook.org/
33[OpenDocument XML]: http://opendocument.xml.org/
34[ODT]: http://en.wikipedia.org/wiki/OpenDocument
35[MediaWiki markup]: http://www.mediawiki.org/wiki/Help:Formatting
36[groff man]: http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man7/groff_man.7.html
37[Haskell]: http://www.haskell.org/
38[GNU Texinfo]: http://www.gnu.org/software/texinfo/
40© 2006-8 John MacFarlane (jgm at berkeley dot edu). Released under the
41[GPL], version 2 or greater. This software carries no warranty of
42any kind. (See COPYRIGHT for full copyright and warranty notices.)
43Contributors: Recai Oktaş (build system, debian package, wrapper
44scripts), Peter Wang (Texinfo writer), Andrea Rossato (OpenDocument writer).
46[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
48Using Pandoc
49============
51If you run `pandoc` without arguments, it will accept input from
52stdin. If you run it with file names as arguments, it will take input
53from those files. By default, `pandoc` writes its output to stdout.[^1]
54If you want to write to a file, use the `-o` option:
56 pandoc -o hello.html hello.txt
58[^1]: The exception is for `odt`. Since this is a binary output format,
59 an output file must be specified explicitly.
61Note that you can specify multiple input files on the command line.
62`pandoc` will concatenate them all (with blank lines between them)
63before parsing:
65 pandoc -s ch1.txt ch2.txt refs.txt > book.html
67(The `-s` option here tells `pandoc` to produce a standalone HTML file,
68with a proper header, rather than a fragment. For more details on this
69and many other command-line options, see below.)
71The format of the input and output can be specified explicitly using
72command-line options. The input format can be specified using the
73`-r/--read` or `-f/--from` options, the output format using the
74`-w/--write` or `-t/--to` options. Thus, to convert `hello.txt` from
75markdown to LaTeX, you could type:
77 pandoc -f markdown -t latex hello.txt
79To convert `hello.html` from html to markdown:
81 pandoc -f html -t markdown hello.html
83Supported output formats include `markdown`, `latex`, `context`
84(ConTeXt), `html`, `rtf` (rich text format), `rst`
85(reStructuredText), `docbook` (DocBook XML), `opendocument`
86(OpenDocument XML), `odt` (OpenOffice text document), `texinfo`, (GNU
87Texinfo), `mediawiki` (MediaWiki markup), `man` (groff man), and `s5`
88(which produces an HTML file that acts like powerpoint).
90Supported input formats include `markdown`, `html`, `latex`, and `rst`.
91Note that the `rst` reader only parses a subset of reStructuredText
92syntax. For example, it doesn't handle tables, option lists, or
93footnotes. But for simple documents it should be adequate. The `latex`
94and `html` readers are also limited in what they can do. Because the
95`html` reader is picky about the HTML it parses, it is recommended that
96you pipe HTML through [HTML Tidy] before sending it to `pandoc`, or use
97the `html2markdown` script described below.
99If you don't specify a reader or writer explicitly, `pandoc` will
100try to determine the input and output format from the extensions of
101the input and output filenames. Thus, for example,
103 pandoc -o hello.tex hello.txt
105will convert `hello.txt` from markdown to LaTeX. If no output file
106is specified (so that output goes to stdout), or if the output file's
107extension is unknown, the output format will default to HTML.
108If no input file is specified (so that input comes from stdin), or
109if the input files' extensions are unknown, the input format will
110be assumed to be markdown unless explicitly specified.
112Character encodings
113-------------------
115All input is assumed to be in the UTF-8 encoding, and all output
116is in UTF-8. If your local character encoding is not UTF-8 and you use
117accented or foreign characters, you should pipe the input and output
118through [`iconv`]. For example,
120 iconv -t utf-8 source.txt | pandoc | iconv -f utf-8 > output.html
122will convert `source.txt` from the local encoding to UTF-8, then
123convert it to HTML, then convert back to the local encoding,
124putting the output in `output.html`.
126The shell scripts (described below) automatically convert the input
127from the local encoding to UTF-8 before running them through `pandoc`,
128then convert the output back to the local encoding.
130Shell scripts
131=============
133Three shell scripts, `markdown2pdf`, `html2markdown`, and `hsmarkdown`,
134are included in the standard Pandoc installation. (They are not included
135in the Windows binary package, as they require a POSIX shell, but they
136may be used in Windows under Cygwin.)
1381. `markdown2pdf` produces a PDF file from markdown-formatted
139 text, using `pandoc` and `pdflatex`. The default
140 behavior of `markdown2pdf` is to create a file with the same
141 base name as the first argument and the extension `pdf`; thus,
142 for example,
144 markdown2pdf sample.txt endnotes.txt
146 will produce `sample.pdf`. (If `sample.pdf` exists already,
147 it will be backed up before being overwritten.) An output file
148 name can be specified explicitly using the `-o` option:
150 markdown2pdf -o book.pdf chap1 chap2
152 If no input file is specified, input will be taken from stdin.
153 All of `pandoc`'s options will work with `markdown2pdf` as well.
155 `markdown2pdf` assumes that `pdflatex` is in the path. It also
156 assumes that the following LaTeX packages are available:
157 `unicode`, `fancyhdr` (if you have verbatim text in footnotes),
158 `graphicx` (if you use images), `array` (if you use tables),
159 and `ulem` (if you use strikeout text). If they are not already
160 included in your LaTeX distribution, you can get them from
161 [CTAN]. A full [TeX Live] or [MacTeX] distribution will have all of
162 these packages.
1642. `html2markdown` grabs a web page from a file or URL and converts
165 it to markdown-formatted text, using `tidy` and `pandoc`.
167 All of `pandoc`'s options will work with `html2markdown` as well.
168 In addition, the following special options may be used.
169 The special options must be separated from the `html2markdown`
170 command and any regular Pandoc options by the delimiter `--`:
172 html2markdown -o out.txt -- -e latin1 -g curl google.com
174 The `-e` or `--encoding` option specifies the character encoding
175 of the HTML input. If this option is not specified, and input
176 is not from stdin, `html2markdown` will attempt to determine the
177 page's character encoding from the "Content-type" meta tag.
178 If this is not present, UTF-8 is assumed.
180 The `-g` or `--grabber` option specifies the command to be used to
181 fetch the contents of a URL:
183 html2markdown -g 'curl --user foo:bar' www.mysite.com
185 If this option is not specified, `html2markdown` searches for an
186 available program (`wget`, `curl`, or a text-mode browser) to fetch
187 the contents of a URL.
189 `html2markdown` requires [HTML Tidy], which must be in the path.
190 It uses [`iconv`] for character encoding conversions; if `iconv`
191 is absent, it will still work, but it will treat everything as UTF-8.
1933. `hsmarkdown` is designed to be used as a drop-in replacement for
194 `Markdown.pl`. It forces `pandoc` to convert from markdown to
195 HTML, and to use the `--strict` flag for maximal compliance with
196 official markdown syntax. (All of Pandoc's syntax extensions and
197 variants, described below, are disabled.) No other command-line
198 options are allowed. (In fact, options will be interpreted as
199 filenames.)
201 As an alternative to using the `hsmarkdown` shell script, the
202 user may create a symbolic link to `pandoc` called `hsmarkdown`.
203 When invoked under the name `hsmarkdown`, `pandoc` will behave
204 as if the `--strict` flag had been selected, and no command-line
205 options will be recognized. However, this approach does not work
206 under Cygwin, due to problems with its simulation of symbolic
207 links.
209[Cygwin]: http://www.cygwin.com/
210[HTML Tidy]: http://tidy.sourceforge.net/
211[`iconv`]: http://www.gnu.org/software/libiconv/
212[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
213[TeX Live]: http://www.tug.org/texlive/
214[MacTeX]: http://www.tug.org/mactex/
216Command-line options
217====================
219Various command-line options can be used to customize the output.
220For further documentation, see the `pandoc(1)` man page.
222`-f`, `--from`, `-r`, or `--read` *format*
223: specifies the input format (the format Pandoc will be converting
224 *from*). *format* can be `native`, `markdown`, `rst`, `html`, or
225 `latex`. (`+lhs` can be appended to indicate that the input should
226 be treated as literate Haskell source. See
227 [Literate Haskell support](#literate-haskell-support), below.)
229`-t`, `--to`, `-w`, or `--write` *format*
230: specifies the output format -- the format Pandoc will
231 be converting *to*. *format* can be `native`, `html`, `s5`,
232 `docbook`, `opendocument`, `latex`, `context`, `markdown`, `man`,
233 `rst`, and `rtf`. (`+lhs` can be appended to indicate that the
234 output should be treated as literate Haskell source. See
235 [Literate Haskell support](#literate-haskell-support), below.)
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.
244 (Exception: if the output format is `odt`, output to stdout
245 is disabled.)
247`-p` or `--preserve-tabs`
248: causes tabs in the source text to be preserved, rather than converted
249 to spaces (the default).
251`--tab-stop` *tabstop*
252: sets the number of spaces per tab to *tabstop* (defaults to 4).
254`--strict`
255: specifies that strict markdown syntax is to be used, without
256 pandoc's usual extensions and variants (described below). When the
257 input format is HTML, this means that constructs that have no
258 equivalents in standard markdown (e.g. definition lists or strikeout
259 text) will be parsed as raw HTML.
261`--reference-links`
262: causes reference-style links to be used in markdown
263 and reStructuredText output. By default inline links are used.
265`-R` or `--parse-raw`
266: causes the HTML and LaTeX readers to parse HTML codes and LaTeX
267 environments that it can't translate as raw HTML or LaTeX. Raw HTML can
268 be printed in markdown, reStructuredText, HTML, and S5 output; raw LaTeX
269 can be printed in markdown, reStructuredText, LaTeX, and ConTeXt output.
270 The default is for the readers to omit untranslatable HTML codes and
271 LaTeX environments. (The LaTeX reader does pass through untranslatable
272 LaTeX *commands*, even if `-R` is not specified.)
274`-C` or `--custom-header` *filename*
275: can be used to specify a custom document header. To see the headers
276 used by default, use the `-D` option: for example, `pandoc -D html`
277 prints the default HTML header.
279`--toc` or `--table-of-contents`
280: includes an automatically generated table of contents (or, in the
281 case of `latex`, `context`, and `rst`, an instruction to create
282 one) in the output document. This option has no effect with `man`,
283 `docbook`, or `s5` output formats.
285`-c` or `--css` *filename*
286: allows the user to specify a custom stylesheet that will be linked to
287 in HTML and S5 output. This option can be used repeatedly to include
288 multiple stylesheets. They will be included in the order specified.
290`-H` or `--include-in-header` *filename*
291: includes the contents of *filename* (verbatim) at the end of the
292 document header. This can be used, for example, to include special
293 CSS or javascript in HTML documents. This option can be used
294 repeatedly to include multiple files in the header. They will be
295 included in the order specified.
297`-B` or `--include-before-body` *filename*
298: includes the contents of *filename* (verbatim) at the beginning of
299 the document body (e.g. after the `<body>` tag in HTML, or the
300 `\begin{document}` command in LaTeX). This can be used to include
301 navigation bars or banners in HTML documents. This option can be
302 used repeatedly to include multiple files. They will be included in
303 the order specified.
305`-A` or `--include-after-body` *filename*
306: includes the contents of *filename* (verbatim) at the end of
307 the document body (before the `</body>` tag in HTML, or the
308 `\end{document}` command in LaTeX). This option can be be used
309 repeatedly to include multiple files. They will be included in the
310 order specified.
312`-P` *MODULE[,MODULE...]*, `--plugins`*=MODULE[,MODULE...]*
313: specifies plugins to load, by module name or source file pathname.
314 Plugins should export a function `transform` of type `a -> a`
315 or `a -> IO a`, where `a` is `Inline`, `Block`, `Pandoc`,
316 `[Inline]`, or `[Block]`. This function will be used to transform
317 the pandoc document after it is parsed by the reader and before it
318 is written out by the writer. (See below on [Plugins](#plugins).)
320`-T` or `--title-prefix` *string*
321: includes *string* as a prefix at the beginning of the title that
322 appears in the HTML header (but not in the title as it appears at
323 the beginning of the HTML body). (See below on
324 [Title Blocks](#title-blocks).)
326`-S` or `--smart`
327: causes `pandoc` to produce typographically correct output, along the
328 lines of John Gruber's [Smartypants]. Straight quotes are converted
329 to curly quotes, `---` to dashes, and `...` to ellipses. Nonbreaking
330 spaces are inserted after certain abbreviations, such as "Mr."
331 (Note: This option is only significant when the input format is
332 `markdown`. It is selected automatically when the output format is
333 `latex` or `context`.)
335`-m`*[url]* or `--latexmathml`*[=url]*
336: causes `pandoc` to use the [LaTeXMathML] script to display
337 TeX math in HTML or S5. If a local copy of `LaTeXMathML.js` is
338 available on the webserver where the page will be viewed, provide a
339 *url* and a link will be inserted in the generated HTML or S5. If
340 no *url* is provided, the contents of the script will be inserted
341 directly; this provides portability at the price of efficiency. If
342 you plan to use math on several pages, it is much better to link to
343 a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
344 `--gladtex`, and `--mimetex` for alternative ways of dealing with
345 math in HTML.)
347`--jsmath`*=[url]*
348: causes `pandoc` to use the [jsMath] script to display
349 TeX math in HTML or S5. The *url* should point to the jsMath load
350 script (e.g. `jsMath/easy/load.js`). If it is provided, a link to it
351 will be included in the header of standalone HTML documents.
352 (See `--latexmathml`, `--mimetex`, and `--gladtex` for alternative
353 ways of dealing with math in HTML.)
355`--gladtex`*[=url]*
356: causes TeX formulas to be enclosed in `<eq>` tags in HTML or S5 output.
357 This output can then be processed by [gladTeX] to produce links to
358 images with the typeset formulas. (See `--latexmathml`, `--jsmath`, and
359 `--mimetex` for alternative ways of dealing with math in HTML.)
361`--mimetex`*[=url]*
362: causes TeX formulas to be replaced by `<img>` tags linking to the
363 [mimeTeX] CGI script, which will produce images with the typeset
364 formulas. (See `--latexmathml`, `--jsmath`, and `--gladtex` for alternative
365 ways of dealing with math in HTML.)
367`-i` or `--incremental`
368: causes all lists in S5 output to be displayed incrementally by
369 default (one item at a time). The normal default is for lists to be
370 displayed all at once.
372`-N` or `--number-sections`
373: causes sections to be numbered in LaTeX or ConTeXt output. By default,
374 sections are not numbered.
376`--no-wrap`
377: disables text-wrapping in output. By default, text is wrapped
378 appropriately for the output format.
380`--sanitize-html`
381: sanitizes HTML (in markdown or HTML input) using a whitelist.
382 Unsafe tags are replaced by HTML comments; unsafe attributes
383 are omitted. URIs in links and images are also checked against a
384 whitelist of URI schemes.
386`--email-obfuscation`*=none|javascript|references*
387: specifies a method for obfuscating `mailto:` links in HTML documents.
388 *none* leaves `mailto:` links as they are. *javascript* obfuscates
389 them using javascript. *references* obfuscates them by printing their
390 letters as decimal or hexadecimal character references. If `--strict`
391 is specified, *references* is used regardless of the presence
392 of this option.
394`--dump-args`
395: is intended to make it easier to create wrapper scripts that use
396 Pandoc. It causes Pandoc to dump information about the arguments
397 with which it was called to stdout, then exit. The first line
398 printed is the name of the output file specified using the `-o`
399 or `--output` option, or `-` if output would go to stdout. The
400 remaining lines, if any, list command-line arguments. These will
401 include the names of input files and any special options passed
402 after ` -- ` on the command line. So, for example,
404: pandoc --dump-args -o foo.html -s foo.txt \
405 appendix.txt -- -e latin1
407: will cause the following to be printed to stdout:
409: foo.html foo.txt appendix.txt -e latin1
411`--ignore-args`
412: causes Pandoc to ignore all command-line arguments.
413 Regular Pandoc options are not ignored. Thus, for example,
415: pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
417: is equivalent to
419: pandoc -o foo.html -s
421`-v` or `--version`
422: prints the version number to STDERR.
424`-h` or `--help`
425: prints a usage message to STDERR.
427[Smartypants]: http://daringfireball.net/projects/smartypants/
428[LaTeXMathML]: http://math.etsu.edu/LaTeXMathML/
429[jsMath]: http://www.math.union.edu/~dpvc/jsmath/
430[gladTeX]: http://www.math.uio.no/~martingu/gladtex/index.html
431[mimeTeX]: http://www.forkosh.com/mimetex.html
433Pandoc's markdown vs. standard markdown
434=======================================
436In parsing markdown, Pandoc departs from and extends [standard markdown]
437in a few respects. (To run Pandoc on the official markdown test suite,
438type `make test-markdown`.) Except where noted, these differences can
439be suppressed by specifying the `--strict` command-line option or by
440using the `hsmarkdown` wrapper.
442[standard markdown]: http://daringfireball.net/projects/markdown/syntax
443 "Markdown syntax description"
445Backslash escapes
446-----------------
448Except inside a code block or inline code, any punctuation or space
449character preceded by a backslash will be treated literally, even if it
450would normally indicate formatting. Thus, for example, if one writes
452 *\*hello\**
454one will get
456 <em>*hello*</em>
458instead of
460 <strong>hello</strong>
462This rule is easier to remember than standard markdown's rule,
463which allows only the following characters to be backslash-escaped:
465 \`*_{}[]()>#+-.!
467A backslash-escaped space is parsed as a nonbreaking space. It will
468appear in TeX output as '~' and in HTML and XML as '\&#160;' or '\&nbsp;'.
470Subscripts and superscripts
471---------------------------
473Superscripts may be written by surrounding the superscripted text by `^`
474characters; subscripts may be written by surrounding the subscripted
475text by `~` characters. Thus, for example,
477 H~2~O is a liquid. 2^10^ is 1024.
479If the superscripted or subscripted text contains spaces, these spaces
480must be escaped with backslashes. (This is to prevent accidental
481superscripting and subscripting through the ordinary use of `~` and `^`.)
482Thus, if you want the letter P with 'a cat' in subscripts, use
483`P~a\ cat~`, not `P~a cat~`.
485Strikeout
486---------
488To strikeout a section of text with a horizontal line, begin and end it
489with `~~`. Thus, for example,
491 This ~~is deleted text.~~
493Nested Lists
494------------
496Pandoc behaves differently from standard markdown on some "edge
497cases" involving lists. Consider this source:
499 1. First
500 2. Second:
501 - Fee
502 - Fie
503 - Foe
505 3. Third
507Pandoc transforms this into a "compact list" (with no `<p>` tags around
508"First", "Second", or "Third"), while markdown puts `<p>` tags around
509"Second" and "Third" (but not "First"), because of the blank space
510around "Third". Pandoc follows a simple rule: if the text is followed by
511a blank line, it is treated as a paragraph. Since "Second" is followed
512by a list, and not a blank line, it isn't treated as a paragraph. The
513fact that the list is followed by a blank line is irrelevant. (Note:
514Pandoc works this way even when the `--strict` option is specified. This
515behavior is consistent with the official markdown syntax description,
516even though it is different from that of `Markdown.pl`.)
518Ordered Lists
519-------------
521Unlike standard markdown, Pandoc allows ordered list items to be marked
522with uppercase and lowercase letters and roman numerals, in addition to
523arabic numerals. (This behavior can be turned off using the `--strict`
524option.) List markers may be enclosed in parentheses or followed by a
525single right-parentheses or period. They must be separated from the
526text that follows by at least one space, and, if the list marker is a
527capital letter with a period, by at least two spaces.[^2]
529[^2]: The point of this rule is to ensure that normal paragraphs
530 starting with people's initials, like
532 B. Russell was an English philosopher.
534 do not get treated as list items.
536 This rule will not prevent
538 (C) 2007 Joe Smith
540 from being interpreted as a list item. In this case, a backslash
541 escape can be used:
543 (C\) 2007 Joe Smith
545Pandoc also pays attention to the type of list marker used, and to the
546starting number, and both of these are preserved where possible in the
547output format. Thus, the following yields a list with numbers followed
548by a single parenthesis, starting with 9, and a sublist with lowercase
549roman numerals:
551 9) Ninth
552 10) Tenth
553 11) Eleventh
554 i. subone
555 ii. subtwo
556 iii. subthree
558Note that Pandoc pays attention only to the *starting* marker in a list.
559So, the following yields a list numbered sequentially starting from 2:
561 (2) Two
562 (5) Three
563 1. Four
564 * Five
566If default list markers are desired, use '`#.`':
568 #. one
569 #. two
570 #. three
572Definition lists
573----------------
575Pandoc supports definition lists, using a syntax inspired by
576[PHP Markdown Extra] and [reStructuredText]:
578 [PHP Markdown Extra]: http://www.michelf.com/projects/php-markdown/extra/
580 Term 1
581 : Definition 1
583 Term 2
584 : Definition 2
586 : Second paragraph of definition 2.
588Each term must fit on one line. The definition must begin on the line
589after the term. The definition consists of one or more block elements
590(paragraph, code block, list, etc.), each beginning with a colon and
591(aside from the colon) indented one tab stop.
593 Term *with inline markup*
594 : Here is the definition. It may contain multiple blocks.
595 Here is some code:
597 : {* my code *}
599 : Here is the third paragraph of this definition.
601If you leave space after the definition (as in the first example above),
602the definitions will be considered paragraphs. In some output formats,
603this will mean greater spacing between term/definition pairs. For a
604compact definition list, do not leave space between the definition and
605the next term:
607 Term 1
608 : Definition 1
609 Term 2
610 : Definition 2
612Reference links
613---------------
615Pandoc allows implicit reference links with just a single set of
616brackets. So, the following links are equivalent:
618 1. Here's my [link]
619 2. Here's my [link][]
621 [link]: linky.com
623(Note: Pandoc works this way even if `--strict` is specified, because
624`Markdown.pl` 1.0.2b7 allows single-bracket links.)
626Footnotes
627---------
629Pandoc's markdown allows footnotes, using the following syntax:
631 Here is a footnote reference,[^1] and another.[^longnote]
633 [^1]: Here is the footnote.
635 [^longnote]: Here's one with multiple blocks.
637 Subsequent paragraphs are indented to show that they
638 belong to the previous footnote.
640 { some.code }
642 The whole paragraph can be indented, or just the first
643 line. In this way, multi-paragraph footnotes work like
644 multi-paragraph list items.
646 This paragraph won't be part of the note, because it isn't indented.
648The identifiers in footnote references may not contain spaces, tabs,
649or newlines. These identifiers are used only to correlate the
650footnote reference with the note itself; in the output, footnotes
651will be numbered sequentially.
653The footnotes themselves need not be placed at the end of the
654document. They may appear anywhere except inside other block elements
655(lists, block quotes, tables, etc.).
657Inline footnotes are also allowed (though, unlike regular notes,
658they cannot contain multiple paragraphs). The syntax is as follows:
660 Here is an inline note.^[Inlines notes are easier to write, since
661 you don't have to pick an identifier and move down to type the
662 note.]
664Inline and regular footnotes may be mixed freely.
666Tables
667------
669Two kinds of tables may be used. Both kinds presuppose the use of
670a fixed-width font, such as Courier.
672Simple tables look like this:
674 Right Left Center Default
675 ------- ------ ---------- -------
676 12 12 12 12
677 123 123 123 123
678 1 1 1 1
680 Table: Demonstration of simple table syntax.
682The headers and table rows must each fit on one line. Column
683alignments are determined by the position of the header text relative
684to the dashed line below it:[^3]
686 - If the dashed line is flush with the header text on the right side
687 but extends beyond it on the left, the column is right-aligned.
688 - If the dashed line is flush with the header text on the left side
689 but extends beyond it on the right, the column is left-aligned.
690 - If the dashed line extends beyond the header text on both sides,
691 the column is centered.
692 - If the dashed line is flush with the header text on both sides,
693 the default alignment is used (in most cases, this will be left).
695[^3]: This scheme is due to Michel Fortin, who proposed it on the
696 [Markdown discussion list](http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html).
698The table must end with a blank line. Optionally, a caption may be
699provided (as illustrated in the example above). A caption is a paragraph
700beginning with the string `Table:`, which will be stripped off.
702The table parser pays attention to the widths of the columns, and
703the writers try to reproduce these relative widths in the output.
704So, if you find that one of the columns is too narrow in the output,
705try widening it in the markdown source.
707Multiline tables allow headers and table rows to span multiple lines
708of text. Here is an example:
710 -------------------------------------------------------------
711 Centered Default Right Left
712 Header Aligned Aligned Aligned
713 ----------- ------- --------------- -------------------------
714 First row 12.0 Example of a row that
715 spans multiple lines.
717 Second row 5.0 Here's another one. Note
718 the blank line between
719 rows.
720 -------------------------------------------------------------
722 Table: Here's the caption. It, too, may span
723 multiple lines.
725These work like simple tables, but with the following differences:
727 - They must begin with a row of dashes, before the header text.
728 - They must end with a row of dashes, then a blank line.
729 - The rows must be separated by blank lines.
731Delimited Code blocks
732---------------------
734In addition to standard indented code blocks, Pandoc supports
735*delimited* code blocks. These begin with a row of three or more
736tildes (`~`) and end with a row of tildes that must be at least
737as long as the starting row. Everything between the tilde-lines
738is treated as code. No indentation is necessary:
740 ~~~~~~~
741 {code here}
742 ~~~~~~~
744If the code itself contains a row of tildes, just use a longer
745row of tildes at the start and end:
747 ~~~~~~~~~~~~~~~~
748 ~~~~~~~~~~
749 code including tildes
750 ~~~~~~~~~~
751 ~~~~~~~~~~~~~~~~
753Optionally, you may specify the language of the code block using
754this syntax:
756 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines}
757 qsort [] = []
758 qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
759 qsort (filter (>= x) xs)
760 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
762Some output formats can use this information to do syntax highlighting.
763Currently, the only output format that uses this information is HTML.
765If pandoc has been compiled with syntax highlighting support, then the
766code block above will appear highlighted, with numbered lines. (To see
767which languages are supported, do `pandoc --version`.)
769If pandoc has not been compiled with syntax highlighting support, the
770code block above will appear as follows:
772 <pre class="haskell">
773 <code>
774 ...
775 </code>
776 </pre>
778Title blocks
779------------
781If the file begins with a title block
783 % title
784 % author(s) (separated by commas)
785 % date
787it will be parsed as bibliographic information, not regular text. (It
788will be used, for example, in the title of standalone LaTeX or HTML
789output.) The block may contain just a title, a title and an author,
790or all three lines. Each must begin with a % and fit on one line.
791The title may contain standard inline formatting. If you want to
792include an author but no title, or a title and a date but no author,
793you need a blank line:
795 % My title
796 %
797 % June 15, 2006
799Titles will be written only when the `--standalone` (`-s`) option is
800chosen. In HTML output, titles will appear twice: once in the
801document head -- this is the title that will appear at the top of the
802window in a browser -- and once at the beginning of the document body.
803The title in the document head can have an optional prefix attached
804(`--title-prefix` or `-T` option). The title in the body appears as
805an H1 element with class "title", so it can be suppressed or
806reformatted with CSS. If a title prefix is specified with `-T` and no
807title block appears in the document, the title prefix will be used by
808itself as the HTML title.
810The man page writer extracts a title, man page section number, and
811other header and footer information from the title line. The title
812is assumed to be the first word on the title line, which may optionally
813end with a (single-digit) section number in parentheses. (There should
814be no space between the title and the parentheses.) Anything after
815this is assumed to be additional footer and header text. A single pipe
816character (`|`) should be used to separate the footer text from the header
817text. Thus,
819 % PANDOC(1)
821will yield a man page with the title `PANDOC` and section 1.
823 % PANDOC(1) Pandoc User Manuals
825will also have "Pandoc User Manuals" in the footer.
827 % PANDOC(1) Pandoc User Manuals | Version 4.0
829will also have "Version 4.0" in the header.
831Markdown in HTML blocks
832-----------------------
834While standard markdown leaves HTML blocks exactly as they are, Pandoc
835treats text between HTML tags as markdown. Thus, for example, Pandoc
836will turn
838 <table>
839 <tr>
840 <td>*one*</td>
841 <td>[a link](http://google.com)</td>
842 </tr>
843 </table>
845into
847 <table>
848 <tr>
849 <td><em>one</em></td>
850 <td><a href="http://google.com">a link</a></td>
851 </tr>
852 </table>
854whereas `Markdown.pl` will preserve it as is.
856There is one exception to this rule: text between `<script>` and
857`</script>` tags is not interpreted as markdown.
859This departure from standard markdown should make it easier to mix
860markdown with HTML block elements. For example, one can surround
861a block of markdown text with `<div>` tags without preventing it
862from being interpreted as markdown.
864Header identifiers in HTML
865--------------------------
867Each header element in pandoc's HTML output is given a unique
868identifier. This identifier is based on the text of the header. To
869derive the identifier from the header text,
871 - Remove all formatting, links, etc.
872 - Remove all punctuation, except dashes and hyphens.
873 - Replace all spaces, dashes, newlines, and hyphens with hyphens.
874 - Convert all alphabetic characters to lowercase.
875 - Remove everything up to the first letter (identifiers may
876 not begin with a number or punctuation mark).
877 - If nothing is left after this, use the identifier `section`.
879Thus, for example,
881 Header Identifier
882 ------------------------------------- ---------------------------
883 Header identifiers in HTML `header-identifiers-in-html`
884 *Dogs*?--in *my* house? `dogs--in-my-house`
885 [HTML], [S5], or [RTF]? `html-s5-or-rtf`
886 3. Applications `applications`
887 33 `section`
889These rules should, in most cases, allow one to determine the identifier
890from the header text. The exception is when several headers have the
891same text; in this case, the first will get an identifier as described
892above; the second will get the same identifier with `-1` appended; the
893third with `-2`; and so on.
895These identifiers are used to provide link targets in the table of
896contents generated by the `--toc|--table-of-contents` option. They
897also make it easy to provide links from one section of a document to
898another. A link to this section, for example, might look like this:
900 See the section on [header identifiers](#header-identifiers-in-html).
902Note, however, that this method of providing links to sections works
903only in HTML.
905Blank lines before headers and blockquotes
906------------------------------------------
908Standard markdown syntax does not require a blank line before a header
909or blockquote. Pandoc does require this (except, of course, at the
910beginning of the document). The reason for the requirement is that
911it is all too easy for a `>` or `#` to end up at the beginning of a
912line by accident (perhaps through line wrapping). Consider, for
913example:
915 I like several of their flavors of ice cream: #22, for example, and
916 #5.
918Math
919----
921Anything between two $ characters will be treated as TeX math. The
922opening $ must have a character immediately to its right, while the
923closing $ must have a character immediately to its left. Thus,
924`$20,000 and $30,000` won't parse as math. If for some reason
925you need to enclose text in literal $ characters, backslash-escape
926them and they won't be treated as math delimiters.
928TeX math will be printed in all output formats. In Markdown,
929reStructuredText, LaTeX, and ConTeXt output, it will appear verbatim
930between $ characters.
932In reStructuredText output, it will be rendered using an interpreted
933text role `:math:`, as described
934[here](http://www.american.edu/econ/itex2mml/mathhack.rst).
936In Texinfo output, it will be rendered inside a `@math` command.
938In groff man output, it will be rendered verbatim without $'s.
940In MediaWiki output, it will be rendered inside `<math>` tags.
942In RTF, Docbook, and OpenDocument output, it will be rendered, as far as
943possible, using unicode characters, and will otherwise appear verbatim.
944Unknown commands and symbols, and commands that cannot be dealt with
945this way (like `\frac`), will be rendered verbatim. So the results may
946be a mix of raw TeX code and properly rendered unicode math.
948In HTML and S5 output, the way math is rendered will depend on the
949command-line options selected:
9511. The default is to render TeX math as far as possible using unicode
952 characters, as with RTF, Docbook, and OpenDocument output. Formulas
953 are put inside a `span` with `class="math"`, so that they may be
954 styled differently from the surrounding text if needed.
9562. If the `--latexmathml` option is used, TeX math will be displayed
957 between $ or $$ characters and put in `<span>` tags with class `LaTeX`.
958 The [LaTeXMathML] script will be used to render it as formulas.
959 (This trick does not work in all browsers, but it works in Firefox.
960 In browsers that do not support LaTeXMathML, TeX math will appear
961 verbatim between $ characters.)
9633. If the `--jsmath` option is used, TeX math will be put inside
964 `<span>` tags (for inline math) or `<div>` tags (for display math)
965 with class `math`. The [jsMath] script will be used to render
966 it.
9684. If the `--mimetex` option is used, the [mimeTeX] CGI script will
969 be called to generate images for each TeX formula. This should
970 work in all browsers. The `--mimetex` option takes an optional URL
971 as argument. If no URL is specified, it will be assumed that the
972 mimeTeX CGI script is at `/cgi-bin/mimetex.cgi`.
9745. If the `--gladtex` option is used, TeX formulas will be enclosed
975 in `<eq>` tags in the HTML output. The resulting `htex` file may then
976 be processed by [gladTeX], which will produce image files for each
977 formula and an `html` file with links to these images. So, the
978 procedure is:
980 pandoc -s --gladtex myfile.txt -o myfile.htex
981 gladtex -d myfile-images myfile.htex # produces myfile.html
982 # and images in myfile-images
984Inline TeX
985----------
987Inline TeX commands will be preserved and passed unchanged to the
988LaTeX and ConTeXt writers. Thus, for example, you can use LaTeX to
989include BibTeX citations:
991 This result was proved in \cite{jones.1967}.
993Note that in LaTeX environments, like
995 \begin{tabular}{|l|l|}\hline
996 Age & Frequency \\ \hline
997 18--25 & 15 \\
998 26--35 & 33 \\
999 36--45 & 22 \\ \hline
1000 \end{tabular}
1002the material between the begin and end tags will be interpreted as raw
1003LaTeX, not as markdown.
1005Inline LaTeX is ignored in output formats other than Markdown, LaTeX,
1006and ConTeXt.
1008Custom headers
1009==============
1011When run with the "standalone" option (`-s`), `pandoc` creates a
1012standalone file, complete with an appropriate header. To see the
1013default headers used for html and latex, use the following commands:
1015 pandoc -D html
1017 pandoc -D latex
1019If you want to use a different header, just create a file containing
1020it and specify it on the command line as follows:
1022 pandoc --header=MyHeaderFile
1024Producing S5 with Pandoc
1025========================
1027Producing an [S5] web-based slide show with Pandoc is easy. A title
1028page is constructed automatically from the document's title block (see
1029above). Each section (with a level-one header) produces a single slide.
1030(Note that if the section is too big, the slide will not fit on the page;
1031S5 is not smart enough to produce multiple pages.)
1033Here's the markdown source for a simple slide show, `eating.txt`:
1035 % Eating Habits
1036 % John Doe
1037 % March 22, 2005
1039 # In the morning
1041 - Eat eggs
1042 - Drink coffee
1044 # In the evening
1046 - Eat spaghetti
1047 - Drink wine
1049To produce the slide show, simply type
1051 pandoc -w s5 -s eating.txt > eating.html
1053and open up `eating.html` in a browser.
1055Note that by default, the S5 writer produces lists that display
1056"all at once." If you want your lists to display incrementally
1057(one item at a time), use the `-i` option. If you want a
1058particular list to depart from the default (that is, to display
1059incrementally without the `-i` option and all at once with the
1060`-i` option), put it in a block quote:
1062 > - Eat spaghetti
1063 > - Drink wine
1065In this way incremental and nonincremental lists can be mixed in
1066a single document.
1068Note: the S5 file produced by pandoc with the `-s/--standalone` option
1069embeds the javascript and CSS required to show the slides. Thus it
1070does not depend on any additional files: you can send the HTML file to
1071others, and they will be able to view the slide show just by opening
1072it. However, if you intend to produce several S5 slide shows, and you
1073are displaying them on your own website, it is better to keep the S5
1074javascript and CSS files separate from the slide shows themselves, so
1075that they may be cached. The best approach in this case is to use pandoc
1076without the `-s` option to produce the body of the S5 document, which
1077can then be inserted into an HTML template that links to the javascript
1078and CSS files required by S5. (See the instructions on the S5 website.)
1079Alternatively, you may use `-s` together with the `-H/--custom-header`
1080option.
1082Literate Haskell support
1083========================
1085If you append `+lhs` to an appropriate input or output format (`markdown`,
1086`rst`, or `latex` for input or output; `html` for output only), pandoc
1087will treat the document as literate Haskell source. This means that
1089 - In markdown input, "bird track" sections will be parsed as Haskell
1090 code rather than block quotations. Text between `\begin{code}`
1091 and `\end{code}` will also be treated as Haskell code.
1093 - In markdown output, code blocks with class `haskell` will be
1094 rendered using bird tracks, and block quotations will be
1095 indented one space, so they will not be treated as Haskell code.
1096 In addition, headers will be rendered setext-style (with underlines)
1097 rather than atx-style (with '#' characters). (This is because ghc
1098 treats '#' characters in column 1 as introducing line numbers.)
1100 - In restructured text input, "bird track" sections will be parsed
1101 as Haskell code.
1103 - In restructured text output, code blocks with class `haskell` will
1104 be rendered using bird tracks.
1106 - In LaTeX input, text in `code` environments will be parsed as
1107 Haskell code.
1109 - In LaTeX output, code blocks with class `haskell` will be rendered
1110 inside `code` environments.
1112 - In HTML output, code blocks with class `haskell` will be rendered
1113 with class `literatehaskell` and bird tracks.
1115Examples:
1117 pandoc -f markdown+lhs -t html
1119reads literate Haskell source formatted with markdown conventions and writes
1120ordinary HTML (without bird tracks).
1122 pandoc -f markdown+lhs -t html+lhs
1124writes HTML with the Haskell code in bird tracks, so it can be copied
1125and pasted as literate Haskell source.
1127Plugins
1128=======
1130Pandoc's plugin system allows users to modify pandoc's behavior by writing
1131short Haskell programs. To how this works, and why it is useful, we
1132 need to understand that pandoc transforms one format (the source
1133format) into another (the target format) by first converting from the
1134source format into a Haskell data structure representing the document,
1135and then converting this data structure into the target format. For
1136example:
1138 -------------------------------------------------------------------------------
1139 Document Format Contents
1140 ------------ --------- -----------------------------------------------------
1141 source markdown `Hello *world*.`
1143 ↓ ↓ ↓
1145 intermediate native `Pandoc (Meta [] [] "")
1146 [Para [Str "Hello",Space,Emph [Str "world"],Str "."]]`
1148 ↓ ↓ ↓
1150 target HTML `<p>Hello <em>world</em>.</p>`
1151 -------------------------------------------------------------------------------
1153We can use standard text-processing tools (`perl`, `sed`, `awk`, etc.)
1154to modify the source or target documents. But what if we want to modify
1155the intermediate representation -- the parsed document -- before it is
1156written to the target format? That's where plugins are needed.
1157A plugin is a Haskell module that exports a function `transform`, which
1158will be used to transform the native representation, after it is generated
1159by the reader, but before it has been transformed by the writer.
1161An example will help make this clearer. Suppose we want to use pandoc with
1162the WordPress blog engine. WordPress provides support for LaTeX math, but
1163instead of `$e = mc^2$`, WordPress wants `$LaTeX e = mc^2$`. Prior to plugins,
1164there was no good way to make pandoc do this. We could have tried using
1165regex replacements on the markdown input or HTML output, but this would have
1166been error-prone: if someone writes `$e = mc^2$` in a code block, for
1167example, we wouldn't want to insert `LaTeX` there. There's no good way to
1168identify the math chunks without parsing the whole document. And pandoc
1169is already doing that, so why not make use of this work? By writing a
1170plugin, we can. Here's the whole plugin:
1172~~~ {.haskell}
1173-- WordPressPlugin.hs
1174module WordPressPlugin (transform) where
1175import Text.Pandoc
1177transform :: Inline -> Inline
1178transform (Math x y) = Math x $ "LaTeX " ++ y
1179transform x = x
1180~~~
1182This is a Haskell program, but a very short one. The lines
1184~~~ {.haskell}
1185module WordPressPlugin (transform) where
1186import Text.Pandoc
1187~~~
1189just define the name of the module (`WordPressPlugin`), the names of any
1190exported functions (for a plugin, this will always just be `transform`),
1191and the modules that will be used in the program itself (`Text.Pandoc`).
1192Every plugin must export a function named `transform`.
1194The real meat of the program is the three-line definition of `transform`:
1196~~~ {.haskell}
1197transform :: Inline -> Inline
1198transform (Math x y) = Math x $ "LaTeX " ++ y
1199transform x = x
1200~~~
1202The first line defines the type of the function: it is a function that
1203takes an `Inline` element and returns an `Inline` element. (For the definition
1204of `Inline`, see the module `Text.Pandoc.Definition`.) The `transform`
1205function in a plugin need not be `Inline -> Inline`, but it must have
1206type `a -> a` or `a -> IO a`, where `a` is `Pandoc`, `Block`, `Inline`,
1207`[Block]`, or `[Inline]`.
1209The next line says that when the input matches the pattern `Math x y`,
1210the string `LaTeX ` should be inserted at the beginning of `y`. (The `x`
1211just specifies whether the math element is inline or display math, so
1212we leave it alone.) The last line says, in effect, that the `transform`
1213function has no effect on any other kind of `Inline` element -- it just
1214passes it through. When the plugin is applied, this transformation will
1215be used on every `Inline` element in the document, and `LaTeX ` will be
1216inserted where needed in math elements.
1218To use this plugin, we just specify the module (or alternatively the filename)
1219with the `--plugins` option:
1221 % echo "Hello, $e=mc^2$." | pandoc -m --plugins=WordPressPlugin.hs
1222 <p
1223 >Hello, <span class="LaTeX"
1224 >$LaTeX e=mc^2$</span
1225 >.</p
1228Let's look at a more complex example, involving IO. Suppose we want to include
1229some [graphviz](http://www.graphviz.org/) diagrams in our document.
1230Of course, we could use a Makefile to generate the diagrams, then use
1231regular images in our document. But wouldn't it be nicer just to include
1232the graphviz code in the document itself, perhaps in a specially marked
1233delimited code block?
1235 ~~~ {.dot name="diagram1"}
1236 graph G {
1238 subgraph clusterA {
1239 a -- b;
1240 subgraph clusterC {
1241 C -- D;
1244 subgraph clusterB {
1245 d -- f
1247 d -- D
1248 e -- clusterB
1249 clusterC -- clusterB
1251 ~~~
1253This can be accomplished by a plugin:
1255~~~ {.haskell}
1256-- DotPlugin.hs
1257module DotPlugin (transform) where
1258import Text.Pandoc
1259import Text.Pandoc.Shared
1260import System.Process (readProcess)
1261import Data.Char (ord)
1262-- from the utf8-string package on HackageDB:
1263import Data.ByteString.Lazy.UTF8 (fromString)
1264-- from the SHA package on HackageDB:
1265import Data.Digest.Pure.SHA
1267transform :: Block -> IO Block
1268transform (CodeBlock (id, classes, namevals) contents) | "dot" `elem` classes = do
1269 let (name, outfile) = case lookup "name" namevals of
1270 Just fn -> ([Str fn], fn ++ ".png")
1271 Nothing -> ([], uniqueName contents ++ ".png")
1272 result <- readProcess "dot" ["-Tpng"] contents
1273 writeFile outfile result
1274 return $ Para [Image name (outfile, "")]
1275transform x = return x
1277-- | Generate a unique filename given the file's contents.
1278uniqueName :: String -> String
1279uniqueName = showDigest . sha1 . fromString
1280~~~
1282The heart of this plugin is the `transform` function, which converts a `Block`
1283to a `Block`. Again, there are two clauses, one for code blocks that are marked
1284with the "dot" class, one for all other blocks. Code blocks with ".dot" are
1285replaced with links to an image file; this file is generated by running
1286`dot -Tpng` on the contents of the code block.
1288Because `transform` performs file reads and writes, it needs to be in the
1289IO monad, hence the type: `Block -> IO Block`.
1291One more example. Suppose we want emphasized text to be CAPITALIZED
1292instead of italicized. We could use a plugin:
1294~~~ {.haskell}
1295module CapitalizeEmphasisPlugin (transform) where
1296import Text.Pandoc
1297import Data.Char (toUpper)
1299transform :: [Inline] -> [Inline]
1300transform (Emph xs : ys) = processWith capStr xs ++ transform ys
1301transform (x : ys) = x : transform ys
1302transform [] = []
1304capStr :: Inline -> Inline
1305capStr (Str x) = Str (map toUpper x)
1306capStr x = x
1307~~~
1309Here `transform` converts a whole list of `Inline` elements to another
1310such list. The key clause is
1312~~~ {.haskell}
1313transform (Emph xs : ys) = processWith capStr xs ++ transform ys
1314~~~
1316This applies the `capStr` function recursively to all inlines in the
1317list of emphasized inlines and puts the transformed list in place
1318of the original. `capStr` is a simple `Inline` transformation that
1319capitalizes `Str` elements and leaves everything else alone. The
1320function `processWith`, defined in `Text.Pandoc.Definition`, uses some
1321`Data.Generics` magic to apply its argument (here `capStr`) to every
1322`Inline` element in a list, including elements that are deeply buried in
1323other elements. Thus
1325 processWith captStr [Str "one", Strong [Str "two", Space]] ==>
1326 [Str "ONE", Strong [Str "TWO", Space]]
1328There are other sample plugins in the `plugins` subdirectory of the
1329pandoc source code.
1331**Note:** Do not attempt to use plugins when running pandoc in the
1332directory containing pandoc's source code. The interpreter will try to
1333load the files directly from the source code, rather than reading the compiled
1334versions, and pandoc will hang.