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

Copyright | Copyright (C) 2013 John MacFarlane
License | BSD3
Maintainer | John MacFarlane <jgm@berkeley.edu>
Stability | alpha
Portability | portable
Safe Haskell | None
Language | Haskell98

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 #

Minimal complete definition

walk, walkM, query

Methods

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.

Instances

Walkable Inline Citation # |
Methods walk :: (Inline -> Inline) -> Citation -> Citation # walkM :: (Monad m, Functor m) => (Inline -> m Inline) -> Citation -> m Citation # query :: Monoid c => (Inline -> c) -> Citation -> c #
Walkable Inline Inline # |
Methods walk :: (Inline -> Inline) -> Inline -> Inline # walkM :: (Monad m, Functor m) => (Inline -> m Inline) -> Inline -> m Inline # query :: Monoid c => (Inline -> c) -> Inline -> c #
Walkable Inline Block # |
Methods walk :: (Inline -> Inline) -> Block -> Block # walkM :: (Monad m, Functor m) => (Inline -> m Inline) -> Block -> m Block # query :: Monoid c => (Inline -> c) -> Block -> c #
Walkable Inline MetaValue # |
Methods walk :: (Inline -> Inline) -> MetaValue -> MetaValue # walkM :: (Monad m, Functor m) => (Inline -> m Inline) -> MetaValue -> m MetaValue # query :: Monoid c => (Inline -> c) -> MetaValue -> c #
Walkable Inline Meta # |
Methods walk :: (Inline -> Inline) -> Meta -> Meta # walkM :: (Monad m, Functor m) => (Inline -> m Inline) -> Meta -> m Meta # query :: Monoid c => (Inline -> c) -> Meta -> c #
Walkable Inline Pandoc # |
Methods walk :: (Inline -> Inline) -> Pandoc -> Pandoc # walkM :: (Monad m, Functor m) => (Inline -> m Inline) -> Pandoc -> m Pandoc # query :: Monoid c => (Inline -> c) -> Pandoc -> c #
Walkable Block Citation # |
Methods walk :: (Block -> Block) -> Citation -> Citation # walkM :: (Monad m, Functor m) => (Block -> m Block) -> Citation -> m Citation # query :: Monoid c => (Block -> c) -> Citation -> c #
Walkable Block Inline # |
Methods walk :: (Block -> Block) -> Inline -> Inline # walkM :: (Monad m, Functor m) => (Block -> m Block) -> Inline -> m Inline # query :: Monoid c => (Block -> c) -> Inline -> c #
Walkable Block Block # |
Methods walk :: (Block -> Block) -> Block -> Block # walkM :: (Monad m, Functor m) => (Block -> m Block) -> Block -> m Block # query :: Monoid c => (Block -> c) -> Block -> c #
Walkable Block MetaValue # |
Methods walk :: (Block -> Block) -> MetaValue -> MetaValue # walkM :: (Monad m, Functor m) => (Block -> m Block) -> MetaValue -> m MetaValue # query :: Monoid c => (Block -> c) -> MetaValue -> c #
Walkable Block Meta # |
Methods walk :: (Block -> Block) -> Meta -> Meta # walkM :: (Monad m, Functor m) => (Block -> m Block) -> Meta -> m Meta # query :: Monoid c => (Block -> c) -> Meta -> c #
Walkable Block Pandoc # |
Methods walk :: (Block -> Block) -> Pandoc -> Pandoc # walkM :: (Monad m, Functor m) => (Block -> m Block) -> Pandoc -> m Pandoc # query :: Monoid c => (Block -> c) -> Pandoc -> c #
Walkable Meta Meta # |
Methods walk :: (Meta -> Meta) -> Meta -> Meta # walkM :: (Monad m, Functor m) => (Meta -> m Meta) -> Meta -> m Meta # query :: Monoid c => (Meta -> c) -> Meta -> c #
Walkable Pandoc Pandoc # |
Methods walk :: (Pandoc -> Pandoc) -> Pandoc -> Pandoc # walkM :: (Monad m, Functor m) => (Pandoc -> m Pandoc) -> Pandoc -> m Pandoc # query :: Monoid c => (Pandoc -> c) -> Pandoc -> c #
(Foldable t, Traversable t, Walkable a b) => Walkable a (t b) # |
Methods walk :: (a -> a) -> t b -> t b # walkM :: (Monad m, Functor m) => (a -> m a) -> t b -> m (t b) # query :: Monoid c => (a -> c) -> t b -> c #
(Walkable a b, Walkable a c) => Walkable a (b, c) # |
Methods walk :: (a -> a) -> (b, c) -> (b, c) # walkM :: (Monad m, Functor m) => (a -> m a) -> (b, c) -> m (b, c) # query :: Monoid c => (a -> c) -> (b, c) -> c #