5Pandoc is a [Haskell] library for converting from one markup format
6to another, and a command-line tool that uses this library. It can read
7[markdown] and (subsets of) [reStructuredText], [HTML], and [LaTeX],
8and it can write [markdown], [reStructuredText], [HTML], [LaTeX], [RTF],
9and [S5] HTML slide shows. Pandoc's version of markdown contains some
10enhancements, like footnotes and embedded LaTeX.
12In contrast to existing tools for converting markdown to HTML, which
13use regex substitutions, Pandoc has a modular design: it consists of a
14set of readers, which parse text in a given format and produce a native
15representation of the document, and a set of writers, which convert
16this native representation into a target format. Thus, adding an input
17or output format requires only adding a reader or writer.
19[markdown]: http://daringfireball.net/projects/markdown/
20[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
21[S5]: http://meyerweb.com/eric/tools/s5/
22[HTML]: http://www.w3.org/TR/html40/
23[LaTeX]: http://www.latex-project.org/
24[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
25[Haskell]: http://www.haskell.org/
27(c) 2006 John MacFarlane (jgm at berkeley dot edu). Released under the
28[GPL], version 2 or greater. This software carries no warranty of
29any kind. (See COPYRIGHT for full copyright and warranty notices.)
30Recai Oktaş (roktas at debian dot org) deserves credit for the build
31system, the debian package, and the robust wrapper scripts.
33[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
38The `pandoc` program itself does not depend on any external libraries
39or programs. The convenience programs `markdown2html`, `markdown2latex`,
40`markdown2rst`, `markdown2rtf`, `markdown2s5`, `html2markdown`,
41`latex2markdown`, and `rst2markdown` are implemented as symbolic links to
44The wrapper script `web2markdown` requires
46 - `html2markdown` (included with Pandoc)
47 - a POSIX-compliant shell (installed by default on all linux and unix
48 systems, including Mac OS X, and in [Cygwin] for Windows),
50 - `iconv` (for character encoding conversion). (If `iconv` is absent,
51 `web2markdown` will still work, but it will treat everything as UTF-8.)
53[Cygwin]: http://www.cygwin.com/
54[HTML Tidy]: http://tidy.sourceforge.net/
55[`iconv`]: http://www.gnu.org/software/libiconv/
57The wrapper script `markdown2pdf` requires
59 - `markdown2latex` (included with Pandoc)
60 - a POSIX-compliant shell
61 - `pdflatex`, which should be part of any [LaTeX] distribution
62 - the [unicode] and [fancyvrb] LaTeX packages, which are included
63 in many LaTeX distributions. The [unicode] package allows LaTeX to
64 process UTF-8 characters. [fancyvrb] allows code blocks and verbatim
65 text to be used within footnotes. If your installation of LaTeX
66 does not include these packages, you will get an error (complaining
67 about missing `ucs.sty` or `fancyvrb.sty`) when you try to compile
68 a LaTeX file produced by Pandoc, or when you use the `markdown2pdf`
69 script (described below). If this happens, install the [unicode] and
70 [fancyvrb] packages package from [CTAN]. (Get the zip file from CTAN
71 and unpack it into `~/texmf/tex/latex/`. You may also need to run
72 `mktexlsr` or `texhash` before the files can be found by TeX.)
74[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
75[unicode]: http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/
76[fancyvrb]: http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/
81If you run `pandoc` without arguments, it will accept input from
82STDIN. If you run it with file names as arguments, it will take input
83from those files. It accepts several command-line options. For a
88The most important options specify the format of the source file and
89the output. The default reader is markdown; the default writer is
90HTML. So if you don't specify a reader or writer, `pandoc` will
91convert markdown to HTML. For example,
95will convert `hello.txt` from markdown to HTML. For other conversions,
96you must specify a reader and/or a writer using the `-r` and `-w`
97flags. To convert markdown to LaTeX, you would write:
99 pandoc -w latex hello.txt
101To convert html to markdown:
103 pandoc -r html -w markdown hello.txt
105Supported writers include `markdown`, `latex`, `html`, `rtf` (rich text
106format), `rst` (reStructuredText), and `s5` (which produces an HTML
107file that acts like powerpoint). Supported readers include `markdown`,
108`html`, `latex`, and `rst`. Note that the `rst` reader only parses
109a subset of reStructuredText syntax. For example, it doesn't handle
110tables, definition lists, option lists, or footnotes. It handles only the
111constructs expressible in unextended markdown. But for simple documents
112it should be adequate. The `latex` and `html` readers are also limited
113in what they can do. Because the `html` reader is picky about the HTML
114it parses, it is recommended that you pipe HTML through [HTML Tidy] before
115sending it to `pandoc`, or use the `web2markdown` script described below.
117By default, `pandoc` writes its output to STDOUT. If you want to
118write to a file, use the `-o` option or shell redirection:
120 pandoc -o hello.html hello.txt
122 pandoc hello.txt > hello.html
124Note that you can specify multiple input files on the command line.
125`pandoc` will concatenate them all (with blank lines between them)
128 pandoc -s chapter1.txt chapter2.txt references.txt > book.html
130(The `-s` option here tells `pandoc` to produce a standalone HTML file,
131with a proper header, rather than a fragment. For more details on this
132and many other command-line options, see below.)
137Unfortunately, due to limitations in GHC, `pandoc` does not automatically
138detect the system's local character encoding. Hence, all input and
139output is assumed to be in the UTF-8 encoding. If your local character
140encoding is not UTF-8 and you use accented or foreign characters,
141you should pipe the input and output through [`iconv`]. For example,
143 iconv -t utf-8 source.txt | pandoc | iconv -f utf-8 > output.html
145will convert `source.txt` from the local encoding to UTF-8, then
146convert it to HTML, then convert back to the local encoding,
147putting the output in `output.html`.
149The shell scripts (described below) automatically convert the input
150from the local encoding to UTF-8 before running them through `pandoc`,
151then convert the output back to the local encoding.
153Convenience programs and wrapper scripts
154========================================
156For convenience, eight variant programs are included with Pandoc:
157`markdown2html` (which is equivalent to `pandoc -w html`),
158`markdown2latex` (equivalent to `pandoc -w latex`), `markdown2rst`
159(equivalent to `pandoc -w rst`), `markdown2rtf` (equivalent to
160`pandoc -w rtf`), `markdown2s5` (equivalent to `pandoc -w s5`),
161`html2markdown` (equivalent to `pandoc -r html -w markdown`),
162`latex2markdown` (equivalent to `pandoc -r latex -w markdown`), and
163`rst2markdown` (equivalent to `pandoc -r rst -w markdown`). These
164programs take an appropriately restricted subset of `pandoc`'s
165options. (Run them with the `-h` flag for a full list of allowed
168Like `pandoc`, all of these programs produce fragments by default.
169If you want to produce a standalone file, complete with a header
170and footer appropriate to the format, use the `-s` option:
172 markdown2latex -s sample.txt > sample.tex
174Two shell scripts have also been included:
1761. `markdown2pdf` produces a PDF file from markdown-formatted
177 text, using `markdown2latex` and `pdflatex`. The default
178 behavior of `markdown2pdf` is to create a file with the same
179 base name as the first argument and the extension `pdf`; thus,
182 markdown2pdf sample.txt endnotes.txt
184 will produce `sample.pdf`. (If `sample.pdf` exists already,
185 it will be backed up before being overwritten.) An output file
186 name can be specified explicitly using the `-o` option:
188 markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
190 If no input file is specified, input will be taken from STDIN.
1922. `web2markdown` grabs a web page from a file or URL and converts
193 it to markdown-formatted text, using `tidy` and `html2markdown`.
194 Unless input is from STDIN, an attempt is made to determine the
195 character encoding of the page from the "Content-type" meta tag.
196 If this is not present, UTF-8 is assumed. Alternatively, a character
197 encoding may be specified explicitly using the `-e` option.
199 `web2markdown` searches for an available program (`wget`, `curl`,
200 or a text-mode browser) to fetch the contents of a URL.
201 Optionally, the `-g` command may be used to specify the command
204 web2markdown -g 'wget --user=foo --password=bar' mysite.com
209Various command-line options can be used to customize the output.
210For a complete list, type
214`-p` or `--preserve-tabs` causes tabs in the source text to be
215preserved, rather than converted to spaces (the default).
217`--tabstop` allows the user to set the tab stop (which defaults to 4).
219`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
220codes and LaTeX environments that it can't translate as raw HTML or
221LaTeX. Raw HTML can be printed in markdown, reStructuredText, HTML,
222and S5 output; raw LaTeX can be printed in markdown, reStructuredText,
223and LaTeX output. The default is for the readers to omit
224untranslatable HTML codes and LaTeX environments. (The LaTeX reader
225does pass through untranslatable LaTeX commands, even if `-R` is not
228`-s` or `--standalone` causes `pandoc` to produce a standalone file,
229complete with appropriate document headers. By default, `pandoc`
232`-o` or `--output-file` can be used to specify an output file.
234`-C` or `--custom-header` can be used to specify a custom document
235header. To see the headers used by default, use the `-D` option:
236for example, `pandoc -D html` prints the default HTML header.
238`-c` or `--css` allows the user to specify a custom stylesheet that
239will be linked to in HTML and S5 output.
241`-H` or `--include-in-header` specifies a file to be included
242(verbatim) at the end of the document header. This can be used, for
243example, to include special CSS or javascript in HTML documents.
245`-B` or `--include-before-body` specifies a file to be included
246(verbatim) at the beginning of the document body (after the `<body>`
247tag in HTML, or the `\begin{document}` command in LaTeX). This can be
248used to include navigation bars or banners in HTML documents.
250`-A` or `--include-after-body` specifies a file to be included
251(verbatim) at the end of the docment body (before the `</body>` tag in
252HTML, or the `\end{document}` command in LaTeX).
254`-T` or `--title-prefix` specifies a string to be included as a prefix
255at the beginning of the title that appears in the HTML header (but not
256in the title as it appears at the beginning of the HTML body). (See
259`-S` or `--smart` causes `pandoc` to produce typographically
260correct HTML output, along the lines of John Gruber's [Smartypants].
261Straight quotes are converted to curly quotes, `---` to dashes, and
264[Smartypants]: http://daringfireball.net/projects/smartypants/
266`-m` or `--asciimathml` will cause LaTeX formulas (between $ signs) in
267HTML or S5 to display as formulas rather than as code. The trick will
268not work in all browsers, but it works in Firefox. Peter Jipsen's
269[ASCIIMathML] script is used to do the magic.
271[ASCIIMathML]: http://www1.chapman.edu/~jipsen/mathml/asciimath.html
273`-i` or `--incremental` causes all lists in S5 output to be displayed
274incrementally by default (one item at a time). The normal default
275is for lists to be displayed all at once.
277`-N` or `--number-sections` causes sections to be numbered in LaTeX
278output. By default, sections are not numbered.
280`-d` or `--debug` causes a debugging message to be written to STDERR.
281The format of the message is as follows:
287Here `OUTPUT=` is followed by the name of the output file specified
288using `-o`, if any. If no output file was specified, `OUTPUT=`
289will appear with nothing following it. Lines beginning `INPUT=`
290specify input files. If there are no input files, no `INPUT=` lines
291will be printed. The `-d` option forces output to be written to
292STDOUT, even if an output file was specified using the `-o` option.
293(This option is provided to make it easier to write wrappers for
296`-v` or `--version` prints the version number to STDERR.
298`-h` or `--help` prints a usage message to STDERR.
300Pandoc's markdown vs. standard markdown
301=======================================
303In parsing markdown, Pandoc departs from and extends [standard markdown]
304in a few respects. (To run Pandoc on the official
305markdown test suite, type `make test-markdown`.)
307[standard markdown]: http://daringfireball.net/projects/markdown/syntax
308 "Markdown syntax description"
313Pandoc creates an invisible anchor in front of every HTML section
314heading. The ID of this anchor is derived from the section heading
315itself: spaces are converted to underscores, and formatting, links,
316and other markup are removed. Thus, for example, the source
318 ## Aristotle's *De Anima*
320gets converted to HTML as follows:
322 <a id="Aristotle's_De_Anima"></a>
323 <h2>Aristotle's <em>De Anima</em></h2>
325This makes it easy to provide internal links that jump to a particular
326place in a document. To provide a link to the heading above, for
329 [Back to Aristotle](#Aristotle's_De_Anima)
334Pandoc behaves differently from standard markdown on some "edge
335cases" involving lists. Consider this source:
345Pandoc transforms this into a "compact list" (with no `<p>` tags
346around "First", "Second", or "Third"), while markdown puts `<p>`
347tags around "Second" and "Third" (but not "First"), because of
348the blank space around "Third". Pandoc follows a simple rule:
349if the text is followed by a blank line, it is treated as a
350paragraph. Since "Second" is followed by a list, and not a blank
351line, it isn't treated as a paragraph. The fact that the list
352is followed by a blank line is irrelevant.
354Unlike standard markdown, Pandoc allows ordered list items to be
355marked with single letters, instead of numbers. So, for example,
356this source yields a nested ordered list:
364Pandoc also extends standard markdown in allowing list item markers
365to be terminated by ')':
373Note that Pandoc pays no attention to the *type* of ordered list
374item marker used. Thus, the following is treated just the same as
383Literal quotes in titles
384------------------------
386Standard markdown allows unescaped literal quotes in titles, as
389 [foo]: "bar "embedded" baz"
391Pandoc requires all quotes within titles to be escaped:
393 [foo]: "bar \"embedded\" baz"
398Pandoc allows implicit reference links in either of two styles:
401 2. Here's my [link][]
405If there's no corresponding reference, the implicit reference link
406will appear as regular bracketed text. Note: even `[link][]` will
407appear as `[link]` if there's no reference for `link`. If you want
408`[link][]`, use a backslash escape: `\[link]\[]`.
413Pandoc's markdown allows footnotes, using the following syntax:
415 Here is a footnote reference,[^1] and another.[^longnote]
417 [^1]: Here is the footnote. It can go anywhere in the document,
418 except in embedded contexts like block quotes or lists.
420 [^longnote]: Here's the other note. This one contains multiple
423 Subsequent paragraphs are indented to show that they belong to
424 the previous footnote.
428 The whole paragraph can be indented, or just the first line.
429 In this way, multi-paragraph footnotes work just like
430 multi-paragraph list items in markdown.
432 This paragraph won't be part of the note.
434The identifiers in footnote references may not contain spaces, tabs,
435or newlines. These identifiers are used only to correlate the
436footnote reference with the note itself; in the output, footnotes
437will be numbered sequentially.
439Inline footnotes are also allowed (though, unlike regular notes,
440they cannot contain multiple paragraphs). The syntax is as follows:
442 Here is an inline note.^[Inlines notes are easier to write, since
443 you don't have to pick an identifier and move down to type the
446Inline and regular footnotes may be mixed freely.
451Pandoc treats embedded HTML in markdown a bit differently than
452Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
453are, Pandoc treats text between HTML tags as markdown. Thus, for
454example, Pandoc will turn
459 <td>[a link](http://google.com)</td>
467 <td><em>one</em></td>
468 <td><a href="http://google.com">a link</a></td>
472whereas Markdown 1.0 will preserve it as is.
474There is one exception to this rule: text between `<script>` and
475`</script>` tags is not interpreted as markdown.
477This departure from standard markdown should make it easier to mix
478markdown with HTML block elements. For example, one can surround
479a block of markdown text with `<div>` tags without preventing it
480from being interpreted as markdown.
485If the file begins with a title block
488 % author(s) (separated by commas)
491it will be parsed as bibliographic information, not regular text. (It
492will be used, for example, in the title of standalone LaTeX or HTML
493output.) The block may contain just a title, a title and an author,
494or all three lines. Each must begin with a % and fit on one line.
495The title may contain standard inline formatting. If you want to
496include an author but no title, or a title and a date but no author,
497you need a blank line:
503Titles will be written only when the `--standalone` (`-s`) option is
504chosen. In HTML output, titles will appear twice: once in the
505document head -- this is the title that will appear at the top of the
506window in a browser -- and once at the beginning of the document body.
507The title in the document head can have an optional prefix attached
508(`--title-prefix` or `-T` option). The title in the body appears as
509an H1 element with class "title", so it can be suppressed or
512If a title prefix is specified with `-T` and no title block appears
513in the document, the title prefix will be used by itself as the
519Pandoc supports emacs-style boxquote block quotes, in addition to
520standard markdown (email-style) boxquotes:
523 | They look like this.
529Anything between two $ characters will be parsed as LaTeX math. The
530opening $ must have a character immediately to its right, while the
531closing $ must have a character immediately to its left. Thus,
532`$20,000 and $30,000` won't parse as math. The $ character can be
533escaped with a backslash if needed.
535If you pass the `-m` (`--asciimathml`) option to `pandoc`, it will
536include the [ASCIIMathML] script in the resulting HTML. This will
537cause LaTeX math to be displayed as formulas in better browsers.
539[ASCIIMathML]: http://www1.chapman.edu/~jipsen/asciimath.html
541Inline LaTeX commands will also be preserved and passed unchanged
542to the LaTeX writer. Thus, for example, you can use LaTeX to
543include BibTeX citations:
545 This result was proved in \cite{jones.1967}.
547You can also use LaTeX environments. For example,
549 \begin{tabular}{|l|l|}\hline
550 Age & Frequency \\ \hline
553 36--45 & 22 \\ \hline
556Note, however, that material between the begin and end tags will
557be interpreted as raw LaTeX, not as markdown.
562When run with the "standalone" option (`-s`), `pandoc` creates a
563standalone file, complete with an appropriate header. To see the
564default headers used for html and latex, use the following commands:
570If you want to use a different header, just create a file containing
571it and specify it on the command line as follows:
573 pandoc --header=MyHeaderFile
575Producing S5 with Pandoc
576========================
578Producing an [S5] web-based slide show with Pandoc is easy. A title
579page is constructed automatically from the document's title block (see
580above). Each section (with a level-one header) produces a single slide.
581(Note that if the section is too big, the slide will not fit on the page;
582S5 is not smart enough to produce multiple pages.)
584Here's the markdown source for a simple slide show, `eating.txt`:
600To produce the slide show, simply type
602 pandoc -w s5 -s eating.txt > eating.html
604and open up `eating.html` in a browser. The HTML file embeds
605all the required javascript and CSS, so no other files are necessary.
607Note that by default, the S5 writer produces lists that display
608"all at once." If you want your lists to display incrementally
609(one item at a time), use the `-i` option. If you want a
610particular list to depart from the default (that is, to display
611incrementally without the `-i` option and all at once with the
612`-i` option), put it in a block quote:
617In this way incremental and nonincremental lists can be mixed in
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list