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.
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
214 As an alternative to using the `hsmarkdown` shell script, the
215 user may create a symbolic link to `pandoc` called `hsmarkdown`.
216 When invoked under the name `hsmarkdown`, `pandoc` will behave
217 as if the `--strict` flag had been selected, and no command-line
218 options will be recognized. However, this approach does not work
219 under Cygwin, due to problems with its simulation of symbolic
225Various command-line options can be used to customize the output.
226For further documentation, see the `pandoc(1)` man page.
228`-f`, `--from`, `-r`, or `--read` can be used to specify the input
229format -- the format Pandoc will be converting *from*. Available
230formats are `native`, `markdown`, `rst`, `html`, and `latex`.
232`-t`, `--to`, `-w`, or `--write` can be used to specify the output
233format -- the format Pandoc will be converting *to*. Available formats
234are `native`, `html`, `s5`, `docbook`, `latex`, `markdown`, `rst`, and
237`-s` or `--standalone` indicates that a standalone document is to be
238produced (with appropriate headers and footers), rather than a fragment.
240`-o` or `--output` specifies the name of the output file. If this
241option is not specified, or if its argument is `-`, output will be sent
244`-p` or `--preserve-tabs` causes tabs in the source text to be
245preserved, rather than converted to spaces (the default).
247`--tabstop` allows the user to set the tab stop (which defaults to 4).
249`--strict` specifies that strict markdown syntax is to be used, without
250pandoc's usual extensions and variants (described below).
252`--reference-links` causes reference-style links to be used in markdown
253and reStructuredText output. By default inline links are used.
255`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
256codes and LaTeX environments that it can't translate as raw HTML or
257LaTeX. Raw HTML can be printed in markdown, reStructuredText, HTML,
258and S5 output; raw LaTeX can be printed in markdown, reStructuredText,
259and LaTeX output. The default is for the readers to omit
260untranslatable HTML codes and LaTeX environments. (The LaTeX reader
261does pass through untranslatable LaTeX commands, even if `-R` is not
264`-C` or `--custom-header` can be used to specify a custom document
265header. To see the headers used by default, use the `-D` option:
266for example, `pandoc -D html` prints the default HTML header.
268`-c` or `--css` allows the user to specify a custom stylesheet that
269will be linked to in HTML and S5 output.
271`-H` or `--include-in-header` specifies a file to be included
272(verbatim) at the end of the document header. This can be used, for
273example, to include special CSS or javascript in HTML documents.
275`-B` or `--include-before-body` specifies a file to be included
276(verbatim) at the beginning of the document body (after the `<body>`
277tag in HTML, or the `\begin{document}` command in LaTeX). This can be
278used to include navigation bars or banners in HTML documents.
280`-A` or `--include-after-body` specifies a file to be included
281(verbatim) at the end of the docment body (before the `</body>` tag in
282HTML, or the `\end{document}` command in LaTeX).
284`-T` or `--title-prefix` specifies a string to be included as a prefix
285at the beginning of the title that appears in the HTML header (but not
286in the title as it appears at the beginning of the HTML body). (See
289`-S` or `--smart` causes `pandoc` to produce typographically
290correct output, along the lines of John Gruber's [Smartypants].
291Straight quotes are converted to curly quotes, `---` to dashes, and
292`...` to ellipses. (Note: This option is only significant when
293the input format is `markdown`. It is selected automatically
294when the output format is `latex`.)
296[Smartypants]: http://daringfireball.net/projects/smartypants/
298`-m` or `--asciimathml` will cause LaTeX formulas (between $ signs) in
299HTML or S5 to display as formulas rather than as code. The trick will
300not work in all browsers, but it works in Firefox. Peter Jipsen's
301[ASCIIMathML] script is used to do the magic.
303[ASCIIMathML]: http://www1.chapman.edu/~jipsen/mathml/asciimath.html
305`-i` or `--incremental` causes all lists in S5 output to be displayed
306incrementally by default (one item at a time). The normal default
307is for lists to be displayed all at once.
309`-N` or `--number-sections` causes sections to be numbered in LaTeX
310output. By default, sections are not numbered.
312`--dump-args` is intended to make it easier to create wrapper scripts
313that use Pandoc. It causes Pandoc to dump information about the arguments
314with which it was called to STDOUT, then exit. The first line printed
315is the name of the output file specified using the `-o` or `--output`
316option, or `-` if output would go to STDOUT. The remaining lines, if any,
317list command-line arguments. These will include the names of input
318files and any special options passed after ` -- ` on the command line.
321 pandoc --dump-args -o foo.html -s foo.txt appendix.txt -- -e latin1
323will cause the following to be printed to STDOUT:
331`--ignore-args` causes Pandoc to ignore all command-line arguments.
332Regular Pandoc options are not ignored. Thus, for example,
334 pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
338 pandoc -o foo.html -s
340`-v` or `--version` prints the version number to STDERR.
342`-h` or `--help` prints a usage message to STDERR.
344Pandoc's markdown vs. standard markdown
345=======================================
347In parsing markdown, Pandoc departs from and extends [standard markdown]
348in a few respects. (To run Pandoc on the official markdown test suite,
349type `make test-markdown`.) Except where noted, these differences can
350be suppressed by specifying the `--strict` command-line option or by
351using the `hsmarkdown` wrapper.
353[standard markdown]: http://daringfireball.net/projects/markdown/syntax
354 "Markdown syntax description"
359Except inside a code block or inline code, any punctuation or space
360character preceded by a backslash will be treated literally, even if it
361would normally indicate formatting. Thus, for example, if one writes
371 <strong>hello</strong>
373This rule is easier to remember than standard markdown's rule,
374which allows only the following characters to be backslash-escaped:
381Pandoc behaves differently from standard markdown on some "edge
382cases" involving lists. Consider this source:
392Pandoc transforms this into a "compact list" (with no `<p>` tags
393around "First", "Second", or "Third"), while markdown puts `<p>`
394tags around "Second" and "Third" (but not "First"), because of
395the blank space around "Third". Pandoc follows a simple rule:
396if the text is followed by a blank line, it is treated as a
397paragraph. Since "Second" is followed by a list, and not a blank
398line, it isn't treated as a paragraph. The fact that the list
399is followed by a blank line is irrelevant. (Note: Pandoc works
400this way even when the `--strict` option is specified. This
401behavior is consistent with the official markdown syntax
402description, even though it is different from that of `Markdown.pl`.)
404Unlike standard markdown, Pandoc allows ordered list items to be
405marked with single lowercase letters (from 'a' to 'n'), instead of
406numbers. So, for example, this source yields a nested ordered list:
414The letters may be followed by either '.' or ')':
422Note that Pandoc pays no attention to the *type* of ordered list
423item marker used. Thus, the following is treated just the same as
435Pandoc supports definition lists, using a syntax inspired by
436[PHP Markdown Extra] and [reStructuredText]:
438 [PHP Markdown Extra]: http://www.michelf.com/projects/php-markdown/extra/
446 : Second paragraph of definition 2.
448Each term must fit on one line. The definition must begin on the line
449after the term. The definition consists of one or more block elements
450(paragraph, code block, list, etc.), each beginning with a colon and
451(aside from the colon) indented one tab stop.
453 Term *with inline markup*
454 : Here is the definition. It may
455 contain multiple blocks. Here is some code:
459 : Here is the third paragraph of this definition.
461If you leave space after the definition (as in the first example above),
462the definitions will be considered paragraphs. In some output formats,
463this will mean greater spacing between term/definition pairs. For a
464compact definition list, do not leave space between the definition and
475Pandoc allows implicit reference links with just a single set of
476brackets. So, the following links are equivalent:
479 2. Here's my [link][]
483(Note: Pandoc works this way even if `--strict` is specified, because
484`Markdown.pl` 1.0.2b7 allows single-bracket links.)
489Pandoc's markdown allows footnotes, using the following syntax:
491 Here is a footnote reference,[^1] and another.[^longnote]
493 [^1]: Here is the footnote. It can go anywhere in the document,
494 except in embedded contexts like block quotes or lists.
496 [^longnote]: Here's the other note. This one contains multiple
499 Subsequent paragraphs are indented to show that they belong to
500 the previous footnote.
504 The whole paragraph can be indented, or just the first line.
505 In this way, multi-paragraph footnotes work just like
506 multi-paragraph list items in markdown.
508 This paragraph won't be part of the note, because it isn't indented.
510The identifiers in footnote references may not contain spaces, tabs,
511or newlines. These identifiers are used only to correlate the
512footnote reference with the note itself; in the output, footnotes
513will be numbered sequentially.
515The footnotes themselves need not be placed at the end of the
516document. They may appear anywhere except inside other block elements
517(lists, block quotes, tables, etc.).
519Inline footnotes are also allowed (though, unlike regular notes,
520they cannot contain multiple paragraphs). The syntax is as follows:
522 Here is an inline note.^[Inlines notes are easier to write, since
523 you don't have to pick an identifier and move down to type the
526Inline and regular footnotes may be mixed freely.
531Two kinds of tables may be used. Both kinds presuppose the use of
532a fixed-width font, such as Courier. Currently only the HTML,
533Docbook, and LaTeX writers support tables.
535Simple tables look like this:
537 Right Left Center Default
538 ------- ------ ---------- -------
543 Table: Demonstration of simple table syntax.
545The headers and table rows must each fit on one line. Column
546alignments are determined by the position of the header text relative
547to the dashed line below it:[^2]
549 - If the dashed line is flush with the header text on the right side
550 but extends beyond it on the left, the column is right-aligned.
551 - If the dashed line is flush with the header text on the left side
552 but extends beyond it on the right, the column is left-aligned.
553 - If the dashed line extends beyond the header text on both sides,
554 the column is centered.
555 - If the dashed line is flush with the header text on both sides,
556 the default alignment is used (in most cases, this will be left).
558[^2]: This scheme is due to Michel Fortin, who proposed it on the
559 Markdown discussion list: <http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html>
561The table must end with a blank line. Optionally, a caption may be
562provided (as illustrated in the example above). A caption is a paragraph
563beginning with the string `Table:`, which will be stripped off.
565The table parser pays attention to the widths of the columns, and
566the writers try to reproduce these relative widths in the output.
567So, if you find that one of the columns is too narrow in the output,
568try widening it in the markdown source.
570Multiline tables allow headers and table rows to span multiple lines
571of text. Here is an example:
573 ---------------------------------------------------------------
575 Header Aligned Aligned Default aligned
576 ---------- --------- ----------- ---------------------------
577 First row 12.0 Example of a row that spans
580 Second row 5.0 Here's another one. Note
581 the blank line between rows.
582 ---------------------------------------------------------------
584 Table: Optional caption. This, too, may span multiple
587These work like simple tables, but with the following differences:
589 - They must begin with a row of dashes, before the header text.
590 - They must end with a row of dashes, then a blank line.
591 - The rows must be separated by blank lines.
596Pandoc treats embedded HTML in markdown a bit differently than
597Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
598are, Pandoc treats text between HTML tags as markdown. Thus, for
599example, Pandoc will turn
604 <td>[a link](http://google.com)</td>
612 <td><em>one</em></td>
613 <td><a href="http://google.com">a link</a></td>
617whereas `Markdown.pl` will preserve it as is.
619There is one exception to this rule: text between `<script>` and
620`</script>` tags is not interpreted as markdown.
622This departure from standard markdown should make it easier to mix
623markdown with HTML block elements. For example, one can surround
624a block of markdown text with `<div>` tags without preventing it
625from being interpreted as markdown.
630If the file begins with a title block
633 % author(s) (separated by commas)
636it will be parsed as bibliographic information, not regular text. (It
637will be used, for example, in the title of standalone LaTeX or HTML
638output.) The block may contain just a title, a title and an author,
639or all three lines. Each must begin with a % and fit on one line.
640The title may contain standard inline formatting. If you want to
641include an author but no title, or a title and a date but no author,
642you need a blank line:
648Titles will be written only when the `--standalone` (`-s`) option is
649chosen. In HTML output, titles will appear twice: once in the
650document head -- this is the title that will appear at the top of the
651window in a browser -- and once at the beginning of the document body.
652The title in the document head can have an optional prefix attached
653(`--title-prefix` or `-T` option). The title in the body appears as
654an H1 element with class "title", so it can be suppressed or
657If a title prefix is specified with `-T` and no title block appears
658in the document, the title prefix will be used by itself as the
664Pandoc supports emacs-style boxquote block quotes, in addition to
665standard markdown (email-style) block quotes:
668 | They look like this.
671Blank lines before headers and blockquotes
672------------------------------------------
674Standard markdown syntax does not require a blank line before a header
675or blockquote. Pandoc does require this (except, of course, at the
676beginning of the document). The reason for the requirement is that
677it is all too easy for a `>` or `#` to end up at the beginning of a
678line by accident (perhaps through line wrapping). Consider, for
681 I like several of their flavors of ice cream: #22, for example, and
687Anything between two $ characters will be parsed as LaTeX math. The
688opening $ must have a character immediately to its right, while the
689closing $ must have a character immediately to its left. Thus,
690`$20,000 and $30,000` won't parse as math. The $ character can be
691escaped with a backslash if needed.
693If you pass the `-m` (`--asciimathml`) option to `pandoc`, it will
694include the [ASCIIMathML] script in the resulting HTML. This will
695cause LaTeX math to be displayed as formulas in better browsers.
697[ASCIIMathML]: http://www1.chapman.edu/~jipsen/asciimath.html
699Inline LaTeX commands will also be preserved and passed unchanged
700to the LaTeX writer. Thus, for example, you can use LaTeX to
701include BibTeX citations:
703 This result was proved in \cite{jones.1967}.
705You can also use LaTeX environments. For example,
707 \begin{tabular}{|l|l|}\hline
708 Age & Frequency \\ \hline
711 36--45 & 22 \\ \hline
714Note, however, that material between the begin and end tags will
715be interpreted as raw LaTeX, not as markdown.
720When run with the "standalone" option (`-s`), `pandoc` creates a
721standalone file, complete with an appropriate header. To see the
722default headers used for html and latex, use the following commands:
728If you want to use a different header, just create a file containing
729it and specify it on the command line as follows:
731 pandoc --header=MyHeaderFile
733Producing S5 with Pandoc
734========================
736Producing an [S5] web-based slide show with Pandoc is easy. A title
737page is constructed automatically from the document's title block (see
738above). Each section (with a level-one header) produces a single slide.
739(Note that if the section is too big, the slide will not fit on the page;
740S5 is not smart enough to produce multiple pages.)
742Here's the markdown source for a simple slide show, `eating.txt`:
758To produce the slide show, simply type
760 pandoc -w s5 -s eating.txt > eating.html
762and open up `eating.html` in a browser. The HTML file embeds
763all the required javascript and CSS, so no other files are necessary.
765Note that by default, the S5 writer produces lists that display
766"all at once." If you want your lists to display incrementally
767(one item at a time), use the `-i` option. If you want a
768particular list to depart from the default (that is, to display
769incrementally without the `-i` option and all at once with the
770`-i` option), put it in a block quote:
775In 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