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.
179 All of `pandoc`'s options will work with `markdown2pdf` as well.
1812. `html2markdown` grabs a web page from a file or URL and converts
182 it to markdown-formatted text, using `tidy` and `pandoc`.
184 All of `pandoc`'s options will work with `html2markdown` as well.
185 In addition, the following special options may be used.
186 The special options must be separated from the `html2markdown`
187 command and any regular Pandoc options by the delimiter `--`:
189 html2markdown -o out.txt -- -e latin1 -g curl google.com
191 The `-e` or `--encoding` option specifies the character encoding
192 of the HTML input. If this option is not specified, and input
193 is not from STDIN, `html2markdown` will attempt to determine the
194 page's character encoding from the "Content-type" meta tag.
195 If this is not present, UTF-8 is assumed.
197 The `-g` or `--grabber` option specifies the command to be used to
198 fetch the contents of a URL:
200 html2markdown -g 'curl --user foo:bar' www.mysite.com
202 If this option is not specified, `html2markdown` searches for an
203 available program (`wget`, `curl`, or a text-mode browser) to fetch
204 the contents of a URL.
2063. `hsmarkdown` is designed to be used as a drop-in replacement for
207 `Markdown.pl`. It forces `pandoc` to convert from markdown to
208 HTML, and to use the `--strict` flag for maximal compliance with
209 official markdown syntax. (All of Pandoc's syntax extensions and
210 variants, described below, are disabled.) No other command-line
211 options are allowed. (In fact, options will be interpreted as
217Various command-line options can be used to customize the output.
218For further documentation, see the `pandoc(1)` man page.
220`-f`, `--from`, `-r`, or `--read` can be used to specify the input
221format -- the format Pandoc will be converting *from*. Available
222formats are `native`, `markdown`, `rst`, `html`, and `latex`.
224`-t`, `--to`, `-w`, or `--write` can be used to specify the output
225format -- the format Pandoc will be converting *to*. Available formats
226are `native`, `html`, `s5`, `docbook`, `latex`, `markdown`, `rst`, and
229`-s` or `--standalone` indicates that a standalone document is to be
230produced (with appropriate headers and footers), rather than a fragment.
232`-o` or `--output` specifies the name of the output file. If this
233option is not specified, or if its argument is `-`, output will be sent
236`-p` or `--preserve-tabs` causes tabs in the source text to be
237preserved, rather than converted to spaces (the default).
239`--tabstop` allows the user to set the tab stop (which defaults to 4).
241`--strict` specifies that strict markdown syntax is to be used, without
242pandoc's usual extensions and variants (described below).
244`--inline-links` causes links in HTML to be parsed as inline links, rather
247`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
248codes and LaTeX environments that it can't translate as raw HTML or
249LaTeX. Raw HTML can be printed in markdown, reStructuredText, HTML,
250and S5 output; raw LaTeX can be printed in markdown, reStructuredText,
251and LaTeX output. The default is for the readers to omit
252untranslatable HTML codes and LaTeX environments. (The LaTeX reader
253does pass through untranslatable LaTeX commands, even if `-R` is not
256`-C` or `--custom-header` can be used to specify a custom document
257header. To see the headers used by default, use the `-D` option:
258for example, `pandoc -D html` prints the default HTML header.
260`-c` or `--css` allows the user to specify a custom stylesheet that
261will be linked to in HTML and S5 output.
263`-H` or `--include-in-header` specifies a file to be included
264(verbatim) at the end of the document header. This can be used, for
265example, to include special CSS or javascript in HTML documents.
267`-B` or `--include-before-body` specifies a file to be included
268(verbatim) at the beginning of the document body (after the `<body>`
269tag in HTML, or the `\begin{document}` command in LaTeX). This can be
270used to include navigation bars or banners in HTML documents.
272`-A` or `--include-after-body` specifies a file to be included
273(verbatim) at the end of the docment body (before the `</body>` tag in
274HTML, or the `\end{document}` command in LaTeX).
276`-T` or `--title-prefix` specifies a string to be included as a prefix
277at the beginning of the title that appears in the HTML header (but not
278in the title as it appears at the beginning of the HTML body). (See
281`-S` or `--smart` causes `pandoc` to produce typographically
282correct output, along the lines of John Gruber's [Smartypants].
283Straight quotes are converted to curly quotes, `---` to dashes, and
284`...` to ellipses. (Note: This option is only significant when
285the input format is `markdown`. It is selected automatically
286when the output format is `latex`.)
288[Smartypants]: http://daringfireball.net/projects/smartypants/
290`-m` or `--asciimathml` will cause LaTeX formulas (between $ signs) in
291HTML or S5 to display as formulas rather than as code. The trick will
292not work in all browsers, but it works in Firefox. Peter Jipsen's
293[ASCIIMathML] script is used to do the magic.
295[ASCIIMathML]: http://www1.chapman.edu/~jipsen/mathml/asciimath.html
297`-i` or `--incremental` causes all lists in S5 output to be displayed
298incrementally by default (one item at a time). The normal default
299is for lists to be displayed all at once.
301`-N` or `--number-sections` causes sections to be numbered in LaTeX
302output. By default, sections are not numbered.
304`--dump-args` is intended to make it easier to create wrapper scripts
305that use Pandoc. It causes Pandoc to dump information about the arguments
306with which it was called to STDOUT, then exit. The first line printed
307is the name of the output file specified using the `-o` or `--output`
308option, or `-` if output would go to STDOUT. The remaining lines, if any,
309list command-line arguments. These will include the names of input
310files and any special options passed after ` -- ` on the command line.
313 pandoc --dump-args -o foo.html -s foo.txt appendix.txt -- -e latin1
315will cause the following to be printed to STDOUT:
323`--ignore-args` causes Pandoc to ignore all command-line arguments.
324Regular Pandoc options are not ignored. Thus, for example,
326 pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
330 pandoc -o foo.html -s
332`-v` or `--version` prints the version number to STDERR.
334`-h` or `--help` prints a usage message to STDERR.
336Pandoc's markdown vs. standard markdown
337=======================================
339In parsing markdown, Pandoc departs from and extends [standard markdown]
340in a few respects. (To run Pandoc on the official markdown test suite,
341type `make test-markdown`.) Except where noted, these differences can
342be suppressed by specifying the `--strict` command-line option or by
343using the `hsmarkdown` wrapper.
345[standard markdown]: http://daringfireball.net/projects/markdown/syntax
346 "Markdown syntax description"
351Except inside a code block or inline code, any punctuation or space
352character preceded by a backslash will be treated literally, even if it
353would normally indicate formatting. Thus, for example, if one writes
363 <strong>hello</strong>
365This rule is easier to remember than standard markdown's rule,
366which allows only the following characters to be backslash-escaped:
373Pandoc behaves differently from standard markdown on some "edge
374cases" involving lists. Consider this source:
384Pandoc transforms this into a "compact list" (with no `<p>` tags
385around "First", "Second", or "Third"), while markdown puts `<p>`
386tags around "Second" and "Third" (but not "First"), because of
387the blank space around "Third". Pandoc follows a simple rule:
388if the text is followed by a blank line, it is treated as a
389paragraph. Since "Second" is followed by a list, and not a blank
390line, it isn't treated as a paragraph. The fact that the list
391is followed by a blank line is irrelevant. (Note: Pandoc works
392this way even when the `--strict` option is specified. This
393behavior is consistent with the official markdown syntax
394description, even though it is different from that of `Markdown.pl`.)
396Unlike standard markdown, Pandoc allows ordered list items to be
397marked with single letters, instead of numbers. So, for example,
398this source yields a nested ordered list:
406Pandoc also extends standard markdown in allowing list item markers
407to be terminated by ')':
415Note that Pandoc pays no attention to the *type* of ordered list
416item marker used. Thus, the following is treated just the same as
428Pandoc allows implicit reference links with just a single set of
429brackets. So, the following links are equivalent:
432 2. Here's my [link][]
436(Note: Pandoc works this way even if `--strict` is specified, because
437`Markdown.pl` 1.0.2b7 allows single-bracket links.)
442Pandoc's markdown allows footnotes, using the following syntax:
444 Here is a footnote reference,[^1] and another.[^longnote]
446 [^1]: Here is the footnote. It can go anywhere in the document,
447 except in embedded contexts like block quotes or lists.
449 [^longnote]: Here's the other note. This one contains multiple
452 Subsequent paragraphs are indented to show that they belong to
453 the previous footnote.
457 The whole paragraph can be indented, or just the first line.
458 In this way, multi-paragraph footnotes work just like
459 multi-paragraph list items in markdown.
461 This paragraph won't be part of the note.
463The identifiers in footnote references may not contain spaces, tabs,
464or newlines. These identifiers are used only to correlate the
465footnote reference with the note itself; in the output, footnotes
466will be numbered sequentially.
468Inline footnotes are also allowed (though, unlike regular notes,
469they cannot contain multiple paragraphs). The syntax is as follows:
471 Here is an inline note.^[Inlines notes are easier to write, since
472 you don't have to pick an identifier and move down to type the
475Inline and regular footnotes may be mixed freely.
480Two kinds of tables may be used. Both kinds presuppose the use of
481a fixed-width font, such as Courier. Currently only the HTML,
482Docbook, and LaTeX writers support tables.
484Simple tables look like this:
486 Right Left Center Default
487 ------- ------ ---------- -------
492 Table: Demonstration of simple table syntax.
494The headers and table rows must each fit on one line. Column
495alignments are determined by the position of the header text relative
496to the dashed line below it:[^2]
498 - If the dashed line is flush with the header text on the right side
499 but extends beyond it on the left, the column is right-aligned.
500 - If the dashed line is flush with the header text on the left side
501 but extends beyond it on the right, the column is left-aligned.
502 - If the dashed line extends beyond the header text on both sides,
503 the column is centered.
504 - If the dashed line is flush with the header text on both sides,
505 the default alignment is used (in most cases, this will be left).
507[^2]: This scheme is due to Michel Fortin, who proposed it on the
508 Markdown discussion list: <http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html>
510The table must end with a blank line. Optionally, a caption may be
511provided (as illustrated in the example above). A caption is a paragraph
512beginning with the string `Table:`, which will be stripped off.
514The table parser pays attention to the widths of the columns, and
515the writers try to reproduce these relative widths in the output.
516So, if you find that one of the columns is too narrow in the output,
517try widening it in the markdown source.
519Multiline tables allow headers and table rows to span multiple lines
520of text. Here is an example:
522 ---------------------------------------------------------------
524 Header Aligned Aligned Default aligned
525 ---------- --------- ----------- ---------------------------
526 First row 12.0 Example of a row that spans
529 Second row 5.0 Here's another one. Note
530 the blank line between rows.
531 ---------------------------------------------------------------
533 Table: Optional caption. This, too, may span multiple
536These work like simple tables, but with the following differences:
538 - They must begin with a row of dashes, before the header text.
539 - They must end with a row of dashes, then a blank line.
540 - The rows must be separated by blank lines.
545Pandoc treats embedded HTML in markdown a bit differently than
546Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
547are, Pandoc treats text between HTML tags as markdown. Thus, for
548example, Pandoc will turn
553 <td>[a link](http://google.com)</td>
561 <td><em>one</em></td>
562 <td><a href="http://google.com">a link</a></td>
566whereas `Markdown.pl` will preserve it as is.
568There is one exception to this rule: text between `<script>` and
569`</script>` tags is not interpreted as markdown.
571This departure from standard markdown should make it easier to mix
572markdown with HTML block elements. For example, one can surround
573a block of markdown text with `<div>` tags without preventing it
574from being interpreted as markdown.
579If the file begins with a title block
582 % author(s) (separated by commas)
585it will be parsed as bibliographic information, not regular text. (It
586will be used, for example, in the title of standalone LaTeX or HTML
587output.) The block may contain just a title, a title and an author,
588or all three lines. Each must begin with a % and fit on one line.
589The title may contain standard inline formatting. If you want to
590include an author but no title, or a title and a date but no author,
591you need a blank line:
597Titles will be written only when the `--standalone` (`-s`) option is
598chosen. In HTML output, titles will appear twice: once in the
599document head -- this is the title that will appear at the top of the
600window in a browser -- and once at the beginning of the document body.
601The title in the document head can have an optional prefix attached
602(`--title-prefix` or `-T` option). The title in the body appears as
603an H1 element with class "title", so it can be suppressed or
606If a title prefix is specified with `-T` and no title block appears
607in the document, the title prefix will be used by itself as the
613Pandoc supports emacs-style boxquote block quotes, in addition to
614standard markdown (email-style) boxquotes:
617 | They look like this.
620Blank lines before headers and blockquotes
621------------------------------------------
623Standard markdown syntax does not require a blank line before a header
624or blockquote. Pandoc does require this (except, of course, at the
625beginning of the document). The reason for the requirement is that
626it is all too easy for a `>` or `#` to end up at the beginning of a
627line by accident (perhaps through line wrapping). Consider, for
630 I like several of their flavors of ice cream: #22, for example, and
636Anything between two $ characters will be parsed as LaTeX math. The
637opening $ must have a character immediately to its right, while the
638closing $ must have a character immediately to its left. Thus,
639`$20,000 and $30,000` won't parse as math. The $ character can be
640escaped with a backslash if needed.
642If you pass the `-m` (`--asciimathml`) option to `pandoc`, it will
643include the [ASCIIMathML] script in the resulting HTML. This will
644cause LaTeX math to be displayed as formulas in better browsers.
646[ASCIIMathML]: http://www1.chapman.edu/~jipsen/asciimath.html
648Inline LaTeX commands will also be preserved and passed unchanged
649to the LaTeX writer. Thus, for example, you can use LaTeX to
650include BibTeX citations:
652 This result was proved in \cite{jones.1967}.
654You can also use LaTeX environments. For example,
656 \begin{tabular}{|l|l|}\hline
657 Age & Frequency \\ \hline
660 36--45 & 22 \\ \hline
663Note, however, that material between the begin and end tags will
664be interpreted as raw LaTeX, not as markdown.
669When run with the "standalone" option (`-s`), `pandoc` creates a
670standalone file, complete with an appropriate header. To see the
671default headers used for html and latex, use the following commands:
677If you want to use a different header, just create a file containing
678it and specify it on the command line as follows:
680 pandoc --header=MyHeaderFile
682Producing S5 with Pandoc
683========================
685Producing an [S5] web-based slide show with Pandoc is easy. A title
686page is constructed automatically from the document's title block (see
687above). Each section (with a level-one header) produces a single slide.
688(Note that if the section is too big, the slide will not fit on the page;
689S5 is not smart enough to produce multiple pages.)
691Here's the markdown source for a simple slide show, `eating.txt`:
707To produce the slide show, simply type
709 pandoc -w s5 -s eating.txt > eating.html
711and open up `eating.html` in a browser. The HTML file embeds
712all the required javascript and CSS, so no other files are necessary.
714Note that by default, the S5 writer produces lists that display
715"all at once." If you want your lists to display incrementally
716(one item at a time), use the `-i` option. If you want a
717particular list to depart from the default (that is, to display
718incrementally without the `-i` option and all at once with the
719`-i` option), put it in a block quote:
724In 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