2017-09-16 23:00:20 -07:00
|
|
|
% Using the pandoc API
|
|
|
|
% John MacFarlane
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-10-24 16:08:05 -07:00
|
|
|
Pandoc can be used as a Haskell library, to write your own
|
|
|
|
conversion tools or power a web application. This document
|
|
|
|
offers an introduction to using the pandoc API.
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-10-24 16:08:05 -07:00
|
|
|
Detailed API documentation at the level of individual functions
|
|
|
|
and types is available at
|
|
|
|
<https://hackage.haskell.org/package/pandoc>.
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-10-24 16:08:05 -07:00
|
|
|
# Pandoc's architecture, and a simple example
|
|
|
|
|
|
|
|
Pandoc structure, readers, writers.
|
|
|
|
|
|
|
|
example of using a reader.
|
|
|
|
|
|
|
|
example of using a writer.
|
|
|
|
|
|
|
|
chaining them together.
|
|
|
|
|
|
|
|
# The PandocMonad class
|
|
|
|
|
|
|
|
Pandoc's functions define computations that can be run in
|
|
|
|
any instance of the `PandocMonad` typeclass. Two instances
|
|
|
|
are provided: `PandocIO` and `PandocPure`. The difference is
|
|
|
|
that computations run in `PandocIO` are allowed to do IO
|
|
|
|
(for example, read a file), while computations in `PandocPure`
|
|
|
|
are free of any side effects. `PandocPure` is useful when
|
|
|
|
you want to prevent users from doing anything malicious.
|
|
|
|
|
|
|
|
Here's an example of such a computation, from the module
|
|
|
|
`Text.Pandoc.Class`:
|
|
|
|
|
|
|
|
```haskell
|
|
|
|
-- | Get the verbosity level.
|
|
|
|
getVerbosity :: PandocMonad m => m Verbosity
|
|
|
|
```
|
|
|
|
|
|
|
|
motivations
|
|
|
|
Class.
|
2017-09-16 23:17:33 -07:00
|
|
|
|
2017-09-16 23:00:20 -07:00
|
|
|
# The Pandoc structure
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
blocks/inlines
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
# Readers and writers
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
getReader, getWriter
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
# Options
|
|
|
|
|
2017-10-24 16:08:05 -07:00
|
|
|
various reader and writer options you can set.
|
|
|
|
templates
|
|
|
|
extensions
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-09-16 23:00:20 -07:00
|
|
|
# Builder
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
Inlines vs Inline, etc.
|
2017-10-24 16:08:05 -07:00
|
|
|
Monoid
|
2017-09-16 23:17:33 -07:00
|
|
|
|
2017-02-01 12:50:44 +01:00
|
|
|
example: report from CSV data
|
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
# Templates and other data files
|
|
|
|
|
|
|
|
# Handling errors and warnings
|
|
|
|
|
2017-09-16 23:00:20 -07:00
|
|
|
# Generic transformations
|
2017-02-01 12:50:44 +01:00
|
|
|
|
|
|
|
Walk and syb for AST transformations
|
|
|
|
|
2017-09-16 23:00:20 -07:00
|
|
|
# Filters
|
2017-02-01 12:50:44 +01:00
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
just the basic idea of toJSONFilter
|
|
|
|
the rest can be left to filters.md
|
|
|
|
|
|
|
|
# Self-contained
|
|
|
|
|
|
|
|
|
|
|
|
# PDF
|
|
|
|
|
2017-10-24 16:08:05 -07:00
|
|
|
# Custom PandocMonad instances
|
|
|
|
|
2017-09-16 23:17:33 -07:00
|
|
|
# Creating a front-end
|
|
|
|
|
|
|
|
Text.Pandoc.App
|
2017-02-01 12:50:44 +01:00
|
|
|
|