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`--reference-links` causes reference-style links to be used in markdown
245and reStructuredText output. By default inline links are used.
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 lowercase letters (from 'a' to 'n'), instead of
398numbers. So, for example, this source yields a nested ordered list:
406The letters may be followed by either '.' or ')':
414Note that Pandoc pays no attention to the *type* of ordered list
415item marker used. Thus, the following is treated just the same as
427Pandoc supports definition lists, using a syntax inspired by
428[PHP Markdown Extra] and [reStructuredText]:
430 [PHP Markdown Extra]: http://www.michelf.com/projects/php-markdown/extra/
438 : Second paragraph of definition 2.
440Each term must fit on one line. The definition must begin on the line
441after the term. The definition consists of one or more block elements
442(paragraph, code block, list, etc.), each beginning with a colon and
443(aside from the colon) indented one tab stop.
445 Term *with inline markup*
446 : Here is the definition. It may
447 contain multiple blocks. Here is some code:
451 : Here is the third paragraph of this definition.
453If you leave space after the definition (as in the first example above),
454the definitions will be considered paragraphs. In some output formats,
455this will mean greater spacing between term/definition pairs. For a
456compact definition list, do not leave space between the definition and
467Pandoc allows implicit reference links with just a single set of
468brackets. So, the following links are equivalent:
471 2. Here's my [link][]
475(Note: Pandoc works this way even if `--strict` is specified, because
476`Markdown.pl` 1.0.2b7 allows single-bracket links.)
481Pandoc's markdown allows footnotes, using the following syntax:
483 Here is a footnote reference,[^1] and another.[^longnote]
485 [^1]: Here is the footnote. It can go anywhere in the document,
486 except in embedded contexts like block quotes or lists.
488 [^longnote]: Here's the other note. This one contains multiple
491 Subsequent paragraphs are indented to show that they belong to
492 the previous footnote.
496 The whole paragraph can be indented, or just the first line.
497 In this way, multi-paragraph footnotes work just like
498 multi-paragraph list items in markdown.
500 This paragraph won't be part of the note, because it isn't indented.
502The identifiers in footnote references may not contain spaces, tabs,
503or newlines. These identifiers are used only to correlate the
504footnote reference with the note itself; in the output, footnotes
505will be numbered sequentially.
507The footnotes themselves need not be placed at the end of the
508document. They may appear anywhere except inside other block elements
509(lists, block quotes, tables, etc.).
511Inline footnotes are also allowed (though, unlike regular notes,
512they cannot contain multiple paragraphs). The syntax is as follows:
514 Here is an inline note.^[Inlines notes are easier to write, since
515 you don't have to pick an identifier and move down to type the
518Inline and regular footnotes may be mixed freely.
523Two kinds of tables may be used. Both kinds presuppose the use of
524a fixed-width font, such as Courier. Currently only the HTML,
525Docbook, and LaTeX writers support tables.
527Simple tables look like this:
529 Right Left Center Default
530 ------- ------ ---------- -------
535 Table: Demonstration of simple table syntax.
537The headers and table rows must each fit on one line. Column
538alignments are determined by the position of the header text relative
539to the dashed line below it:[^2]
541 - If the dashed line is flush with the header text on the right side
542 but extends beyond it on the left, the column is right-aligned.
543 - If the dashed line is flush with the header text on the left side
544 but extends beyond it on the right, the column is left-aligned.
545 - If the dashed line extends beyond the header text on both sides,
546 the column is centered.
547 - If the dashed line is flush with the header text on both sides,
548 the default alignment is used (in most cases, this will be left).
550[^2]: This scheme is due to Michel Fortin, who proposed it on the
551 Markdown discussion list: <http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html>
553The table must end with a blank line. Optionally, a caption may be
554provided (as illustrated in the example above). A caption is a paragraph
555beginning with the string `Table:`, which will be stripped off.
557The table parser pays attention to the widths of the columns, and
558the writers try to reproduce these relative widths in the output.
559So, if you find that one of the columns is too narrow in the output,
560try widening it in the markdown source.
562Multiline tables allow headers and table rows to span multiple lines
563of text. Here is an example:
565 ---------------------------------------------------------------
567 Header Aligned Aligned Default aligned
568 ---------- --------- ----------- ---------------------------
569 First row 12.0 Example of a row that spans
572 Second row 5.0 Here's another one. Note
573 the blank line between rows.
574 ---------------------------------------------------------------
576 Table: Optional caption. This, too, may span multiple
579These work like simple tables, but with the following differences:
581 - They must begin with a row of dashes, before the header text.
582 - They must end with a row of dashes, then a blank line.
583 - The rows must be separated by blank lines.
588Pandoc treats embedded HTML in markdown a bit differently than
589Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
590are, Pandoc treats text between HTML tags as markdown. Thus, for
591example, Pandoc will turn
596 <td>[a link](http://google.com)</td>
604 <td><em>one</em></td>
605 <td><a href="http://google.com">a link</a></td>
609whereas `Markdown.pl` will preserve it as is.
611There is one exception to this rule: text between `<script>` and
612`</script>` tags is not interpreted as markdown.
614This departure from standard markdown should make it easier to mix
615markdown with HTML block elements. For example, one can surround
616a block of markdown text with `<div>` tags without preventing it
617from being interpreted as markdown.
622If the file begins with a title block
625 % author(s) (separated by commas)
628it will be parsed as bibliographic information, not regular text. (It
629will be used, for example, in the title of standalone LaTeX or HTML
630output.) The block may contain just a title, a title and an author,
631or all three lines. Each must begin with a % and fit on one line.
632The title may contain standard inline formatting. If you want to
633include an author but no title, or a title and a date but no author,
634you need a blank line:
640Titles will be written only when the `--standalone` (`-s`) option is
641chosen. In HTML output, titles will appear twice: once in the
642document head -- this is the title that will appear at the top of the
643window in a browser -- and once at the beginning of the document body.
644The title in the document head can have an optional prefix attached
645(`--title-prefix` or `-T` option). The title in the body appears as
646an H1 element with class "title", so it can be suppressed or
649If a title prefix is specified with `-T` and no title block appears
650in the document, the title prefix will be used by itself as the
656Pandoc supports emacs-style boxquote block quotes, in addition to
657standard markdown (email-style) boxquotes:
660 | They look like this.
663Blank lines before headers and blockquotes
664------------------------------------------
666Standard markdown syntax does not require a blank line before a header
667or blockquote. Pandoc does require this (except, of course, at the
668beginning of the document). The reason for the requirement is that
669it is all too easy for a `>` or `#` to end up at the beginning of a
670line by accident (perhaps through line wrapping). Consider, for
673 I like several of their flavors of ice cream: #22, for example, and
679Anything between two $ characters will be parsed as LaTeX math. The
680opening $ must have a character immediately to its right, while the
681closing $ must have a character immediately to its left. Thus,
682`$20,000 and $30,000` won't parse as math. The $ character can be
683escaped with a backslash if needed.
685If you pass the `-m` (`--asciimathml`) option to `pandoc`, it will
686include the [ASCIIMathML] script in the resulting HTML. This will
687cause LaTeX math to be displayed as formulas in better browsers.
689[ASCIIMathML]: http://www1.chapman.edu/~jipsen/asciimath.html
691Inline LaTeX commands will also be preserved and passed unchanged
692to the LaTeX writer. Thus, for example, you can use LaTeX to
693include BibTeX citations:
695 This result was proved in \cite{jones.1967}.
697You can also use LaTeX environments. For example,
699 \begin{tabular}{|l|l|}\hline
700 Age & Frequency \\ \hline
703 36--45 & 22 \\ \hline
706Note, however, that material between the begin and end tags will
707be interpreted as raw LaTeX, not as markdown.
712When run with the "standalone" option (`-s`), `pandoc` creates a
713standalone file, complete with an appropriate header. To see the
714default headers used for html and latex, use the following commands:
720If you want to use a different header, just create a file containing
721it and specify it on the command line as follows:
723 pandoc --header=MyHeaderFile
725Producing S5 with Pandoc
726========================
728Producing an [S5] web-based slide show with Pandoc is easy. A title
729page is constructed automatically from the document's title block (see
730above). Each section (with a level-one header) produces a single slide.
731(Note that if the section is too big, the slide will not fit on the page;
732S5 is not smart enough to produce multiple pages.)
734Here's the markdown source for a simple slide show, `eating.txt`:
750To produce the slide show, simply type
752 pandoc -w s5 -s eating.txt > eating.html
754and open up `eating.html` in a browser. The HTML file embeds
755all the required javascript and CSS, so no other files are necessary.
757Note that by default, the S5 writer produces lists that display
758"all at once." If you want your lists to display incrementally
759(one item at a time), use the `-i` option. If you want a
760particular list to depart from the default (that is, to display
761incrementally without the `-i` option and all at once with the
762`-i` option), put it in a block quote:
767In 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