Copyright | Copyright (C) 2013-2023 John MacFarlane |
---|---|
License | BSD3 |
Maintainer | John MacFarlane <jgm@berkeley.edu> |
Stability | alpha |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Functions for serializing the Pandoc AST to JSON and deserializing from JSON.
Example of use: The following script (capitalize.hs
) reads
reads a JSON representation of a Pandoc document from stdin,
and writes a JSON representation of a Pandoc document to stdout.
It changes all regular text in the document to uppercase, without
affecting URLs, code, tags, etc. Run the script with
pandoc -t json | runghc capitalize.hs | pandoc -f json
or (making capitalize.hs executable)
pandoc --filter ./capitalize.hs
#!/usr/bin/env runghc import Text.Pandoc.JSON import Data.Char (toUpper) main :: IO () main = toJSONFilter capitalizeStrings capitalizeStrings :: Inline -> Inline capitalizeStrings (Str s) = Str $ map toUpper s capitalizeStrings x = x
Synopsis
- module Text.Pandoc.Definition
- class ToJSONFilter m a where
- toJSONFilter :: a -> m ()
Documentation
module Text.Pandoc.Definition
class ToJSONFilter m a where Source #
toJSONFilter
convert a function into a filter that reads pandoc's
JSON serialized output from stdin, transforms it by walking the AST
and applying the specified function, and serializes the result as JSON
to stdout.
For a straight transformation, use a function of type a -> a
or
a -> IO a
where a
= Block
, Inline
, Pandoc
, Meta
, or MetaValue
.
If your transformation needs to be sensitive to the script's arguments,
use a function of type [String] -> a -> a
(with a
constrained as above).
The [String]
will be populated with the script's arguments.
An alternative is to use the type Maybe Format -> a -> a
.
This is appropriate when the first argument of the script (if present)
will be the target format, and allows scripts to behave differently
depending on the target format. The pandoc executable automatically
provides the target format as argument when scripts are called using
the `--filter` option.
toJSONFilter :: a -> m () Source #
Instances
(ToJSONFilter m a, MonadIO m) => ToJSONFilter m (Maybe Format -> a) Source # | |
Defined in Text.Pandoc.JSON toJSONFilter :: (Maybe Format -> a) -> m () Source # | |
(ToJSONFilter m a, MonadIO m) => ToJSONFilter m ([String] -> a) Source # | |
Defined in Text.Pandoc.JSON toJSONFilter :: ([String] -> a) -> m () Source # | |
(Walkable [a] Pandoc, MonadIO m) => ToJSONFilter m (a -> [a]) Source # | |
Defined in Text.Pandoc.JSON toJSONFilter :: (a -> [a]) -> m () Source # | |
(Walkable a Pandoc, MonadIO m) => ToJSONFilter m (a -> a) Source # | |
Defined in Text.Pandoc.JSON toJSONFilter :: (a -> a) -> m () Source # | |
(Walkable [a] Pandoc, MonadIO m) => ToJSONFilter m (a -> m [a]) Source # | |
Defined in Text.Pandoc.JSON toJSONFilter :: (a -> m [a]) -> m () Source # | |
(Walkable a Pandoc, MonadIO m) => ToJSONFilter m (a -> m a) Source # | |
Defined in Text.Pandoc.JSON toJSONFilter :: (a -> m a) -> m () Source # |