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],
9[DocBook XML], and [S5] HTML slide shows. Pandoc's version of markdown
10contains some enhancements, 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[DocBook XML]: http://www.docbook.org/
26[Haskell]: http://www.haskell.org/
28(c) 2006 John MacFarlane (jgm at berkeley dot edu). Released under the
29[GPL], version 2 or greater. This software carries no warranty of
30any kind. (See COPYRIGHT for full copyright and warranty notices.)
31Recai Oktaş (roktas at debian dot org) deserves credit for the build
32system, the debian package, and the robust wrapper scripts.
34[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
39The `pandoc` program itself does not depend on any external libraries
42The wrapper script `html2markdown` requires
44 - `pandoc` (which must be in the PATH)
45 - a POSIX-compliant shell (installed by default on all linux and unix
46 systems, including Mac OS X, and in [Cygwin] for Windows),
48 - `iconv` (for character encoding conversion). (If `iconv` is absent,
49 `html2markdown` will still work, but it will treat everything as UTF-8.)
51The wrapper script `markdown2pdf` requires
53 - `pandoc` (which must be in the PATH)
54 - a POSIX-compliant shell
55 - `pdflatex`, which should be part of any [LaTeX] distribution
56 - the [unicode] and [fancyvrb] LaTeX packages, which are included
57 in many LaTeX distributions.[^1] If your installation of LaTeX
58 does not include these packages, you will get an error (complaining
59 about missing `ucs.sty` or `fancyvrb.sty`) when you try to compile
60 a LaTeX file produced by Pandoc, or when you use the `markdown2pdf`
61 script (described below). If this happens, install the [unicode] and
62 [fancyvrb] packages package from [CTAN]. (Get the zip file from CTAN
63 and unpack it into `~/texmf/tex/latex/`. You may also need to run
64 `mktexlsr` or `texhash` before the files can be found by TeX.)
66The wrapper script `hsmarkdown` requires only a POSIX-compliant shell.
68[Cygwin]: http://www.cygwin.com/
69[HTML Tidy]: http://tidy.sourceforge.net/
70[`iconv`]: http://www.gnu.org/software/libiconv/
71[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
72[unicode]: http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/
73[fancyvrb]: http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/
75[^1]: The [unicode] package allows LaTeX to process UTF-8 characters.
76[fancyvrb] allows code blocks and verbatim text to be used within
82If you run `pandoc` without arguments, it will accept input from
83STDIN. If you run it with file names as arguments, it will take input
84from those files. By default, `pandoc` writes its output to STDOUT.
85If you want to write to a file, use the `-o` option:
87 pandoc -o hello.html hello.txt
89Note that you can specify multiple input files on the command line.
90`pandoc` will concatenate them all (with blank lines between them)
93 pandoc -s chapter1.txt chapter2.txt references.txt > book.html
95(The `-s` option here tells `pandoc` to produce a standalone HTML file,
96with a proper header, rather than a fragment. For more details on this
97and many other command-line options, see below.)
99The format of the input and output can be specified explicitly using
100command-line options. The input format can be specified using the
101`-r/--read` or `-f/--from` options, the output format using the
102`-w/--write` or `-t/--to` options. Thus, to convert `hello.txt` from
103markdown to LaTeX, you could type:
105 pandoc -f markdown -t latex hello.txt
107To convert `hello.html` from html to markdown:
109 pandoc -f html -t markdown hello.html
111Supported output formats include `markdown`, `latex`, `html`, `rtf`
112(rich text format), `rst` (reStructuredText), `docbook` (DocBook
113XML), and `s5` (which produces an HTML file that acts like powerpoint).
114Supported input formats include `markdown`, `html`, `latex`, and `rst`.
115Note that the `rst` reader only parses a subset of reStructuredText
116syntax. For example, it doesn't handle tables, definition lists, option
117lists, or footnotes. It handles only the constructs expressible in
118unextended markdown. But for simple documents it should be adequate.
119The `latex` and `html` readers are also limited in what they can do.
120Because the `html` reader is picky about the HTML it parses, it is
121recommended that you pipe HTML through [HTML Tidy] before sending it to
122`pandoc`, or use the `html2markdown` script described below.
124If you don't specify a reader or writer explicitly, `pandoc` will
125try to determine the input and output format from the extensions of
126the input and output filenames. Thus, for example,
128 pandoc -o hello.tex hello.txt
130will convert `hello.txt` from markdown to LaTeX. If no output file
131is specified (so that output goes to STDOUT), or if the output file's
132extension is unknown, the output format will default to HTML.
133If no input file is specified (so that input comes from STDIN), or
134if the input files' extensions are unknown, the input format will
135be assumed to be markdown unless explicitly specified.
140Unfortunately, due to limitations in GHC, `pandoc` does not automatically
141detect the system's local character encoding. Hence, all input and
142output is assumed to be in the UTF-8 encoding. If your local character
143encoding is not UTF-8 and you use accented or foreign characters,
144you should pipe the input and output through [`iconv`]. For example,
146 iconv -t utf-8 source.txt | pandoc | iconv -f utf-8 > output.html
148will convert `source.txt` from the local encoding to UTF-8, then
149convert it to HTML, then convert back to the local encoding,
150putting the output in `output.html`.
152The shell scripts (described below) automatically convert the input
153from the local encoding to UTF-8 before running them through `pandoc`,
154then convert the output back to the local encoding.
156`markdown2pdf`, `html2markdown`, and `hsmarkdown`
157=================================================
159Three shell scripts, `markdown2pdf`, `html2markdown`, and `hsmarkdown`,
160are included in the standard Pandoc installation. (They are not included
161in the Windows binary package, as they require a POSIX shell, but they
162may be used in Windows under Cygwin.)
1641. `markdown2pdf` produces a PDF file from markdown-formatted
165 text, using `pandoc` and `pdflatex`. The default
166 behavior of `markdown2pdf` is to create a file with the same
167 base name as the first argument and the extension `pdf`; thus,
170 markdown2pdf sample.txt endnotes.txt
172 will produce `sample.pdf`. (If `sample.pdf` exists already,
173 it will be backed up before being overwritten.) An output file
174 name can be specified explicitly using the `-o` option:
176 markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
178 If no input file is specified, input will be taken from STDIN.
1802. `html2markdown` grabs a web page from a file or URL and converts
181 it to markdown-formatted text, using `tidy` and `pandoc`.
182 Unless input is from STDIN, an attempt is made to determine the
183 character encoding of the page from the "Content-type" meta tag.
184 If this is not present, UTF-8 is assumed. Alternatively, a character
185 encoding may be specified explicitly using the `-e` option.
187 `html2markdown` searches for an available program (`wget`, `curl`,
188 or a text-mode browser) to fetch the contents of a URL.
189 Optionally, the `-g` command may be used to specify the command
192 html2markdown -g 'wget --user=foo --password=bar' mysite.com
1943. `hsmarkdown` is designed to be used as a drop-in replacement for
195 `Markdown.pl`. It forces `pandoc` to convert from markdown to
196 HTML, and to use the `--strict` flag for maximal compliance with
197 official markdown syntax. (All of Pandoc's syntax extensions and
198 variants, described below, are disabled.) No other command-line
199 options are allowed. (In fact, options will be interpreted as
205Various command-line options can be used to customize the output.
207`-f`, `--from`, `-r`, or `--read` can be used to specify the input
208format -- the format Pandoc will be converting *from*. Available
209formats are `native`, `markdown`, `rst`, `html`, and `latex`.
211`-t`, `--to`, `-w`, or `--write` can be used to specify the output
212format -- the format Pandoc will be converting *to*. Available formats
213are `native`, `html`, `s5`, `docbook`, `latex`, `markdown`, `rst`, and
216`-s` or `--standalone` indicates that a standalone document is to be
217produced (with appropriate headers and footers), rather than a fragment.
219`-o` or `--output` specifies the name of the output file. If no output
220filename is given, output will be sent to STDOUT.
222`-p` or `--preserve-tabs` causes tabs in the source text to be
223preserved, rather than converted to spaces (the default).
225`--tabstop` allows the user to set the tab stop (which defaults to 4).
227`--strict` specifies that strict markdown syntax is to be used, without
228pandoc's usual extensions and variants (described below).
230`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
231codes and LaTeX environments that it can't translate as raw HTML or
232LaTeX. Raw HTML can be printed in markdown, reStructuredText, HTML,
233and S5 output; raw LaTeX can be printed in markdown, reStructuredText,
234and LaTeX output. The default is for the readers to omit
235untranslatable HTML codes and LaTeX environments. (The LaTeX reader
236does pass through untranslatable LaTeX commands, even if `-R` is not
239`-C` or `--custom-header` can be used to specify a custom document
240header. To see the headers used by default, use the `-D` option:
241for example, `pandoc -D html` prints the default HTML header.
243`-c` or `--css` allows the user to specify a custom stylesheet that
244will be linked to in HTML and S5 output.
246`-H` or `--include-in-header` specifies a file to be included
247(verbatim) at the end of the document header. This can be used, for
248example, to include special CSS or javascript in HTML documents.
250`-B` or `--include-before-body` specifies a file to be included
251(verbatim) at the beginning of the document body (after the `<body>`
252tag in HTML, or the `\begin{document}` command in LaTeX). This can be
253used to include navigation bars or banners in HTML documents.
255`-A` or `--include-after-body` specifies a file to be included
256(verbatim) at the end of the docment body (before the `</body>` tag in
257HTML, or the `\end{document}` command in LaTeX).
259`-T` or `--title-prefix` specifies a string to be included as a prefix
260at the beginning of the title that appears in the HTML header (but not
261in the title as it appears at the beginning of the HTML body). (See
264`-S` or `--smart` causes `pandoc` to produce typographically
265correct HTML output, along the lines of John Gruber's [Smartypants].
266Straight quotes are converted to curly quotes, `---` to dashes, and
269[Smartypants]: http://daringfireball.net/projects/smartypants/
271`-m` or `--asciimathml` will cause LaTeX formulas (between $ signs) in
272HTML or S5 to display as formulas rather than as code. The trick will
273not work in all browsers, but it works in Firefox. Peter Jipsen's
274[ASCIIMathML] script is used to do the magic.
276[ASCIIMathML]: http://www1.chapman.edu/~jipsen/mathml/asciimath.html
278`-i` or `--incremental` causes all lists in S5 output to be displayed
279incrementally by default (one item at a time). The normal default
280is for lists to be displayed all at once.
282`-N` or `--number-sections` causes sections to be numbered in LaTeX
283output. By default, sections are not numbered.
285`-d` or `--debug` causes a debugging message to be written to STDERR.
286The format of the message is as follows:
292Here `OUTPUT=` is followed by the name of the output file specified
293using `-o`, if any. If no output file was specified, `OUTPUT=`
294will appear with nothing following it. Lines beginning `INPUT=`
295specify input files. If there are no input files, no `INPUT=` lines
296will be printed. The `-d` option forces output to be written to
297STDOUT, even if an output file was specified using the `-o` option.
298(This option is provided to make it easier to write wrappers for
301`-v` or `--version` prints the version number to STDERR.
303`-h` or `--help` prints a usage message to STDERR.
305Pandoc's markdown vs. standard markdown
306=======================================
308In parsing markdown, Pandoc departs from and extends [standard markdown]
309in a few respects. (To run Pandoc on the official
310markdown test suite, type `make test-markdown`.) These differences can
311be suppressed by specifying the `--strict` command-line option or by
312using the `hsmarkdown` wrapper.
314[standard markdown]: http://daringfireball.net/projects/markdown/syntax
315 "Markdown syntax description"
320Pandoc behaves differently from standard markdown on some "edge
321cases" involving lists. Consider this source:
331Pandoc transforms this into a "compact list" (with no `<p>` tags
332around "First", "Second", or "Third"), while markdown puts `<p>`
333tags around "Second" and "Third" (but not "First"), because of
334the blank space around "Third". Pandoc follows a simple rule:
335if the text is followed by a blank line, it is treated as a
336paragraph. Since "Second" is followed by a list, and not a blank
337line, it isn't treated as a paragraph. The fact that the list
338is followed by a blank line is irrelevant. (Note: Pandoc works
339this way even when the `--strict` option is specified. This
340behavior is consistent with the official markdown syntax
341description, even though it is different from that of `Markdown.pl`.)
343Unlike standard markdown, Pandoc allows ordered list items to be
344marked with single letters, instead of numbers. So, for example,
345this source yields a nested ordered list:
353Pandoc also extends standard markdown in allowing list item markers
354to be terminated by ')':
362Note that Pandoc pays no attention to the *type* of ordered list
363item marker used. Thus, the following is treated just the same as
375Pandoc allows implicit reference links with just a single set of
376brackets. So, the following links are equivalent:
379 2. Here's my [link][]
386Pandoc's markdown allows footnotes, using the following syntax:
388 Here is a footnote reference,[^1] and another.[^longnote]
390 [^1]: Here is the footnote. It can go anywhere in the document,
391 except in embedded contexts like block quotes or lists.
393 [^longnote]: Here's the other note. This one contains multiple
396 Subsequent paragraphs are indented to show that they belong to
397 the previous footnote.
401 The whole paragraph can be indented, or just the first line.
402 In this way, multi-paragraph footnotes work just like
403 multi-paragraph list items in markdown.
405 This paragraph won't be part of the note.
407The identifiers in footnote references may not contain spaces, tabs,
408or newlines. These identifiers are used only to correlate the
409footnote reference with the note itself; in the output, footnotes
410will be numbered sequentially.
412Inline footnotes are also allowed (though, unlike regular notes,
413they cannot contain multiple paragraphs). The syntax is as follows:
415 Here is an inline note.^[Inlines notes are easier to write, since
416 you don't have to pick an identifier and move down to type the
419Inline and regular footnotes may be mixed freely.
424Pandoc treats embedded HTML in markdown a bit differently than
425Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
426are, Pandoc treats text between HTML tags as markdown. Thus, for
427example, Pandoc will turn
432 <td>[a link](http://google.com)</td>
440 <td><em>one</em></td>
441 <td><a href="http://google.com">a link</a></td>
445whereas `Markdown.pl` will preserve it as is.
447There is one exception to this rule: text between `<script>` and
448`</script>` tags is not interpreted as markdown.
450This departure from standard markdown should make it easier to mix
451markdown with HTML block elements. For example, one can surround
452a block of markdown text with `<div>` tags without preventing it
453from being interpreted as markdown.
458If the file begins with a title block
461 % author(s) (separated by commas)
464it will be parsed as bibliographic information, not regular text. (It
465will be used, for example, in the title of standalone LaTeX or HTML
466output.) The block may contain just a title, a title and an author,
467or all three lines. Each must begin with a % and fit on one line.
468The title may contain standard inline formatting. If you want to
469include an author but no title, or a title and a date but no author,
470you need a blank line:
476Titles will be written only when the `--standalone` (`-s`) option is
477chosen. In HTML output, titles will appear twice: once in the
478document head -- this is the title that will appear at the top of the
479window in a browser -- and once at the beginning of the document body.
480The title in the document head can have an optional prefix attached
481(`--title-prefix` or `-T` option). The title in the body appears as
482an H1 element with class "title", so it can be suppressed or
485If a title prefix is specified with `-T` and no title block appears
486in the document, the title prefix will be used by itself as the
492Pandoc supports emacs-style boxquote block quotes, in addition to
493standard markdown (email-style) boxquotes:
496 | They look like this.
499Blank lines before headers and blockquotes
500------------------------------------------
502Standard markdown syntax does not require a blank line before a header
503or blockquote. Pandoc does require this (except, of course, at the
504beginning of the document). The reason for the requirement is that
505it is all too easy for a `>` or `#` to end up at the beginning of a
506line by accident (perhaps through line wrapping). Consider, for
509 I like several of their flavors of ice cream: #22, for example, and
515Anything between two $ characters will be parsed as LaTeX math. The
516opening $ must have a character immediately to its right, while the
517closing $ must have a character immediately to its left. Thus,
518`$20,000 and $30,000` won't parse as math. The $ character can be
519escaped with a backslash if needed.
521If you pass the `-m` (`--asciimathml`) option to `pandoc`, it will
522include the [ASCIIMathML] script in the resulting HTML. This will
523cause LaTeX math to be displayed as formulas in better browsers.
525[ASCIIMathML]: http://www1.chapman.edu/~jipsen/asciimath.html
527Inline LaTeX commands will also be preserved and passed unchanged
528to the LaTeX writer. Thus, for example, you can use LaTeX to
529include BibTeX citations:
531 This result was proved in \cite{jones.1967}.
533You can also use LaTeX environments. For example,
535 \begin{tabular}{|l|l|}\hline
536 Age & Frequency \\ \hline
539 36--45 & 22 \\ \hline
542Note, however, that material between the begin and end tags will
543be interpreted as raw LaTeX, not as markdown.
548When run with the "standalone" option (`-s`), `pandoc` creates a
549standalone file, complete with an appropriate header. To see the
550default headers used for html and latex, use the following commands:
556If you want to use a different header, just create a file containing
557it and specify it on the command line as follows:
559 pandoc --header=MyHeaderFile
561Producing S5 with Pandoc
562========================
564Producing an [S5] web-based slide show with Pandoc is easy. A title
565page is constructed automatically from the document's title block (see
566above). Each section (with a level-one header) produces a single slide.
567(Note that if the section is too big, the slide will not fit on the page;
568S5 is not smart enough to produce multiple pages.)
570Here's the markdown source for a simple slide show, `eating.txt`:
586To produce the slide show, simply type
588 pandoc -w s5 -s eating.txt > eating.html
590and open up `eating.html` in a browser. The HTML file embeds
591all the required javascript and CSS, so no other files are necessary.
593Note that by default, the S5 writer produces lists that display
594"all at once." If you want your lists to display incrementally
595(one item at a time), use the `-i` option. If you want a
596particular list to depart from the default (that is, to display
597incrementally without the `-i` option and all at once with the
598`-i` option), put it in a block quote:
603In 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