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`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
245codes and LaTeX environments that it can't translate as raw HTML or
246LaTeX. Raw HTML can be printed in markdown, reStructuredText, HTML,
247and S5 output; raw LaTeX can be printed in markdown, reStructuredText,
248and LaTeX output. The default is for the readers to omit
249untranslatable HTML codes and LaTeX environments. (The LaTeX reader
250does pass through untranslatable LaTeX commands, even if `-R` is not
253`-C` or `--custom-header` can be used to specify a custom document
254header. To see the headers used by default, use the `-D` option:
255for example, `pandoc -D html` prints the default HTML header.
257`-c` or `--css` allows the user to specify a custom stylesheet that
258will be linked to in HTML and S5 output.
260`-H` or `--include-in-header` specifies a file to be included
261(verbatim) at the end of the document header. This can be used, for
262example, to include special CSS or javascript in HTML documents.
264`-B` or `--include-before-body` specifies a file to be included
265(verbatim) at the beginning of the document body (after the `<body>`
266tag in HTML, or the `\begin{document}` command in LaTeX). This can be
267used to include navigation bars or banners in HTML documents.
269`-A` or `--include-after-body` specifies a file to be included
270(verbatim) at the end of the docment body (before the `</body>` tag in
271HTML, or the `\end{document}` command in LaTeX).
273`-T` or `--title-prefix` specifies a string to be included as a prefix
274at the beginning of the title that appears in the HTML header (but not
275in the title as it appears at the beginning of the HTML body). (See
278`-S` or `--smart` causes `pandoc` to produce typographically
279correct output, along the lines of John Gruber's [Smartypants].
280Straight quotes are converted to curly quotes, `---` to dashes, and
281`...` to ellipses. (Note: This option is only significant when
282the input format is `markdown`. It is selected automatically
283when the output format is `latex`.)
285[Smartypants]: http://daringfireball.net/projects/smartypants/
287`-m` or `--asciimathml` will cause LaTeX formulas (between $ signs) in
288HTML or S5 to display as formulas rather than as code. The trick will
289not work in all browsers, but it works in Firefox. Peter Jipsen's
290[ASCIIMathML] script is used to do the magic.
292[ASCIIMathML]: http://www1.chapman.edu/~jipsen/mathml/asciimath.html
294`-i` or `--incremental` causes all lists in S5 output to be displayed
295incrementally by default (one item at a time). The normal default
296is for lists to be displayed all at once.
298`-N` or `--number-sections` causes sections to be numbered in LaTeX
299output. By default, sections are not numbered.
301`--dump-args` is intended to make it easier to create wrapper scripts
302that use Pandoc. It causes Pandoc to dump information about the arguments
303with which it was called to STDOUT, then exit. The first line printed
304is the name of the output file specified using the `-o` or `--output`
305option, or `-` if output would go to STDOUT. The remaining lines, if any,
306list command-line arguments. These will include the names of input
307files and any special options passed after ` -- ` on the command line.
310 pandoc --dump-args -o foo.html -s foo.txt appendix.txt -- -e latin1
312will cause the following to be printed to STDOUT:
320`--ignore-args` causes Pandoc to ignore all command-line arguments.
321Regular Pandoc options are not ignored. Thus, for example,
323 pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
327 pandoc -o foo.html -s
329`-v` or `--version` prints the version number to STDERR.
331`-h` or `--help` prints a usage message to STDERR.
333Pandoc's markdown vs. standard markdown
334=======================================
336In parsing markdown, Pandoc departs from and extends [standard markdown]
337in a few respects. (To run Pandoc on the official markdown test suite,
338type `make test-markdown`.) Except where noted, these differences can
339be suppressed by specifying the `--strict` command-line option or by
340using the `hsmarkdown` wrapper.
342[standard markdown]: http://daringfireball.net/projects/markdown/syntax
343 "Markdown syntax description"
348Except inside a code block or inline code, any punctuation or space
349character preceded by a backslash will be treated literally, even if it
350would normally indicate formatting. Thus, for example, if one writes
360 <strong>hello</strong>
362This rule is easier to remember than standard markdown's rule,
363which allows only the following characters to be backslash-escaped:
370Pandoc behaves differently from standard markdown on some "edge
371cases" involving lists. Consider this source:
381Pandoc transforms this into a "compact list" (with no `<p>` tags
382around "First", "Second", or "Third"), while markdown puts `<p>`
383tags around "Second" and "Third" (but not "First"), because of
384the blank space around "Third". Pandoc follows a simple rule:
385if the text is followed by a blank line, it is treated as a
386paragraph. Since "Second" is followed by a list, and not a blank
387line, it isn't treated as a paragraph. The fact that the list
388is followed by a blank line is irrelevant. (Note: Pandoc works
389this way even when the `--strict` option is specified. This
390behavior is consistent with the official markdown syntax
391description, even though it is different from that of `Markdown.pl`.)
393Unlike standard markdown, Pandoc allows ordered list items to be
394marked with single letters, instead of numbers. So, for example,
395this source yields a nested ordered list:
403Pandoc also extends standard markdown in allowing list item markers
404to be terminated by ')':
412Note that Pandoc pays no attention to the *type* of ordered list
413item marker used. Thus, the following is treated just the same as
425Pandoc allows implicit reference links with just a single set of
426brackets. So, the following links are equivalent:
429 2. Here's my [link][]
433(Note: Pandoc works this way even if `--strict` is specified, because
434`Markdown.pl` 1.0.2b7 allows single-bracket links.)
439Pandoc's markdown allows footnotes, using the following syntax:
441 Here is a footnote reference,[^1] and another.[^longnote]
443 [^1]: Here is the footnote. It can go anywhere in the document,
444 except in embedded contexts like block quotes or lists.
446 [^longnote]: Here's the other note. This one contains multiple
449 Subsequent paragraphs are indented to show that they belong to
450 the previous footnote.
454 The whole paragraph can be indented, or just the first line.
455 In this way, multi-paragraph footnotes work just like
456 multi-paragraph list items in markdown.
458 This paragraph won't be part of the note.
460The identifiers in footnote references may not contain spaces, tabs,
461or newlines. These identifiers are used only to correlate the
462footnote reference with the note itself; in the output, footnotes
463will be numbered sequentially.
465Inline footnotes are also allowed (though, unlike regular notes,
466they cannot contain multiple paragraphs). The syntax is as follows:
468 Here is an inline note.^[Inlines notes are easier to write, since
469 you don't have to pick an identifier and move down to type the
472Inline and regular footnotes may be mixed freely.
477Two kinds of tables may be used. Both kinds presuppose the use of
478a fixed-width font, such as Courier. Currently only the HTML,
479Docbook, and LaTeX writers support tables.
481Simple tables look like this:
483 Right Left Center Default
484 ------- ------ ---------- -------
489 Table: Demonstration of simple table syntax.
491The headers and table rows must each fit on one line. Column
492alignments are determined by the position of the header text relative
493to the dashed line below it:[^2]
495 - If the dashed line is flush with the header text on the right side
496 but extends beyond it on the left, the column is right-aligned.
497 - If the dashed line is flush with the header text on the left side
498 but extends beyond it on the right, the column is left-aligned.
499 - If the dashed line extends beyond the header text on both sides,
500 the column is centered.
501 - If the dashed line is flush with the header text on both sides,
502 the default alignment is used (in most cases, this will be left).
504[^2]: This scheme is due to Michel Fortin, who proposed it on the
505 Markdown discussion list: <http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html>
507The table must end with a blank line. Optionally, a caption may be
508provided (as illustrated in the example above). A caption is a paragraph
509beginning with the string `Table:`, which will be stripped off.
511The table parser pays attention to the widths of the columns, and
512the writers try to reproduce these relative widths in the output.
513So, if you find that one of the columns is too narrow in the output,
514try widening it in the markdown source.
516Multiline tables allow headers and table rows to span multiple lines
517of text. Here is an example:
519 ---------------------------------------------------------------
521 Header Aligned Aligned Default aligned
522 ---------- --------- ----------- ---------------------------
523 First row 12.0 Example of a row that spans
526 Second row 5.0 Here's another one. Note
527 the blank line between rows.
528 ---------------------------------------------------------------
530 Table: Optional caption. This, too, may span multiple
533These work like simple tables, but with the following differences:
535 - They must begin with a row of dashes, before the header text.
536 - They must end with a row of dashes, then a blank line.
537 - The rows must be separated by blank lines.
542Pandoc treats embedded HTML in markdown a bit differently than
543Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
544are, Pandoc treats text between HTML tags as markdown. Thus, for
545example, Pandoc will turn
550 <td>[a link](http://google.com)</td>
558 <td><em>one</em></td>
559 <td><a href="http://google.com">a link</a></td>
563whereas `Markdown.pl` will preserve it as is.
565There is one exception to this rule: text between `<script>` and
566`</script>` tags is not interpreted as markdown.
568This departure from standard markdown should make it easier to mix
569markdown with HTML block elements. For example, one can surround
570a block of markdown text with `<div>` tags without preventing it
571from being interpreted as markdown.
576If the file begins with a title block
579 % author(s) (separated by commas)
582it will be parsed as bibliographic information, not regular text. (It
583will be used, for example, in the title of standalone LaTeX or HTML
584output.) The block may contain just a title, a title and an author,
585or all three lines. Each must begin with a % and fit on one line.
586The title may contain standard inline formatting. If you want to
587include an author but no title, or a title and a date but no author,
588you need a blank line:
594Titles will be written only when the `--standalone` (`-s`) option is
595chosen. In HTML output, titles will appear twice: once in the
596document head -- this is the title that will appear at the top of the
597window in a browser -- and once at the beginning of the document body.
598The title in the document head can have an optional prefix attached
599(`--title-prefix` or `-T` option). The title in the body appears as
600an H1 element with class "title", so it can be suppressed or
603If a title prefix is specified with `-T` and no title block appears
604in the document, the title prefix will be used by itself as the
610Pandoc supports emacs-style boxquote block quotes, in addition to
611standard markdown (email-style) boxquotes:
614 | They look like this.
617Blank lines before headers and blockquotes
618------------------------------------------
620Standard markdown syntax does not require a blank line before a header
621or blockquote. Pandoc does require this (except, of course, at the
622beginning of the document). The reason for the requirement is that
623it is all too easy for a `>` or `#` to end up at the beginning of a
624line by accident (perhaps through line wrapping). Consider, for
627 I like several of their flavors of ice cream: #22, for example, and
633Anything between two $ characters will be parsed as LaTeX math. The
634opening $ must have a character immediately to its right, while the
635closing $ must have a character immediately to its left. Thus,
636`$20,000 and $30,000` won't parse as math. The $ character can be
637escaped with a backslash if needed.
639If you pass the `-m` (`--asciimathml`) option to `pandoc`, it will
640include the [ASCIIMathML] script in the resulting HTML. This will
641cause LaTeX math to be displayed as formulas in better browsers.
643[ASCIIMathML]: http://www1.chapman.edu/~jipsen/asciimath.html
645Inline LaTeX commands will also be preserved and passed unchanged
646to the LaTeX writer. Thus, for example, you can use LaTeX to
647include BibTeX citations:
649 This result was proved in \cite{jones.1967}.
651You can also use LaTeX environments. For example,
653 \begin{tabular}{|l|l|}\hline
654 Age & Frequency \\ \hline
657 36--45 & 22 \\ \hline
660Note, however, that material between the begin and end tags will
661be interpreted as raw LaTeX, not as markdown.
666When run with the "standalone" option (`-s`), `pandoc` creates a
667standalone file, complete with an appropriate header. To see the
668default headers used for html and latex, use the following commands:
674If you want to use a different header, just create a file containing
675it and specify it on the command line as follows:
677 pandoc --header=MyHeaderFile
679Producing S5 with Pandoc
680========================
682Producing an [S5] web-based slide show with Pandoc is easy. A title
683page is constructed automatically from the document's title block (see
684above). Each section (with a level-one header) produces a single slide.
685(Note that if the section is too big, the slide will not fit on the page;
686S5 is not smart enough to produce multiple pages.)
688Here's the markdown source for a simple slide show, `eating.txt`:
704To produce the slide show, simply type
706 pandoc -w s5 -s eating.txt > eating.html
708and open up `eating.html` in a browser. The HTML file embeds
709all the required javascript and CSS, so no other files are necessary.
711Note that by default, the S5 writer produces lists that display
712"all at once." If you want your lists to display incrementally
713(one item at a time), use the `-i` option. If you want a
714particular list to depart from the default (that is, to display
715incrementally without the `-i` option and all at once with the
716`-i` option), put it in a block quote:
721In 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