{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
#if MIN_VERSION_base(4,9,0)
{-# OPTIONS_GHC -fno-warn-redundant-constraints -O2 #-}
#endif
#define OVERLAPS {-# OVERLAPPING #-}
{-
Copyright (c) 2013-2023, John MacFarlane

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of John MacFarlane nor the names of other
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-}

{- |
   Module      : Text.Pandoc.Walk
   Copyright   : Copyright (C) 2013-2023 John MacFarlane
   License     : BSD3

   Maintainer  : John MacFarlane <jgm@berkeley.edu>
   Stability   : alpha
   Portability : portable

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 -> [Text]
> extractURL (Link _ _ (u,_)) = [u]
> extractURL (Image _ _ (u,_)) = [u]
> extractURL _ = []
>
> extractURLs :: Pandoc -> [Text]
> extractURLs = query extractURL
-}


module Text.Pandoc.Walk
  ( Walkable(..)
  , queryBlock
  , queryCaption
  , queryRow
  , queryTableHead
  , queryTableBody
  , queryTableFoot
  , queryCell
  , queryCitation
  , queryInline
  , queryMetaValue
  , queryMetaValue'
  , queryPandoc
  , walkBlockM
  , walkCaptionM
  , walkRowM
  , walkTableHeadM
  , walkTableBodyM
  , walkTableFootM
  , walkCellM
  , walkCitationM
  , walkInlineM
  , walkMetaValueM
  , walkMetaValueM'
  , walkPandocM
  )
where
import Control.Applicative (Applicative ((<*>), pure), (<$>))
import Control.Monad ((>=>))
import Data.Functor.Identity (Identity (runIdentity))
import qualified Data.Map as M
import Text.Pandoc.Definition
import qualified Data.Traversable as T
import Data.Traversable (Traversable)
import qualified Data.Foldable as F
import Data.Foldable (Foldable)
import Data.Monoid ((<>))

class Walkable a b where
  -- | @walk f x@ walks the structure @x@ (bottom up) and replaces every
  -- occurrence of an @a@ with the result of applying @f@ to it.
  walk  :: (a -> a) -> b -> b
  walk a -> a
f = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
f)
  -- | A monadic version of 'walk'.
  walkM :: (Monad m, Applicative m, Functor m) => (a -> m a) -> b -> m b
  -- | @query f x@ walks the structure @x@ (bottom up) and applies @f@
  -- to every @a@, appending the results.
  query :: Monoid c => (a -> c) -> b -> c
  {-# MINIMAL walkM, query #-}

instance (Foldable t, Traversable t, Walkable a b) => Walkable a (t b) where
  walk :: (a -> a) -> t b -> t b
walk a -> a
f  = forall (t :: * -> *) a b. Traversable t => (a -> b) -> t a -> t b
T.fmapDefault (forall a b. Walkable a b => (a -> a) -> b -> b
walk a -> a
f)
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(a -> m a) -> t b -> m (t b)
walkM a -> m a
f = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
T.mapM (forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f)
  query :: forall c. Monoid c => (a -> c) -> t b -> c
query a -> c
f = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap (forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f)

-- Walk pairs by handling both elements, then combine the results.
instance OVERLAPS
        (Walkable a b, Walkable a c) => Walkable a (b,c) where
  walk :: (a -> a) -> (b, c) -> (b, c)
walk a -> a
f (b
x,c
y)  = (forall a b. Walkable a b => (a -> a) -> b -> b
walk a -> a
f b
x, forall a b. Walkable a b => (a -> a) -> b -> b
walk a -> a
f c
y)
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(a -> m a) -> (b, c) -> m (b, c)
walkM a -> m a
f (b
x,c
y) = do b
x' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f b
x
                     c
y' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f c
y
                     forall (m :: * -> *) a. Monad m => a -> m a
return (b
x',c
y')
  query :: forall c. Monoid c => (a -> c) -> (b, c) -> c
query a -> c
f (b
x,c
y) = forall a. Monoid a => a -> a -> a
mappend (forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f b
x) (forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f c
y)

instance Walkable Inline Inline where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Inline -> m Inline
walkM Inline -> m Inline
f Inline
x = forall a (m :: * -> *).
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monad m, Applicative m, Functor m) =>
(a -> m a) -> Inline -> m Inline
walkInlineM Inline -> m Inline
f Inline
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Inline -> m Inline
f
  query :: forall c. Monoid c => (Inline -> c) -> Inline -> c
query Inline -> c
f Inline
x = Inline -> c
f Inline
x forall a. Semigroup a => a -> a -> a
<> forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Inline -> c
queryInline Inline -> c
f Inline
x

instance OVERLAPS
         Walkable [Inline] [Inline] where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> [Inline] -> m [Inline]
walkM [Inline] -> m [Inline]
f = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
T.traverse (forall a (m :: * -> *).
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monad m, Applicative m, Functor m) =>
(a -> m a) -> Inline -> m Inline
walkInlineM [Inline] -> m [Inline]
f) forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> [Inline] -> m [Inline]
f
  query :: forall c. Monoid c => ([Inline] -> c) -> [Inline] -> c
query [Inline] -> c
f [Inline]
inlns = [Inline] -> c
f [Inline]
inlns forall a. Semigroup a => a -> a -> a
<> forall a. Monoid a => [a] -> a
mconcat (forall a b. (a -> b) -> [a] -> [b]
map (forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Inline -> c
queryInline [Inline] -> c
f) [Inline]
inlns)

instance Walkable [Inline] Inline where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Inline -> m Inline
walkM = forall a (m :: * -> *).
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monad m, Applicative m, Functor m) =>
(a -> m a) -> Inline -> m Inline
walkInlineM
  query :: forall c. Monoid c => ([Inline] -> c) -> Inline -> c
query = forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Inline -> c
queryInline

instance Walkable Inline Block where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Block -> m Block
walkM = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Monad m, Applicative m, Functor m) =>
(a -> m a) -> Block -> m Block
walkBlockM
  query :: forall c. Monoid c => (Inline -> c) -> Block -> c
query = forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Walkable a [Inline], Monoid c) =>
(a -> c) -> Block -> c
queryBlock

instance Walkable [Inline] Block where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Block -> m Block
walkM = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Monad m, Applicative m, Functor m) =>
(a -> m a) -> Block -> m Block
walkBlockM
  query :: forall c. Monoid c => ([Inline] -> c) -> Block -> c
query = forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Walkable a [Inline], Monoid c) =>
(a -> c) -> Block -> c
queryBlock

instance Walkable Block Block where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Block -> m Block
walkM Block -> m Block
f Block
x = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Monad m, Applicative m, Functor m) =>
(a -> m a) -> Block -> m Block
walkBlockM Block -> m Block
f Block
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Block -> m Block
f
  query :: forall c. Monoid c => (Block -> c) -> Block -> c
query Block -> c
f Block
x = Block -> c
f Block
x forall a. Semigroup a => a -> a -> a
<> forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Walkable a [Inline], Monoid c) =>
(a -> c) -> Block -> c
queryBlock Block -> c
f Block
x

instance Walkable [Block] Block where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Block -> m Block
walkM = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Monad m, Applicative m, Functor m) =>
(a -> m a) -> Block -> m Block
walkBlockM
  query :: forall c. Monoid c => ([Block] -> c) -> Block -> c
query = forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Walkable a [Inline], Monoid c) =>
(a -> c) -> Block -> c
queryBlock

instance OVERLAPS
         Walkable [Block] [Block] where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> [Block] -> m [Block]
walkM [Block] -> m [Block]
f = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
T.traverse (forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Monad m, Applicative m, Functor m) =>
(a -> m a) -> Block -> m Block
walkBlockM [Block] -> m [Block]
f) forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> [Block] -> m [Block]
f
  query :: forall c. Monoid c => ([Block] -> c) -> [Block] -> c
query [Block] -> c
f [Block]
blks = [Block] -> c
f [Block]
blks forall a. Semigroup a => a -> a -> a
<> forall a. Monoid a => [a] -> a
mconcat (forall a b. (a -> b) -> [a] -> [b]
map (forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Walkable a [Inline], Monoid c) =>
(a -> c) -> Block -> c
queryBlock [Block] -> c
f) [Block]
blks)

instance Walkable Block Inline where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Inline -> m Inline
walkM = forall a (m :: * -> *).
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monad m, Applicative m, Functor m) =>
(a -> m a) -> Inline -> m Inline
walkInlineM
  query :: forall c. Monoid c => (Block -> c) -> Inline -> c
query = forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Inline -> c
queryInline

instance Walkable [Block] Inline where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Inline -> m Inline
walkM = forall a (m :: * -> *).
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monad m, Applicative m, Functor m) =>
(a -> m a) -> Inline -> m Inline
walkInlineM
  query :: forall c. Monoid c => ([Block] -> c) -> Inline -> c
query = forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Inline -> c
queryInline

--
-- Walk Pandoc
--
instance Walkable Block Pandoc where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Pandoc -> m Pandoc
walkM = forall a (m :: * -> *).
(Walkable a Meta, Walkable a [Block], Monad m, Applicative m,
 Functor m) =>
(a -> m a) -> Pandoc -> m Pandoc
walkPandocM
  query :: forall c. Monoid c => (Block -> c) -> Pandoc -> c
query = forall a c.
(Walkable a Meta, Walkable a [Block], Monoid c) =>
(a -> c) -> Pandoc -> c
queryPandoc

instance Walkable [Block] Pandoc where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Pandoc -> m Pandoc
walkM = forall a (m :: * -> *).
(Walkable a Meta, Walkable a [Block], Monad m, Applicative m,
 Functor m) =>
(a -> m a) -> Pandoc -> m Pandoc
walkPandocM
  query :: forall c. Monoid c => ([Block] -> c) -> Pandoc -> c
query = forall a c.
(Walkable a Meta, Walkable a [Block], Monoid c) =>
(a -> c) -> Pandoc -> c
queryPandoc

instance Walkable Inline Pandoc where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Pandoc -> m Pandoc
walkM = forall a (m :: * -> *).
(Walkable a Meta, Walkable a [Block], Monad m, Applicative m,
 Functor m) =>
(a -> m a) -> Pandoc -> m Pandoc
walkPandocM
  query :: forall c. Monoid c => (Inline -> c) -> Pandoc -> c
query = forall a c.
(Walkable a Meta, Walkable a [Block], Monoid c) =>
(a -> c) -> Pandoc -> c
queryPandoc

instance Walkable [Inline] Pandoc where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Pandoc -> m Pandoc
walkM = forall a (m :: * -> *).
(Walkable a Meta, Walkable a [Block], Monad m, Applicative m,
 Functor m) =>
(a -> m a) -> Pandoc -> m Pandoc
walkPandocM
  query :: forall c. Monoid c => ([Inline] -> c) -> Pandoc -> c
query = forall a c.
(Walkable a Meta, Walkable a [Block], Monoid c) =>
(a -> c) -> Pandoc -> c
queryPandoc

instance Walkable Meta Pandoc where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Meta -> m Meta) -> Pandoc -> m Pandoc
walkM Meta -> m Meta
f (Pandoc Meta
m [Block]
bs) = Meta -> [Block] -> Pandoc
Pandoc forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Meta -> m Meta
f Meta
m forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [Block]
bs
  query :: forall c. Monoid c => (Meta -> c) -> Pandoc -> c
query Meta -> c
f (Pandoc Meta
m [Block]
_) = Meta -> c
f Meta
m

instance Walkable MetaValue Pandoc where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(MetaValue -> m MetaValue) -> Pandoc -> m Pandoc
walkM MetaValue -> m MetaValue
f (Pandoc Meta
m [Block]
bs) = Meta -> [Block] -> Pandoc
Pandoc forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM MetaValue -> m MetaValue
f Meta
m forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [Block]
bs
  query :: forall c. Monoid c => (MetaValue -> c) -> Pandoc -> c
query MetaValue -> c
f (Pandoc Meta
m [Block]
_) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query MetaValue -> c
f Meta
m

instance Walkable Pandoc Pandoc where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Pandoc -> m Pandoc) -> Pandoc -> m Pandoc
walkM Pandoc -> m Pandoc
f = Pandoc -> m Pandoc
f
  query :: forall c. Monoid c => (Pandoc -> c) -> Pandoc -> c
query Pandoc -> c
f = Pandoc -> c
f

--
-- Walk Meta
--
instance Walkable Meta Meta where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Meta -> m Meta) -> Meta -> m Meta
walkM Meta -> m Meta
f = Meta -> m Meta
f
  query :: forall c. Monoid c => (Meta -> c) -> Meta -> c
query Meta -> c
f = Meta -> c
f

instance Walkable Inline Meta where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Meta -> m Meta
walkM Inline -> m Inline
f (Meta Map Text MetaValue
metamap) = Map Text MetaValue -> Meta
Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM Inline -> m Inline
f Map Text MetaValue
metamap
  query :: forall c. Monoid c => (Inline -> c) -> Meta -> c
query Inline -> c
f (Meta Map Text MetaValue
metamap) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query Inline -> c
f Map Text MetaValue
metamap

instance Walkable [Inline] Meta where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Meta -> m Meta
walkM [Inline] -> m [Inline]
f (Meta Map Text MetaValue
metamap) = Map Text MetaValue -> Meta
Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM [Inline] -> m [Inline]
f Map Text MetaValue
metamap
  query :: forall c. Monoid c => ([Inline] -> c) -> Meta -> c
query [Inline] -> c
f (Meta Map Text MetaValue
metamap) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query [Inline] -> c
f Map Text MetaValue
metamap

instance Walkable Block Meta where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Meta -> m Meta
walkM Block -> m Block
f (Meta Map Text MetaValue
metamap) = Map Text MetaValue -> Meta
Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM Block -> m Block
f Map Text MetaValue
metamap
  query :: forall c. Monoid c => (Block -> c) -> Meta -> c
query Block -> c
f (Meta Map Text MetaValue
metamap) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query Block -> c
f Map Text MetaValue
metamap

instance Walkable [Block] Meta where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Meta -> m Meta
walkM [Block] -> m [Block]
f (Meta Map Text MetaValue
metamap) = Map Text MetaValue -> Meta
Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM [Block] -> m [Block]
f Map Text MetaValue
metamap
  query :: forall c. Monoid c => ([Block] -> c) -> Meta -> c
query [Block] -> c
f (Meta Map Text MetaValue
metamap) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query [Block] -> c
f Map Text MetaValue
metamap

instance Walkable MetaValue Meta where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(MetaValue -> m MetaValue) -> Meta -> m Meta
walkM MetaValue -> m MetaValue
f (Meta Map Text MetaValue
metamap) =
    Map Text MetaValue -> Meta
Meta forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Eq k => [(k, a)] -> Map k a
M.fromAscList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Text
k, MetaValue
v) -> (,) Text
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM MetaValue -> m MetaValue
f MetaValue
v) (forall k a. Map k a -> [(k, a)]
M.toAscList Map Text MetaValue
metamap)
  query :: forall c. Monoid c => (MetaValue -> c) -> Meta -> c
query MetaValue -> c
f (Meta Map Text MetaValue
metamap) = forall m k a. Monoid m => (k -> a -> m) -> Map k a -> m
M.foldMapWithKey (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query MetaValue -> c
f) Map Text MetaValue
metamap

--
-- Walk MetaValue
--
instance Walkable MetaValue MetaValue where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(MetaValue -> m MetaValue) -> MetaValue -> m MetaValue
walkM MetaValue -> m MetaValue
f MetaValue
x = forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(MetaValue -> m MetaValue) -> MetaValue -> m MetaValue
walkMetaValueM' MetaValue -> m MetaValue
f MetaValue
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MetaValue -> m MetaValue
f
  query :: forall c. Monoid c => (MetaValue -> c) -> MetaValue -> c
query MetaValue -> c
f MetaValue
x = MetaValue -> c
f MetaValue
x forall a. Semigroup a => a -> a -> a
<> forall c. Monoid c => (MetaValue -> c) -> MetaValue -> c
queryMetaValue' MetaValue -> c
f MetaValue
x

instance Walkable Inline MetaValue where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> MetaValue -> m MetaValue
walkM = forall a (f :: * -> *).
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monad f, Applicative f, Functor f) =>
(a -> f a) -> MetaValue -> f MetaValue
walkMetaValueM
  query :: forall c. Monoid c => (Inline -> c) -> MetaValue -> c
query = forall a c.
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> MetaValue -> c
queryMetaValue

instance Walkable [Inline] MetaValue where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> MetaValue -> m MetaValue
walkM = forall a (f :: * -> *).
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monad f, Applicative f, Functor f) =>
(a -> f a) -> MetaValue -> f MetaValue
walkMetaValueM
  query :: forall c. Monoid c => ([Inline] -> c) -> MetaValue -> c
query = forall a c.
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> MetaValue -> c
queryMetaValue

instance Walkable Block MetaValue where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> MetaValue -> m MetaValue
walkM = forall a (f :: * -> *).
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monad f, Applicative f, Functor f) =>
(a -> f a) -> MetaValue -> f MetaValue
walkMetaValueM
  query :: forall c. Monoid c => (Block -> c) -> MetaValue -> c
query = forall a c.
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> MetaValue -> c
queryMetaValue

instance Walkable [Block] MetaValue where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> MetaValue -> m MetaValue
walkM = forall a (f :: * -> *).
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monad f, Applicative f, Functor f) =>
(a -> f a) -> MetaValue -> f MetaValue
walkMetaValueM
  query :: forall c. Monoid c => ([Block] -> c) -> MetaValue -> c
query = forall a c.
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> MetaValue -> c
queryMetaValue

--
-- Walk Row
--
instance Walkable Inline Row where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Row -> m Row
walkM = forall a (m :: * -> *).
(Walkable a Cell, Monad m) =>
(a -> m a) -> Row -> m Row
walkRowM
  query :: forall c. Monoid c => (Inline -> c) -> Row -> c
query = forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c
queryRow

instance Walkable [Inline] Row where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Row -> m Row
walkM = forall a (m :: * -> *).
(Walkable a Cell, Monad m) =>
(a -> m a) -> Row -> m Row
walkRowM
  query :: forall c. Monoid c => ([Inline] -> c) -> Row -> c
query = forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c
queryRow

instance Walkable Block Row where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Row -> m Row
walkM = forall a (m :: * -> *).
(Walkable a Cell, Monad m) =>
(a -> m a) -> Row -> m Row
walkRowM
  query :: forall c. Monoid c => (Block -> c) -> Row -> c
query = forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c
queryRow

instance Walkable [Block] Row where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Row -> m Row
walkM = forall a (m :: * -> *).
(Walkable a Cell, Monad m) =>
(a -> m a) -> Row -> m Row
walkRowM
  query :: forall c. Monoid c => ([Block] -> c) -> Row -> c
query = forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c
queryRow

--
-- Walk TableHead
--
instance Walkable Inline TableHead where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> TableHead -> m TableHead
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableHead -> m TableHead
walkTableHeadM
  query :: forall c. Monoid c => (Inline -> c) -> TableHead -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableHead -> c
queryTableHead

instance Walkable [Inline] TableHead where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> TableHead -> m TableHead
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableHead -> m TableHead
walkTableHeadM
  query :: forall c. Monoid c => ([Inline] -> c) -> TableHead -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableHead -> c
queryTableHead

instance Walkable Block TableHead where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> TableHead -> m TableHead
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableHead -> m TableHead
walkTableHeadM
  query :: forall c. Monoid c => (Block -> c) -> TableHead -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableHead -> c
queryTableHead

instance Walkable [Block] TableHead where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> TableHead -> m TableHead
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableHead -> m TableHead
walkTableHeadM
  query :: forall c. Monoid c => ([Block] -> c) -> TableHead -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableHead -> c
queryTableHead

--
-- Walk TableBody
--
instance Walkable Inline TableBody where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> TableBody -> m TableBody
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableBody -> m TableBody
walkTableBodyM
  query :: forall c. Monoid c => (Inline -> c) -> TableBody -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableBody -> c
queryTableBody

instance Walkable [Inline] TableBody where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> TableBody -> m TableBody
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableBody -> m TableBody
walkTableBodyM
  query :: forall c. Monoid c => ([Inline] -> c) -> TableBody -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableBody -> c
queryTableBody

instance Walkable Block TableBody where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> TableBody -> m TableBody
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableBody -> m TableBody
walkTableBodyM
  query :: forall c. Monoid c => (Block -> c) -> TableBody -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableBody -> c
queryTableBody

instance Walkable [Block] TableBody where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> TableBody -> m TableBody
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableBody -> m TableBody
walkTableBodyM
  query :: forall c. Monoid c => ([Block] -> c) -> TableBody -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableBody -> c
queryTableBody

--
-- Walk TableFoot
--
instance Walkable Inline TableFoot where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> TableFoot -> m TableFoot
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableFoot -> m TableFoot
walkTableFootM
  query :: forall c. Monoid c => (Inline -> c) -> TableFoot -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableFoot -> c
queryTableFoot

instance Walkable [Inline] TableFoot where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> TableFoot -> m TableFoot
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableFoot -> m TableFoot
walkTableFootM
  query :: forall c. Monoid c => ([Inline] -> c) -> TableFoot -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableFoot -> c
queryTableFoot

instance Walkable Block TableFoot where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> TableFoot -> m TableFoot
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableFoot -> m TableFoot
walkTableFootM
  query :: forall c. Monoid c => (Block -> c) -> TableFoot -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableFoot -> c
queryTableFoot

instance Walkable [Block] TableFoot where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> TableFoot -> m TableFoot
walkM = forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableFoot -> m TableFoot
walkTableFootM
  query :: forall c. Monoid c => ([Block] -> c) -> TableFoot -> c
query = forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableFoot -> c
queryTableFoot

--
-- Walk Caption
--
instance Walkable Inline Caption where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Caption -> m Caption
walkM = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Monad m,
 Walkable a [Inline]) =>
(a -> m a) -> Caption -> m Caption
walkCaptionM
  query :: forall c. Monoid c => (Inline -> c) -> Caption -> c
query = forall a c.
(Walkable a [Block], Walkable a [Inline], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Caption -> c
queryCaption

instance Walkable [Inline] Caption where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Caption -> m Caption
walkM = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Monad m,
 Walkable a [Inline]) =>
(a -> m a) -> Caption -> m Caption
walkCaptionM
  query :: forall c. Monoid c => ([Inline] -> c) -> Caption -> c
query = forall a c.
(Walkable a [Block], Walkable a [Inline], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Caption -> c
queryCaption

instance Walkable Block Caption where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Caption -> m Caption
walkM = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Monad m,
 Walkable a [Inline]) =>
(a -> m a) -> Caption -> m Caption
walkCaptionM
  query :: forall c. Monoid c => (Block -> c) -> Caption -> c
query = forall a c.
(Walkable a [Block], Walkable a [Inline], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Caption -> c
queryCaption

instance Walkable [Block] Caption where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Caption -> m Caption
walkM = forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Monad m,
 Walkable a [Inline]) =>
(a -> m a) -> Caption -> m Caption
walkCaptionM
  query :: forall c. Monoid c => ([Block] -> c) -> Caption -> c
query = forall a c.
(Walkable a [Block], Walkable a [Inline], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Caption -> c
queryCaption

--
-- Walk Cell
--
instance Walkable Inline Cell where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Cell -> m Cell
walkM = forall a (m :: * -> *).
(Walkable a [Block], Monad m) =>
(a -> m a) -> Cell -> m Cell
walkCellM
  query :: forall c. Monoid c => (Inline -> c) -> Cell -> c
query = forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c
queryCell

instance Walkable [Inline] Cell where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Cell -> m Cell
walkM = forall a (m :: * -> *).
(Walkable a [Block], Monad m) =>
(a -> m a) -> Cell -> m Cell
walkCellM
  query :: forall c. Monoid c => ([Inline] -> c) -> Cell -> c
query = forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c
queryCell

instance Walkable Block Cell where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Cell -> m Cell
walkM = forall a (m :: * -> *).
(Walkable a [Block], Monad m) =>
(a -> m a) -> Cell -> m Cell
walkCellM
  query :: forall c. Monoid c => (Block -> c) -> Cell -> c
query = forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c
queryCell

instance Walkable [Block] Cell where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Cell -> m Cell
walkM = forall a (m :: * -> *).
(Walkable a [Block], Monad m) =>
(a -> m a) -> Cell -> m Cell
walkCellM
  query :: forall c. Monoid c => ([Block] -> c) -> Cell -> c
query = forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c
queryCell

--
-- Walk Citation
--
instance Walkable Inline Citation where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Inline -> m Inline) -> Citation -> m Citation
walkM = forall a (m :: * -> *).
(Walkable a [Inline], Monad m, Applicative m, Functor m) =>
(a -> m a) -> Citation -> m Citation
walkCitationM
  query :: forall c. Monoid c => (Inline -> c) -> Citation -> c
query = forall a c.
(Walkable a [Inline], Monoid c) =>
(a -> c) -> Citation -> c
queryCitation

instance Walkable [Inline] Citation where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Inline] -> m [Inline]) -> Citation -> m Citation
walkM = forall a (m :: * -> *).
(Walkable a [Inline], Monad m, Applicative m, Functor m) =>
(a -> m a) -> Citation -> m Citation
walkCitationM
  query :: forall c. Monoid c => ([Inline] -> c) -> Citation -> c
query = forall a c.
(Walkable a [Inline], Monoid c) =>
(a -> c) -> Citation -> c
queryCitation

instance Walkable Block Citation where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(Block -> m Block) -> Citation -> m Citation
walkM = forall a (m :: * -> *).
(Walkable a [Inline], Monad m, Applicative m, Functor m) =>
(a -> m a) -> Citation -> m Citation
walkCitationM
  query :: forall c. Monoid c => (Block -> c) -> Citation -> c
query = forall a c.
(Walkable a [Inline], Monoid c) =>
(a -> c) -> Citation -> c
queryCitation

instance Walkable [Block] Citation where
  walkM :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
([Block] -> m [Block]) -> Citation -> m Citation
walkM = forall a (m :: * -> *).
(Walkable a [Inline], Monad m, Applicative m, Functor m) =>
(a -> m a) -> Citation -> m Citation
walkCitationM
  query :: forall c. Monoid c => ([Block] -> c) -> Citation -> c
query = forall a c.
(Walkable a [Inline], Monoid c) =>
(a -> c) -> Citation -> c
queryCitation

-- | Helper method to walk to elements nested below @'Inline'@ nodes.
--
-- When walking an inline with this function, only the contents of the traversed
-- inline element may change. The element itself, i.e. its constructor, cannot
-- be changed.
walkInlineM :: (Walkable a Citation, Walkable a [Block],
                Walkable a [Inline], Monad m, Applicative m, Functor m)
            => (a -> m a) -> Inline -> m Inline
walkInlineM :: forall a (m :: * -> *).
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monad m, Applicative m, Functor m) =>
(a -> m a) -> Inline -> m Inline
walkInlineM a -> m a
_ (Str Text
xs)         = forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inline
Str Text
xs)
walkInlineM a -> m a
f (Emph [Inline]
xs)        = [Inline] -> Inline
Emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Underline [Inline]
xs)   = [Inline] -> Inline
Underline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Strong [Inline]
xs)      = [Inline] -> Inline
Strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Strikeout [Inline]
xs)   = [Inline] -> Inline
Strikeout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Subscript [Inline]
xs)   = [Inline] -> Inline
Subscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Superscript [Inline]
xs) = [Inline] -> Inline
Superscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (SmallCaps [Inline]
xs)   = [Inline] -> Inline
SmallCaps forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Quoted QuoteType
qt [Inline]
xs)   = QuoteType -> [Inline] -> Inline
Quoted QuoteType
qt forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Link Attr
atr [Inline]
xs Target
t)  = Attr -> [Inline] -> Target -> Inline
Link Attr
atr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure Target
t
walkInlineM a -> m a
f (Image Attr
atr [Inline]
xs Target
t) = Attr -> [Inline] -> Target -> Inline
Image Attr
atr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure Target
t
walkInlineM a -> m a
f (Note [Block]
bs)        = [Block] -> Inline
Note forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Block]
bs
walkInlineM a -> m a
f (Span Attr
attr [Inline]
xs)   = Attr -> [Inline] -> Inline
Span Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
f (Cite [Citation]
cs [Inline]
xs)     = [Citation] -> [Inline] -> Inline
Cite forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Citation]
cs forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkInlineM a -> m a
_ Inline
LineBreak        = forall (m :: * -> *) a. Monad m => a -> m a
return Inline
LineBreak
walkInlineM a -> m a
_ Inline
SoftBreak        = forall (m :: * -> *) a. Monad m => a -> m a
return Inline
SoftBreak
walkInlineM a -> m a
_ Inline
Space            = forall (m :: * -> *) a. Monad m => a -> m a
return Inline
Space
walkInlineM a -> m a
_ x :: Inline
x@Code {}        = forall (m :: * -> *) a. Monad m => a -> m a
return Inline
x
walkInlineM a -> m a
_ x :: Inline
x@Math {}        = forall (m :: * -> *) a. Monad m => a -> m a
return Inline
x
walkInlineM a -> m a
_ x :: Inline
x@RawInline {}   = forall (m :: * -> *) a. Monad m => a -> m a
return Inline
x

-- | Perform a query on elements nested below an @'Inline'@ element by
-- querying nested lists of @Inline@s, @Block@s, or @Citation@s.
queryInline :: (Walkable a Citation, Walkable a [Block],
                Walkable a [Inline], Monoid c)
            => (a -> c) -> Inline -> c
queryInline :: forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Inline -> c
queryInline a -> c
_ (Str Text
_)         = forall a. Monoid a => a
mempty
queryInline a -> c
f (Emph [Inline]
xs)       = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Underline [Inline]
xs)  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Strong [Inline]
xs)     = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Strikeout [Inline]
xs)  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Subscript [Inline]
xs)  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Superscript [Inline]
xs)= forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (SmallCaps [Inline]
xs)  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Quoted QuoteType
_ [Inline]
xs)   = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Cite [Citation]
cs [Inline]
xs)    = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Citation]
cs forall a. Semigroup a => a -> a -> a
<> forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
_ (Code Attr
_ Text
_)      = forall a. Monoid a => a
mempty
queryInline a -> c
_ Inline
Space           = forall a. Monoid a => a
mempty
queryInline a -> c
_ Inline
SoftBreak       = forall a. Monoid a => a
mempty
queryInline a -> c
_ Inline
LineBreak       = forall a. Monoid a => a
mempty
queryInline a -> c
_ (Math MathType
_ Text
_)      = forall a. Monoid a => a
mempty
queryInline a -> c
_ (RawInline Format
_ Text
_) = forall a. Monoid a => a
mempty
queryInline a -> c
f (Link Attr
_ [Inline]
xs Target
_)   = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Image Attr
_ [Inline]
xs Target
_)  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryInline a -> c
f (Note [Block]
bs)       = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
bs
queryInline a -> c
f (Span Attr
_ [Inline]
xs)     = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs


-- | Helper method to walk to elements nested below @'Block'@ nodes.
--
-- When walking a block with this function, only the contents of the traversed
-- block element may change. The element itself, i.e. its constructor, its @'Attr'@,
-- and its raw text value, will remain unchanged.
walkBlockM :: (Walkable a [Block], Walkable a [Inline], Walkable a Row,
               Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
               Walkable a TableFoot, Monad m, Applicative m, Functor m)
           => (a -> m a) -> Block -> m Block
walkBlockM :: forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Monad m, Applicative m, Functor m) =>
(a -> m a) -> Block -> m Block
walkBlockM a -> m a
f (Para [Inline]
xs)                = [Inline] -> Block
Para forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkBlockM a -> m a
f (Plain [Inline]
xs)               = [Inline] -> Block
Plain forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkBlockM a -> m a
f (LineBlock [[Inline]]
xs)           = [[Inline]] -> Block
LineBlock forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [[Inline]]
xs
walkBlockM a -> m a
f (BlockQuote [Block]
xs)          = [Block] -> Block
BlockQuote forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Block]
xs
walkBlockM a -> m a
f (OrderedList ListAttributes
a [[Block]]
cs)       = ListAttributes -> [[Block]] -> Block
OrderedList ListAttributes
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [[Block]]
cs
walkBlockM a -> m a
f (BulletList [[Block]]
cs)          = [[Block]] -> Block
BulletList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [[Block]]
cs
walkBlockM a -> m a
f (DefinitionList [([Inline], [[Block]])]
xs)      = [([Inline], [[Block]])] -> Block
DefinitionList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [([Inline], [[Block]])]
xs
walkBlockM a -> m a
f (Header Int
lev Attr
attr [Inline]
xs)     = Int -> Attr -> [Inline] -> Block
Header Int
lev Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
xs
walkBlockM a -> m a
f (Div Attr
attr [Block]
bs')           = Attr -> [Block] -> Block
Div Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Block]
bs'
walkBlockM a -> m a
_ x :: Block
x@CodeBlock {}           = forall (m :: * -> *) a. Monad m => a -> m a
return Block
x
walkBlockM a -> m a
_ x :: Block
x@RawBlock {}            = forall (m :: * -> *) a. Monad m => a -> m a
return Block
x
walkBlockM a -> m a
_ Block
HorizontalRule           = forall (m :: * -> *) a. Monad m => a -> m a
return Block
HorizontalRule
walkBlockM a -> m a
f (Table Attr
attr Caption
capt [ColSpec]
as TableHead
hs [TableBody]
bs TableFoot
fs)
  = do Caption
capt' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f Caption
capt
       TableHead
hs' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f TableHead
hs
       [TableBody]
bs' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [TableBody]
bs
       TableFoot
fs' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f TableFoot
fs
       forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr Caption
capt' [ColSpec]
as TableHead
hs' [TableBody]
bs' TableFoot
fs'
walkBlockM a -> m a
f (Figure Attr
attr Caption
capt [Block]
blks)
  = do Caption
capt' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f Caption
capt
       [Block]
blks' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Block]
blks
       forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Caption -> [Block] -> Block
Figure Attr
attr Caption
capt' [Block]
blks'

-- | Perform a query on elements nested below a @'Block'@ element by
-- querying all directly nested lists of @Inline@s or @Block@s.
queryBlock :: (Walkable a Citation, Walkable a [Block], Walkable a Row,
               Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
               Walkable a TableFoot, Walkable a [Inline], Monoid c)
           => (a -> c) -> Block -> c
queryBlock :: forall a c.
(Walkable a Citation, Walkable a [Block], Walkable a Row,
 Walkable a Caption, Walkable a TableHead, Walkable a TableBody,
 Walkable a TableFoot, Walkable a [Inline], Monoid c) =>
(a -> c) -> Block -> c
queryBlock a -> c
f (Para [Inline]
xs)                = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryBlock a -> c
f (Plain [Inline]
xs)               = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryBlock a -> c
f (LineBlock [[Inline]]
xs)           = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [[Inline]]
xs
queryBlock a -> c
_ (CodeBlock Attr
_ Text
_)          = forall a. Monoid a => a
mempty
queryBlock a -> c
_ (RawBlock Format
_ Text
_)           = forall a. Monoid a => a
mempty
queryBlock a -> c
f (BlockQuote [Block]
bs)          = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
bs
queryBlock a -> c
f (OrderedList ListAttributes
_ [[Block]]
cs)       = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [[Block]]
cs
queryBlock a -> c
f (BulletList [[Block]]
cs)          = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [[Block]]
cs
queryBlock a -> c
f (DefinitionList [([Inline], [[Block]])]
xs)      = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [([Inline], [[Block]])]
xs
queryBlock a -> c
f (Header Int
_ Attr
_ [Inline]
xs)          = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryBlock a -> c
_ Block
HorizontalRule           = forall a. Monoid a => a
mempty
queryBlock a -> c
f (Table Attr
_ Caption
capt [ColSpec]
_ TableHead
hs [TableBody]
bs TableFoot
fs)
  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f Caption
capt forall a. Semigroup a => a -> a -> a
<>
    forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f TableHead
hs forall a. Semigroup a => a -> a -> a
<>
    forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [TableBody]
bs forall a. Semigroup a => a -> a -> a
<>
    forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f TableFoot
fs
queryBlock a -> c
f (Figure Attr
_ Caption
capt [Block]
blks)
  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f Caption
capt forall a. Semigroup a => a -> a -> a
<>
    forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
blks
queryBlock a -> c
f (Div Attr
_ [Block]
bs)               = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
bs

-- | Helper method to walk to elements nested below @'MetaValue'@ nodes.
--
-- When walking a meta value with this function, only the contents of the
-- traversed meta value element may change. @MetaBool@ and @MetaString@ will
-- always remain unchanged.
walkMetaValueM :: (Walkable a MetaValue, Walkable a [Block],
                  Walkable a [Inline], Monad f, Applicative f, Functor f)
               => (a -> f a) -> MetaValue -> f MetaValue
walkMetaValueM :: forall a (f :: * -> *).
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monad f, Applicative f, Functor f) =>
(a -> f a) -> MetaValue -> f MetaValue
walkMetaValueM a -> f a
f (MetaList [MetaValue]
xs)    = [MetaValue] -> MetaValue
MetaList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> f a
f [MetaValue]
xs
walkMetaValueM a -> f a
_ (MetaBool Bool
b)     = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Bool -> MetaValue
MetaBool Bool
b
walkMetaValueM a -> f a
_ (MetaString Text
s)   = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> MetaValue
MetaString Text
s
walkMetaValueM a -> f a
f (MetaInlines [Inline]
xs) = [Inline] -> MetaValue
MetaInlines forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> f a
f [Inline]
xs
walkMetaValueM a -> f a
f (MetaBlocks [Block]
bs)  = [Block] -> MetaValue
MetaBlocks forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> f a
f [Block]
bs
walkMetaValueM a -> f a
f (MetaMap Map Text MetaValue
m)      = Map Text MetaValue -> MetaValue
MetaMap forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> f a
f Map Text MetaValue
m

-- | Helper method to walk @'MetaValue'@ nodes nested below @'MetaValue'@ nodes.
walkMetaValueM' :: (Monad f, Applicative f, Functor f)
                => (MetaValue -> f MetaValue) -> MetaValue -> f MetaValue
walkMetaValueM' :: forall (m :: * -> *).
(Monad m, Applicative m, Functor m) =>
(MetaValue -> m MetaValue) -> MetaValue -> m MetaValue
walkMetaValueM' MetaValue -> f MetaValue
f (MetaMap Map Text MetaValue
m) =
    Map Text MetaValue -> MetaValue
MetaMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Eq k => [(k, a)] -> Map k a
M.fromAscList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Text
k, MetaValue
v) -> (,) Text
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM MetaValue -> f MetaValue
f MetaValue
v) (forall k a. Map k a -> [(k, a)]
M.toAscList Map Text MetaValue
m)
walkMetaValueM' MetaValue -> f MetaValue
f (MetaList [MetaValue]
xs) = [MetaValue] -> MetaValue
MetaList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM MetaValue -> f MetaValue
f) [MetaValue]
xs
walkMetaValueM' MetaValue -> f MetaValue
_ MetaValue
x = forall (m :: * -> *) a. Monad m => a -> m a
return MetaValue
x

-- | Perform a query on elements nested below a @'MetaValue'@ element by
-- querying all directly nested lists of @Inline@s, list of @Block@s, or
-- lists or maps of @MetaValue@s.
queryMetaValue :: (Walkable a MetaValue, Walkable a [Block],
                   Walkable a [Inline], Monoid c)
               => (a -> c) -> MetaValue -> c
queryMetaValue :: forall a c.
(Walkable a MetaValue, Walkable a [Block], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> MetaValue -> c
queryMetaValue a -> c
f (MetaList [MetaValue]
xs)    = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [MetaValue]
xs
queryMetaValue a -> c
_ (MetaBool Bool
_)     = forall a. Monoid a => a
mempty
queryMetaValue a -> c
_ (MetaString Text
_)   = forall a. Monoid a => a
mempty
queryMetaValue a -> c
f (MetaInlines [Inline]
xs) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
xs
queryMetaValue a -> c
f (MetaBlocks [Block]
bs)  = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
bs
queryMetaValue a -> c
f (MetaMap Map Text MetaValue
m)      = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f Map Text MetaValue
m

-- | Perform a query on @'MetaValue'@ elements nested below a @'MetaValue'@
-- element
queryMetaValue' :: Monoid c
                => (MetaValue -> c) -> MetaValue -> c
queryMetaValue' :: forall c. Monoid c => (MetaValue -> c) -> MetaValue -> c
queryMetaValue' MetaValue -> c
f (MetaMap Map Text MetaValue
m)   = forall m k a. Monoid m => (k -> a -> m) -> Map k a -> m
M.foldMapWithKey (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query MetaValue -> c
f) Map Text MetaValue
m
queryMetaValue' MetaValue -> c
f (MetaList [MetaValue]
xs) = forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query MetaValue -> c
f) [MetaValue]
xs
queryMetaValue' MetaValue -> c
_ MetaValue
_             = forall a. Monoid a => a
mempty

-- | Helper method to walk to elements nested below @'Citation'@ nodes.
--
-- The non-inline contents of a citation will remain unchanged during traversal.
-- Only the inline contents, viz. the citation's prefix and postfix, will be
-- traversed further and can thus be changed during this operation.
walkCitationM :: (Walkable a [Inline], Monad m, Applicative m, Functor m)
              => (a -> m a) -> Citation -> m Citation
walkCitationM :: forall a (m :: * -> *).
(Walkable a [Inline], Monad m, Applicative m, Functor m) =>
(a -> m a) -> Citation -> m Citation
walkCitationM a -> m a
f (Citation Text
id' [Inline]
pref [Inline]
suff CitationMode
mode Int
notenum Int
hash) =
    do [Inline]
pref' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
pref
       [Inline]
suff' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Inline]
suff
       forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
-> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation
Citation Text
id' [Inline]
pref' [Inline]
suff' CitationMode
mode Int
notenum Int
hash

-- | Perform a query on elements nested below a @'Citation'@ element by
-- querying the prefix and postfix @Inline@ lists.
queryCitation :: (Walkable a [Inline], Monoid c)
              => (a -> c) -> Citation -> c
queryCitation :: forall a c.
(Walkable a [Inline], Monoid c) =>
(a -> c) -> Citation -> c
queryCitation a -> c
f (Citation Text
_ [Inline]
pref [Inline]
suff CitationMode
_ Int
_ Int
_) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
pref forall a. Semigroup a => a -> a -> a
<> forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Inline]
suff

-- | Helper method to walk the elements nested below @'Row'@ nodes. The
-- @'Attr'@ component is not changed by this operation.
walkRowM :: (Walkable a Cell, Monad m)
         => (a -> m a) -> Row -> m Row
walkRowM :: forall a (m :: * -> *).
(Walkable a Cell, Monad m) =>
(a -> m a) -> Row -> m Row
walkRowM a -> m a
f (Row Attr
attr [Cell]
bd) = Attr -> [Cell] -> Row
Row Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Cell]
bd

-- | Query the elements below a 'Row' element.
queryRow :: (Walkable a Cell, Monoid c)
         => (a -> c) -> Row -> c
queryRow :: forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c
queryRow a -> c
f (Row Attr
_ [Cell]
bd) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Cell]
bd

-- | Helper method to walk the elements nested below @'TableHead'@ nodes. The
-- @'Attr'@ component is not changed by this operation.
walkTableHeadM :: (Walkable a Row, Monad m)
               => (a -> m a) -> TableHead -> m TableHead
walkTableHeadM :: forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableHead -> m TableHead
walkTableHeadM a -> m a
f (TableHead Attr
attr [Row]
body) = Attr -> [Row] -> TableHead
TableHead Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Row]
body

-- | Query the elements below a 'TableHead' element.
queryTableHead :: (Walkable a Row, Monoid c)
               => (a -> c) -> TableHead -> c
queryTableHead :: forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableHead -> c
queryTableHead a -> c
f (TableHead Attr
_ [Row]
body) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Row]
body

-- | Helper method to walk the elements nested below @'TableBody'@
-- nodes. The @'Attr'@ and @'RowHeadColumns'@ components are not
-- changed by this operation.
walkTableBodyM :: (Walkable a Row, Monad m)
               => (a -> m a) -> TableBody -> m TableBody
walkTableBodyM :: forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableBody -> m TableBody
walkTableBodyM a -> m a
f (TableBody Attr
attr RowHeadColumns
rhc [Row]
hd [Row]
bd) = Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
attr RowHeadColumns
rhc forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Row]
hd forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Row]
bd

-- | Query the elements below a 'TableBody' element.
queryTableBody :: (Walkable a Row, Monoid c)
               => (a -> c) -> TableBody -> c
queryTableBody :: forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableBody -> c
queryTableBody a -> c
f (TableBody Attr
_ RowHeadColumns
_ [Row]
hd [Row]
bd) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Row]
hd forall a. Semigroup a => a -> a -> a
<> forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Row]
bd

-- | Helper method to walk the elements nested below @'TableFoot'@ nodes. The
-- @'Attr'@ component is not changed by this operation.
walkTableFootM :: (Walkable a Row, Monad m)
               => (a -> m a) -> TableFoot -> m TableFoot
walkTableFootM :: forall a (m :: * -> *).
(Walkable a Row, Monad m) =>
(a -> m a) -> TableFoot -> m TableFoot
walkTableFootM a -> m a
f (TableFoot Attr
attr [Row]
body) = Attr -> [Row] -> TableFoot
TableFoot Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Row]
body

-- | Query the elements below a 'TableFoot' element.
queryTableFoot :: (Walkable a Row, Monoid c)
               => (a -> c) -> TableFoot -> c
queryTableFoot :: forall a c.
(Walkable a Row, Monoid c) =>
(a -> c) -> TableFoot -> c
queryTableFoot a -> c
f (TableFoot Attr
_ [Row]
body) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Row]
body

-- | Helper method to walk the elements nested below 'Cell'
-- nodes. Only the @['Block']@ cell content is changed by this
-- operation.
walkCellM :: (Walkable a [Block], Monad m)
          => (a -> m a) -> Cell -> m Cell
walkCellM :: forall a (m :: * -> *).
(Walkable a [Block], Monad m) =>
(a -> m a) -> Cell -> m Cell
walkCellM a -> m a
f (Cell Attr
attr Alignment
ma RowSpan
rs ColSpan
cs [Block]
content) = Attr -> Alignment -> RowSpan -> ColSpan -> [Block] -> Cell
Cell Attr
attr Alignment
ma RowSpan
rs ColSpan
cs forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Block]
content

-- | Query the elements below a 'Cell' element.
queryCell :: (Walkable a [Block], Monoid c)
          => (a -> c) -> Cell -> c
queryCell :: forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c
queryCell a -> c
f (Cell Attr
_ Alignment
_ RowSpan
_ ColSpan
_ [Block]
content) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
content

-- | Helper method to walk the elements nested below 'Caption'
-- nodes.
walkCaptionM :: (Walkable a [Block], Walkable a [Inline], Monad m, Walkable a ShortCaption)
          => (a -> m a) -> Caption -> m Caption
walkCaptionM :: forall a (m :: * -> *).
(Walkable a [Block], Walkable a [Inline], Monad m,
 Walkable a [Inline]) =>
(a -> m a) -> Caption -> m Caption
walkCaptionM a -> m a
f (Caption Maybe [Inline]
mshort [Block]
body) = Maybe [Inline] -> [Block] -> Caption
Caption forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f Maybe [Inline]
mshort forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Block]
body

-- | Query the elements below a 'Cell' element.
queryCaption :: (Walkable a [Block], Walkable a [Inline], Walkable a ShortCaption, Monoid c)
          => (a -> c) -> Caption -> c
queryCaption :: forall a c.
(Walkable a [Block], Walkable a [Inline], Walkable a [Inline],
 Monoid c) =>
(a -> c) -> Caption -> c
queryCaption a -> c
f (Caption Maybe [Inline]
mshort [Block]
body) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f Maybe [Inline]
mshort forall a. Semigroup a => a -> a -> a
<> forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
body

-- | Helper method to walk the components of a Pandoc element.
walkPandocM :: (Walkable a Meta, Walkable a [Block], Monad m,
                  Applicative m, Functor m)
            => (a -> m a) -> Pandoc -> m Pandoc
walkPandocM :: forall a (m :: * -> *).
(Walkable a Meta, Walkable a [Block], Monad m, Applicative m,
 Functor m) =>
(a -> m a) -> Pandoc -> m Pandoc
walkPandocM a -> m a
f (Pandoc Meta
m [Block]
bs) = do Meta
m' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f Meta
m
                                 [Block]
bs' <- forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM a -> m a
f [Block]
bs
                                 forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Meta -> [Block] -> Pandoc
Pandoc Meta
m' [Block]
bs'

-- | Query a pandoc element by recursing first into its @'Meta'@ data
-- and then append the result of recursing into the list of @'Block'@s.
queryPandoc :: (Walkable a Meta, Walkable a [Block], Monoid c)
             => (a -> c) -> Pandoc -> c
queryPandoc :: forall a c.
(Walkable a Meta, Walkable a [Block], Monoid c) =>
(a -> c) -> Pandoc -> c
queryPandoc a -> c
f (Pandoc Meta
m [Block]
bs) = forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f Meta
m forall a. Semigroup a => a -> a -> a
<> forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query a -> c
f [Block]
bs