LEFT TEXT
_library/index-include.md.cms
_library/sitemap-include.md.cms
If you need to render a format not already handled by pandoc, or you want to change how pandoc renders a format, you can create a custom writer using the Lua language. Pandoc has a built-in Lua interpreter, so you needn’t install any additional software to do this.
A custom writer is a Lua file that defines how to render the document. Two styles of custom writers are supported: classic custom writers must define rendering functions for each AST element. New style writers, available since pandoc 2.17.2, must define just a single function Writer
, which gets passed the document and writer options, and then does all rendering.
A writer using the classic style defines rendering functions for each element of the pandoc AST.
For example,
The best way to go about creating a classic custom writer is to modify the example that comes with pandoc. To get the example, you can do
pandoc --print-default-data-file sample.lua > sample.lua
[…]
If you need to parse a format not already handled by pandoc, you can create a custom reader using the Lua language. Pandoc has a built-in Lua interpreter, so you needn’t install any additional software to do this.
A custom reader is a Lua file that defines a function called Reader
, which takes two arguments:
{ columns = 62, standalone = true }
.The Reader
function should return a Pandoc
AST. This can be created using functions in the pandoc
module, which is automatically in scope. (Indeed, all of the utility functions that are available for Lua filters are available in custom readers, too.)
Each source item corresponds to a file or stream passed to pandoc containing its text and name. E.g., if a single file input.txt
is passed to pandoc, then the list of sources will contain just a single element s
, where s.name == 'input.txt'
and s.text
contains the file contents as a string.
[…]
Pandoc has long supported filters, which allow the pandoc abstract syntax tree (AST) to be manipulated between the parsing and the writing phase. Traditional pandoc filters accept a JSON representation of the pandoc AST and produce an altered JSON representation of the AST. They may be written in any programming language, and invoked from pandoc using the --filter
option.
Although traditional filters are very flexible, they have a couple of disadvantages. First, there is some overhead in writing JSON to stdout and reading it from stdin (twice, once on each side of the filter). Second, whether a filter will work will depend on details of the user’s environment. A filter may require an interpreter for a certain programming language to be available, as well as a library for manipulating the pandoc AST in JSON form. One cannot simply provide a filter that can be used by anyone who has a certain version of the pandoc executable.
Starting with version 2.0, pandoc makes it possible to write filters in Lua without any external dependencies at all. A Lua interpreter (version 5.3) and a Lua library for creating pandoc filters is built into the pandoc executable. Pandoc data types are marshaled to Lua directly, avoiding the overhead of writing JSON to stdout and reading it from stdin.
[…]
pandoc
[options] [input-file]…
Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library.
Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx. For the full lists of input and output formats, see the --from
and --to
options below. Pandoc can also produce PDF output: see creating a PDF, below.
Pandoc’s enhanced version of Markdown includes syntax for tables, definition lists, metadata blocks, footnotes, citations, math, and much more. See below under Pandoc’s Markdown.
[…]
Starting with version 1.6, pandoc can produce output in the EPUB electronic book format. EPUB books can be viewed on iPads, Nooks, and other electronic book readers, including many smart phones. (They can also be converted to Kindle books using the GUI only KindlePreviewer on Windows and Mac OSX. KindleGen – which offers a command line interface and supports Linux, Mac OSX and Windows – has been deprecated, but binaries can still be found on the internet.)
This means that it’s now very easy to produce an electronic book! Let’s try it.
Use your text editor to create a file mybook.txt
, with the following contents:
% My Book
% Sam Smith
This is my book!
# Chapter One
Chapter one is over.
# Chapter Two
Chapter two has just begun.
[…]
This document provides a quick overview over the various ways to customize pandoc’s output, with links to fuller documentation and some examples.
When the -s
/--standalone
option is used, pandoc will generate a standalone document rather than a fragment. For example, in HTML output this will include the <head>
element; in LaTeX output, it will include the preamble.
Pandoc comes with a default template for (almost) every output format. A template is a plain text file containing variables that are replaced by text generated by pandoc. For example, the variable $body$
will be replaced by the document body, and $title$
by the title from metadata.
To look at the default template for an output format, you can do pandoc -D FORMAT
, where FORMAT
is replaced by the name of the format. For example pandoc -D latex
. You can also use your own template instead, either by using the --template
option or by putting the custom template in your user data directory (on Linux and macOS, ~/.pandoc/templates/
).
[…]
This document is for people who are unfamiliar with command line tools. Command-line experts can go straight to the User’s Guide or the pandoc man page.
First, install pandoc, following the instructions for your platform.
Pandoc is a command-line tool. There is no graphic user interface. So, to use it, you’ll need to open a terminal window:
On OS X, the Terminal application can be found in /Applications/Utilities
. Open a Finder window and go to Applications
, then Utilities
. Then double click on Terminal
. (Or, click the spotlight icon in the upper right hand corner of your screen and type Terminal
– you should see Terminal
under Applications
.)
On Windows, you can use either the classic command prompt or the more modern PowerShell terminal. If you use Windows in desktop mode, run the cmd
or powershell
command from the Start menu. If you use the Windows 8 start screen instead, simply type cmd
or powershell
, and then run either the “Command Prompt” or “Windows Powershell” application. If you are using cmd
, type chcp 65001
before using pandoc, to set the encoding to UTF-8.
On Linux, there are many possible configurations, depending on what desktop environment you’re using:
Dash
, and search for Terminal
. Or, use the keyboard shortcut Ctrl-Alt-T
.Applications
, then Accessories
, and select Terminal
, or use Ctrl-Alt-T
.Applications
, then System
, then Terminal
, or use Super-T
.KMenu
, then System
, then Terminal Program (Konsole)
.[…]
The following Haskell libraries have been developed to support pandoc:
[…]