pandoc-types-1.17.4.2: Types for representing a structured document

CopyrightCopyright (C) 2013 John MacFarlane
LicenseBSD3
MaintainerJohn MacFarlane <jgm@berkeley.edu>
Stabilityalpha
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Text.Pandoc.Walk

Description

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 Source #

Minimal complete definition

walkM, query

Methods

walk :: (a -> a) -> b -> b Source #

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, Applicative m, Functor m) => (a -> m a) -> b -> m b Source #

A monadic version of walk.

query :: Monoid c => (a -> c) -> b -> c Source #

query f x walks the structure x (bottom up) and applies f to every a, appending the results.

Instances

Walkable Inline Citation Source # 

Methods

walk :: (Inline -> Inline) -> Citation -> Citation Source #

walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> Citation -> m Citation Source #

query :: Monoid c => (Inline -> c) -> Citation -> c Source #

Walkable Inline Inline Source # 

Methods

walk :: (Inline -> Inline) -> Inline -> Inline Source #

walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> Inline -> m Inline Source #

query :: Monoid c => (Inline -> c) -> Inline -> c Source #

Walkable Inline Block Source # 

Methods

walk :: (Inline -> Inline) -> Block -> Block Source #

walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> Block -> m Block Source #

query :: Monoid c => (Inline -> c) -> Block -> c Source #

Walkable Inline MetaValue Source # 

Methods

walk :: (Inline -> Inline) -> MetaValue -> MetaValue Source #

walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> MetaValue -> m MetaValue Source #

query :: Monoid c => (Inline -> c) -> MetaValue -> c Source #

Walkable Inline Meta Source # 

Methods

walk :: (Inline -> Inline) -> Meta -> Meta Source #

walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> Meta -> m Meta Source #

query :: Monoid c => (Inline -> c) -> Meta -> c Source #

Walkable Inline Pandoc Source # 

Methods

walk :: (Inline -> Inline) -> Pandoc -> Pandoc Source #

walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> Pandoc -> m Pandoc Source #

query :: Monoid c => (Inline -> c) -> Pandoc -> c Source #

Walkable Block Citation Source # 

Methods

walk :: (Block -> Block) -> Citation -> Citation Source #

walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> Citation -> m Citation Source #

query :: Monoid c => (Block -> c) -> Citation -> c Source #

Walkable Block Inline Source # 

Methods

walk :: (Block -> Block) -> Inline -> Inline Source #

walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> Inline -> m Inline Source #

query :: Monoid c => (Block -> c) -> Inline -> c Source #

Walkable Block Block Source # 

Methods

walk :: (Block -> Block) -> Block -> Block Source #

walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> Block -> m Block Source #

query :: Monoid c => (Block -> c) -> Block -> c Source #

Walkable Block MetaValue Source # 

Methods

walk :: (Block -> Block) -> MetaValue -> MetaValue Source #

walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> MetaValue -> m MetaValue Source #

query :: Monoid c => (Block -> c) -> MetaValue -> c Source #

Walkable Block Meta Source # 

Methods

walk :: (Block -> Block) -> Meta -> Meta Source #

walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> Meta -> m Meta Source #

query :: Monoid c => (Block -> c) -> Meta -> c Source #

Walkable Block Pandoc Source # 

Methods

walk :: (Block -> Block) -> Pandoc -> Pandoc Source #

walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> Pandoc -> m Pandoc Source #

query :: Monoid c => (Block -> c) -> Pandoc -> c Source #

Walkable Meta Meta Source # 

Methods

walk :: (Meta -> Meta) -> Meta -> Meta Source #

walkM :: (Monad m, Applicative m, Functor m) => (Meta -> m Meta) -> Meta -> m Meta Source #

query :: Monoid c => (Meta -> c) -> Meta -> c Source #

Walkable Pandoc Pandoc Source # 

Methods

walk :: (Pandoc -> Pandoc) -> Pandoc -> Pandoc Source #

walkM :: (Monad m, Applicative m, Functor m) => (Pandoc -> m Pandoc) -> Pandoc -> m Pandoc Source #

query :: Monoid c => (Pandoc -> c) -> Pandoc -> c Source #

(Foldable t, Traversable t, Walkable a b) => Walkable a (t b) Source # 

Methods

walk :: (a -> a) -> t b -> t b Source #

walkM :: (Monad m, Applicative m, Functor m) => (a -> m a) -> t b -> m (t b) Source #

query :: Monoid c => (a -> c) -> t b -> c Source #

(Walkable a b, Walkable a c) => Walkable a (b, c) Source # 

Methods

walk :: (a -> a) -> (b, c) -> (b, c) Source #

walkM :: (Monad m, Applicative m, Functor m) => (a -> m a) -> (b, c) -> m (b, c) Source #

query :: Monoid c => (a -> c) -> (b, c) -> c Source #

Walkable [Inline] Citation Source # 

Methods

walk :: ([Inline] -> [Inline]) -> Citation -> Citation Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Inline] -> m [Inline]) -> Citation -> m Citation Source #

query :: Monoid c => ([Inline] -> c) -> Citation -> c Source #

Walkable [Inline] Inline Source # 

Methods

walk :: ([Inline] -> [Inline]) -> Inline -> Inline Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Inline] -> m [Inline]) -> Inline -> m Inline Source #

query :: Monoid c => ([Inline] -> c) -> Inline -> c Source #

Walkable [Inline] Block Source # 

Methods

walk :: ([Inline] -> [Inline]) -> Block -> Block Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Inline] -> m [Inline]) -> Block -> m Block Source #

query :: Monoid c => ([Inline] -> c) -> Block -> c Source #

Walkable [Inline] MetaValue Source # 

Methods

walk :: ([Inline] -> [Inline]) -> MetaValue -> MetaValue Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Inline] -> m [Inline]) -> MetaValue -> m MetaValue Source #

query :: Monoid c => ([Inline] -> c) -> MetaValue -> c Source #

Walkable [Inline] Meta Source # 

Methods

walk :: ([Inline] -> [Inline]) -> Meta -> Meta Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Inline] -> m [Inline]) -> Meta -> m Meta Source #

query :: Monoid c => ([Inline] -> c) -> Meta -> c Source #

Walkable [Inline] Pandoc Source # 

Methods

walk :: ([Inline] -> [Inline]) -> Pandoc -> Pandoc Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Inline] -> m [Inline]) -> Pandoc -> m Pandoc Source #

query :: Monoid c => ([Inline] -> c) -> Pandoc -> c Source #

Walkable [Block] Citation Source # 

Methods

walk :: ([Block] -> [Block]) -> Citation -> Citation Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Block] -> m [Block]) -> Citation -> m Citation Source #

query :: Monoid c => ([Block] -> c) -> Citation -> c Source #

Walkable [Block] Inline Source # 

Methods

walk :: ([Block] -> [Block]) -> Inline -> Inline Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Block] -> m [Block]) -> Inline -> m Inline Source #

query :: Monoid c => ([Block] -> c) -> Inline -> c Source #

Walkable [Block] Block Source # 

Methods

walk :: ([Block] -> [Block]) -> Block -> Block Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Block] -> m [Block]) -> Block -> m Block Source #

query :: Monoid c => ([Block] -> c) -> Block -> c Source #

Walkable [Block] MetaValue Source # 

Methods

walk :: ([Block] -> [Block]) -> MetaValue -> MetaValue Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Block] -> m [Block]) -> MetaValue -> m MetaValue Source #

query :: Monoid c => ([Block] -> c) -> MetaValue -> c Source #

Walkable [Block] Meta Source # 

Methods

walk :: ([Block] -> [Block]) -> Meta -> Meta Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Block] -> m [Block]) -> Meta -> m Meta Source #

query :: Monoid c => ([Block] -> c) -> Meta -> c Source #

Walkable [Block] Pandoc Source # 

Methods

walk :: ([Block] -> [Block]) -> Pandoc -> Pandoc Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Block] -> m [Block]) -> Pandoc -> m Pandoc Source #

query :: Monoid c => ([Block] -> c) -> Pandoc -> c Source #

Walkable [Inline] [Inline] Source # 

Methods

walk :: ([Inline] -> [Inline]) -> [Inline] -> [Inline] Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Inline] -> m [Inline]) -> [Inline] -> m [Inline] Source #

query :: Monoid c => ([Inline] -> c) -> [Inline] -> c Source #

Walkable [Block] [Block] Source # 

Methods

walk :: ([Block] -> [Block]) -> [Block] -> [Block] Source #

walkM :: (Monad m, Applicative m, Functor m) => ([Block] -> m [Block]) -> [Block] -> m [Block] Source #

query :: Monoid c => ([Block] -> c) -> [Block] -> c Source #