Copyright | Copyright (C) 2013 John MacFarlane |
---|---|
License | GNU GPL, version 2 or above |
Maintainer | John MacFarlane <jgm@berkeley.edu> |
Stability | alpha |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
Functions for manipulating Pandoc
documents or extracting
information from them by walking the Pandoc
structure (or
intermediate structures like '[Block]' or '[Inline]'.
These are faster (by a factor of four or five) than the generic
functions defined in Text.Pandoc.Generic
.
Here's a simple example, defining a function that replaces all the level 3+ headers in a document with regular paragraphs in ALL CAPS:
import Text.Pandoc.Definition import Text.Pandoc.Walk import Data.Char (toUpper) modHeader :: Block -> Block modHeader (Header n _ xs) | n >= 3 = Para $ walk allCaps xs modHeader x = x allCaps :: Inline -> Inline allCaps (Str xs) = Str $ map toUpper xs allCaps x = x changeHeaders :: Pandoc -> Pandoc changeHeaders = walk modHeader
query
can be used, for example, to compile a list of URLs
linked to in a document:
extractURL :: Inline -> [String] extractURL (Link _ (u,_)) = [u] extractURL (Image _ (u,_)) = [u] extractURL _ = [] extractURLs :: Pandoc -> [String] extractURLs = query extractURL
Documentation
class Walkable a b where
walk :: (a -> a) -> b -> b
walk f x
walks the structure x
(bottom up) and replaces every
occurrence of an a
with the result of applying f
to it.
walkM :: (Monad m, Functor m) => (a -> m a) -> b -> m b
A monadic version of walk
.
query :: Monoid c => (a -> c) -> b -> c
query f x
walks the structure x
(bottom up) and applies f
to every a
, appending the results.
Walkable Inline Citation | |
Walkable Inline Inline | |
Walkable Inline Block | |
Walkable Inline MetaValue | |
Walkable Inline Meta | |
Walkable Inline Pandoc | |
Walkable Block Citation | |
Walkable Block Inline | |
Walkable Block Block | |
Walkable Block MetaValue | |
Walkable Block Meta | |
Walkable Block Pandoc | |
Walkable Meta Meta | |
Walkable Pandoc Pandoc | |
Walkable a b => Walkable a [b] | |
(Foldable t, Traversable t, Walkable a b) => Walkable a (t b) | |
(Walkable a b, Walkable a c) => Walkable a (b, c) |