{-# 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-2019, 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-2019 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 = Identity b -> b forall a. Identity a -> a runIdentity (Identity b -> b) -> (b -> Identity b) -> b -> b forall b c a. (b -> c) -> (a -> b) -> a -> c . (a -> Identity a) -> b -> Identity b forall a b (m :: * -> *). (Walkable a b, Monad m, Applicative m, Functor m) => (a -> m a) -> b -> m b walkM (a -> Identity a forall (m :: * -> *) a. Monad m => a -> m a return (a -> Identity a) -> (a -> a) -> a -> Identity a 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 = (b -> b) -> t b -> t b forall (t :: * -> *) a b. Traversable t => (a -> b) -> t a -> t b T.fmapDefault ((a -> a) -> b -> b forall a b. Walkable a b => (a -> a) -> b -> b walk a -> a f) walkM :: (a -> m a) -> t b -> m (t b) walkM a -> m a f = (b -> m b) -> t b -> m (t b) forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) T.mapM ((a -> m a) -> b -> m 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) query :: (a -> c) -> t b -> c query a -> c f = (b -> c) -> t b -> c forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m F.foldMap ((a -> c) -> b -> c 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) = ((a -> a) -> b -> b forall a b. Walkable a b => (a -> a) -> b -> b walk a -> a f b x, (a -> a) -> c -> c forall a b. Walkable a b => (a -> a) -> b -> b walk a -> a f c y) walkM :: (a -> m a) -> (b, c) -> m (b, c) walkM a -> m a f (b x,c y) = do b x' <- (a -> m a) -> b -> m 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 b x c y' <- (a -> m a) -> c -> m c 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 (b, c) -> m (b, c) forall (m :: * -> *) a. Monad m => a -> m a return (b x',c y') query :: (a -> c) -> (b, c) -> c query a -> c f (b x,c y) = c -> c -> c forall a. Monoid a => a -> a -> a mappend ((a -> c) -> b -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f b x) ((a -> c) -> c -> c 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 :: (Inline -> m Inline) -> Inline -> m Inline walkM Inline -> m Inline f Inline x = (Inline -> m Inline) -> Inline -> m Inline 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 m Inline -> (Inline -> m Inline) -> m Inline forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= Inline -> m Inline f query :: (Inline -> c) -> Inline -> c query Inline -> c f Inline x = Inline -> c f Inline x c -> c -> c forall a. Semigroup a => a -> a -> a <> (Inline -> c) -> Inline -> c 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 :: ([Inline] -> m [Inline]) -> [Inline] -> m [Inline] walkM [Inline] -> m [Inline] f = (Inline -> m Inline) -> [Inline] -> m [Inline] forall (t :: * -> *) (f :: * -> *) a b. (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) T.traverse (([Inline] -> m [Inline]) -> Inline -> m Inline 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] -> m [Inline]) -> ([Inline] -> m [Inline]) -> [Inline] -> m [Inline] forall (m :: * -> *) a b c. Monad m => (a -> m b) -> (b -> m c) -> a -> m c >=> [Inline] -> m [Inline] f query :: ([Inline] -> c) -> [Inline] -> c query [Inline] -> c f [Inline] inlns = [Inline] -> c f [Inline] inlns c -> c -> c forall a. Semigroup a => a -> a -> a <> [c] -> c forall a. Monoid a => [a] -> a mconcat ((Inline -> c) -> [Inline] -> [c] forall a b. (a -> b) -> [a] -> [b] map (([Inline] -> c) -> Inline -> c 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 :: ([Inline] -> m [Inline]) -> Inline -> m Inline walkM = ([Inline] -> m [Inline]) -> Inline -> m Inline 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 :: ([Inline] -> c) -> Inline -> c query = ([Inline] -> c) -> Inline -> c 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 :: (Inline -> m Inline) -> Block -> m Block walkM = (Inline -> m Inline) -> Block -> m Block 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 :: (Inline -> c) -> Block -> c query = (Inline -> c) -> Block -> c 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 :: ([Inline] -> m [Inline]) -> Block -> m Block walkM = ([Inline] -> m [Inline]) -> Block -> m Block 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 :: ([Inline] -> c) -> Block -> c query = ([Inline] -> c) -> Block -> c 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 :: (Block -> m Block) -> Block -> m Block walkM Block -> m Block f Block x = (Block -> m Block) -> Block -> m Block 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 m Block -> (Block -> m Block) -> m Block forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= Block -> m Block f query :: (Block -> c) -> Block -> c query Block -> c f Block x = Block -> c f Block x c -> c -> c forall a. Semigroup a => a -> a -> a <> (Block -> c) -> Block -> c 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 :: ([Block] -> m [Block]) -> Block -> m Block walkM = ([Block] -> m [Block]) -> Block -> m Block 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 :: ([Block] -> c) -> Block -> c query = ([Block] -> c) -> Block -> c 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 :: ([Block] -> m [Block]) -> [Block] -> m [Block] walkM [Block] -> m [Block] f = (Block -> m Block) -> [Block] -> m [Block] forall (t :: * -> *) (f :: * -> *) a b. (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) T.traverse (([Block] -> m [Block]) -> Block -> m Block 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] -> m [Block]) -> ([Block] -> m [Block]) -> [Block] -> m [Block] forall (m :: * -> *) a b c. Monad m => (a -> m b) -> (b -> m c) -> a -> m c >=> [Block] -> m [Block] f query :: ([Block] -> c) -> [Block] -> c query [Block] -> c f [Block] blks = [Block] -> c f [Block] blks c -> c -> c forall a. Semigroup a => a -> a -> a <> [c] -> c forall a. Monoid a => [a] -> a mconcat ((Block -> c) -> [Block] -> [c] forall a b. (a -> b) -> [a] -> [b] map (([Block] -> c) -> Block -> c 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 :: (Block -> m Block) -> Inline -> m Inline walkM = (Block -> m Block) -> Inline -> m Inline 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 :: (Block -> c) -> Inline -> c query = (Block -> c) -> Inline -> c 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 :: ([Block] -> m [Block]) -> Inline -> m Inline walkM = ([Block] -> m [Block]) -> Inline -> m Inline 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 :: ([Block] -> c) -> Inline -> c query = ([Block] -> c) -> Inline -> c 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 :: (Block -> m Block) -> Pandoc -> m Pandoc walkM = (Block -> m Block) -> Pandoc -> m Pandoc forall a (m :: * -> *). (Walkable a Meta, Walkable a [Block], Monad m, Applicative m, Functor m) => (a -> m a) -> Pandoc -> m Pandoc walkPandocM query :: (Block -> c) -> Pandoc -> c query = (Block -> c) -> Pandoc -> c forall a c. (Walkable a Meta, Walkable a [Block], Monoid c) => (a -> c) -> Pandoc -> c queryPandoc instance Walkable [Block] Pandoc where walkM :: ([Block] -> m [Block]) -> Pandoc -> m Pandoc walkM = ([Block] -> m [Block]) -> Pandoc -> m Pandoc forall a (m :: * -> *). (Walkable a Meta, Walkable a [Block], Monad m, Applicative m, Functor m) => (a -> m a) -> Pandoc -> m Pandoc walkPandocM query :: ([Block] -> c) -> Pandoc -> c query = ([Block] -> c) -> Pandoc -> c forall a c. (Walkable a Meta, Walkable a [Block], Monoid c) => (a -> c) -> Pandoc -> c queryPandoc instance Walkable Inline Pandoc where walkM :: (Inline -> m Inline) -> Pandoc -> m Pandoc walkM = (Inline -> m Inline) -> Pandoc -> m Pandoc forall a (m :: * -> *). (Walkable a Meta, Walkable a [Block], Monad m, Applicative m, Functor m) => (a -> m a) -> Pandoc -> m Pandoc walkPandocM query :: (Inline -> c) -> Pandoc -> c query = (Inline -> c) -> Pandoc -> c forall a c. (Walkable a Meta, Walkable a [Block], Monoid c) => (a -> c) -> Pandoc -> c queryPandoc instance Walkable [Inline] Pandoc where walkM :: ([Inline] -> m [Inline]) -> Pandoc -> m Pandoc walkM = ([Inline] -> m [Inline]) -> Pandoc -> m Pandoc forall a (m :: * -> *). (Walkable a Meta, Walkable a [Block], Monad m, Applicative m, Functor m) => (a -> m a) -> Pandoc -> m Pandoc walkPandocM query :: ([Inline] -> c) -> Pandoc -> c query = ([Inline] -> c) -> Pandoc -> c forall a c. (Walkable a Meta, Walkable a [Block], Monoid c) => (a -> c) -> Pandoc -> c queryPandoc instance Walkable Meta Pandoc where walkM :: (Meta -> m Meta) -> Pandoc -> m Pandoc walkM Meta -> m Meta f (Pandoc Meta m [Block] bs) = Meta -> [Block] -> Pandoc Pandoc (Meta -> [Block] -> Pandoc) -> m Meta -> m ([Block] -> Pandoc) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Meta -> m Meta f Meta m m ([Block] -> Pandoc) -> m [Block] -> m Pandoc forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> [Block] -> m [Block] forall (f :: * -> *) a. Applicative f => a -> f a pure [Block] bs query :: (Meta -> c) -> Pandoc -> c query Meta -> c f (Pandoc Meta m [Block] _) = Meta -> c f Meta m instance Walkable MetaValue Pandoc where walkM :: (MetaValue -> m MetaValue) -> Pandoc -> m Pandoc walkM MetaValue -> m MetaValue f (Pandoc Meta m [Block] bs) = Meta -> [Block] -> Pandoc Pandoc (Meta -> [Block] -> Pandoc) -> m Meta -> m ([Block] -> Pandoc) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (MetaValue -> m MetaValue) -> Meta -> m Meta 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 m ([Block] -> Pandoc) -> m [Block] -> m Pandoc forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> [Block] -> m [Block] forall (f :: * -> *) a. Applicative f => a -> f a pure [Block] bs query :: (MetaValue -> c) -> Pandoc -> c query MetaValue -> c f (Pandoc Meta m [Block] _) = (MetaValue -> c) -> Meta -> c 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 :: (Pandoc -> m Pandoc) -> Pandoc -> m Pandoc walkM Pandoc -> m Pandoc f = Pandoc -> m Pandoc f query :: (Pandoc -> c) -> Pandoc -> c query Pandoc -> c f = Pandoc -> c f -- -- Walk Meta -- instance Walkable Meta Meta where walkM :: (Meta -> m Meta) -> Meta -> m Meta walkM Meta -> m Meta f = Meta -> m Meta f query :: (Meta -> c) -> Meta -> c query Meta -> c f = Meta -> c f instance Walkable Inline Meta where walkM :: (Inline -> m Inline) -> Meta -> m Meta walkM Inline -> m Inline f (Meta Map Text MetaValue metamap) = Map Text MetaValue -> Meta Meta (Map Text MetaValue -> Meta) -> m (Map Text MetaValue) -> m Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Inline -> m Inline) -> Map Text MetaValue -> m (Map Text MetaValue) 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 :: (Inline -> c) -> Meta -> c query Inline -> c f (Meta Map Text MetaValue metamap) = (Inline -> c) -> Map Text MetaValue -> c 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 :: ([Inline] -> m [Inline]) -> Meta -> m Meta walkM [Inline] -> m [Inline] f (Meta Map Text MetaValue metamap) = Map Text MetaValue -> Meta Meta (Map Text MetaValue -> Meta) -> m (Map Text MetaValue) -> m Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ([Inline] -> m [Inline]) -> Map Text MetaValue -> m (Map Text MetaValue) 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 :: ([Inline] -> c) -> Meta -> c query [Inline] -> c f (Meta Map Text MetaValue metamap) = ([Inline] -> c) -> Map Text MetaValue -> c 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 :: (Block -> m Block) -> Meta -> m Meta walkM Block -> m Block f (Meta Map Text MetaValue metamap) = Map Text MetaValue -> Meta Meta (Map Text MetaValue -> Meta) -> m (Map Text MetaValue) -> m Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Block -> m Block) -> Map Text MetaValue -> m (Map Text MetaValue) 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 :: (Block -> c) -> Meta -> c query Block -> c f (Meta Map Text MetaValue metamap) = (Block -> c) -> Map Text MetaValue -> c 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 :: ([Block] -> m [Block]) -> Meta -> m Meta walkM [Block] -> m [Block] f (Meta Map Text MetaValue metamap) = Map Text MetaValue -> Meta Meta (Map Text MetaValue -> Meta) -> m (Map Text MetaValue) -> m Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ([Block] -> m [Block]) -> Map Text MetaValue -> m (Map Text MetaValue) 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 :: ([Block] -> c) -> Meta -> c query [Block] -> c f (Meta Map Text MetaValue metamap) = ([Block] -> c) -> Map Text MetaValue -> c 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 :: (MetaValue -> m MetaValue) -> Meta -> m Meta walkM MetaValue -> m MetaValue f (Meta Map Text MetaValue metamap) = Map Text MetaValue -> Meta Meta (Map Text MetaValue -> Meta) -> ([(Text, MetaValue)] -> Map Text MetaValue) -> [(Text, MetaValue)] -> Meta forall b c a. (b -> c) -> (a -> b) -> a -> c . [(Text, MetaValue)] -> Map Text MetaValue forall k a. Eq k => [(k, a)] -> Map k a M.fromAscList ([(Text, MetaValue)] -> Meta) -> m [(Text, MetaValue)] -> m Meta forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ((Text, MetaValue) -> m (Text, MetaValue)) -> [(Text, MetaValue)] -> m [(Text, MetaValue)] forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) mapM (\(Text k, MetaValue v) -> (,) Text k (MetaValue -> (Text, MetaValue)) -> m MetaValue -> m (Text, MetaValue) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (MetaValue -> m MetaValue) -> MetaValue -> m MetaValue 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) (Map Text MetaValue -> [(Text, MetaValue)] forall k a. Map k a -> [(k, a)] M.toAscList Map Text MetaValue metamap) query :: (MetaValue -> c) -> Meta -> c query MetaValue -> c f (Meta Map Text MetaValue metamap) = (Text -> MetaValue -> c) -> Map Text MetaValue -> c forall m k a. Monoid m => (k -> a -> m) -> Map k a -> m M.foldMapWithKey ((MetaValue -> c) -> Text -> MetaValue -> c forall a b. a -> b -> a const ((MetaValue -> c) -> Text -> MetaValue -> c) -> (MetaValue -> c) -> Text -> MetaValue -> c forall a b. (a -> b) -> a -> b $ (MetaValue -> c) -> MetaValue -> c 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 :: (MetaValue -> m MetaValue) -> MetaValue -> m MetaValue walkM MetaValue -> m MetaValue f MetaValue x = (MetaValue -> m MetaValue) -> MetaValue -> m MetaValue forall (m :: * -> *). (Monad m, Applicative m, Functor m) => (MetaValue -> m MetaValue) -> MetaValue -> m MetaValue walkMetaValueM' MetaValue -> m MetaValue f MetaValue x m MetaValue -> (MetaValue -> m MetaValue) -> m MetaValue forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= MetaValue -> m MetaValue f query :: (MetaValue -> c) -> MetaValue -> c query MetaValue -> c f MetaValue x = MetaValue -> c f MetaValue x c -> c -> c forall a. Semigroup a => a -> a -> a <> (MetaValue -> c) -> MetaValue -> c forall c. Monoid c => (MetaValue -> c) -> MetaValue -> c queryMetaValue' MetaValue -> c f MetaValue x instance Walkable Inline MetaValue where walkM :: (Inline -> m Inline) -> MetaValue -> m MetaValue walkM = (Inline -> m Inline) -> MetaValue -> m MetaValue 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 :: (Inline -> c) -> MetaValue -> c query = (Inline -> c) -> MetaValue -> c 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 :: ([Inline] -> m [Inline]) -> MetaValue -> m MetaValue walkM = ([Inline] -> m [Inline]) -> MetaValue -> m MetaValue 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 :: ([Inline] -> c) -> MetaValue -> c query = ([Inline] -> c) -> MetaValue -> c 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 :: (Block -> m Block) -> MetaValue -> m MetaValue walkM = (Block -> m Block) -> MetaValue -> m MetaValue 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 :: (Block -> c) -> MetaValue -> c query = (Block -> c) -> MetaValue -> c 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 :: ([Block] -> m [Block]) -> MetaValue -> m MetaValue walkM = ([Block] -> m [Block]) -> MetaValue -> m MetaValue 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 :: ([Block] -> c) -> MetaValue -> c query = ([Block] -> c) -> MetaValue -> c 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 :: (Inline -> m Inline) -> Row -> m Row walkM = (Inline -> m Inline) -> Row -> m Row forall a (m :: * -> *). (Walkable a Cell, Monad m) => (a -> m a) -> Row -> m Row walkRowM query :: (Inline -> c) -> Row -> c query = (Inline -> c) -> Row -> c forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c queryRow instance Walkable [Inline] Row where walkM :: ([Inline] -> m [Inline]) -> Row -> m Row walkM = ([Inline] -> m [Inline]) -> Row -> m Row forall a (m :: * -> *). (Walkable a Cell, Monad m) => (a -> m a) -> Row -> m Row walkRowM query :: ([Inline] -> c) -> Row -> c query = ([Inline] -> c) -> Row -> c forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c queryRow instance Walkable Block Row where walkM :: (Block -> m Block) -> Row -> m Row walkM = (Block -> m Block) -> Row -> m Row forall a (m :: * -> *). (Walkable a Cell, Monad m) => (a -> m a) -> Row -> m Row walkRowM query :: (Block -> c) -> Row -> c query = (Block -> c) -> Row -> c forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c queryRow instance Walkable [Block] Row where walkM :: ([Block] -> m [Block]) -> Row -> m Row walkM = ([Block] -> m [Block]) -> Row -> m Row forall a (m :: * -> *). (Walkable a Cell, Monad m) => (a -> m a) -> Row -> m Row walkRowM query :: ([Block] -> c) -> Row -> c query = ([Block] -> c) -> Row -> c forall a c. (Walkable a Cell, Monoid c) => (a -> c) -> Row -> c queryRow -- -- Walk TableHead -- instance Walkable Inline TableHead where walkM :: (Inline -> m Inline) -> TableHead -> m TableHead walkM = (Inline -> m Inline) -> TableHead -> m TableHead forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableHead -> m TableHead walkTableHeadM query :: (Inline -> c) -> TableHead -> c query = (Inline -> c) -> TableHead -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableHead -> c queryTableHead instance Walkable [Inline] TableHead where walkM :: ([Inline] -> m [Inline]) -> TableHead -> m TableHead walkM = ([Inline] -> m [Inline]) -> TableHead -> m TableHead forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableHead -> m TableHead walkTableHeadM query :: ([Inline] -> c) -> TableHead -> c query = ([Inline] -> c) -> TableHead -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableHead -> c queryTableHead instance Walkable Block TableHead where walkM :: (Block -> m Block) -> TableHead -> m TableHead walkM = (Block -> m Block) -> TableHead -> m TableHead forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableHead -> m TableHead walkTableHeadM query :: (Block -> c) -> TableHead -> c query = (Block -> c) -> TableHead -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableHead -> c queryTableHead instance Walkable [Block] TableHead where walkM :: ([Block] -> m [Block]) -> TableHead -> m TableHead walkM = ([Block] -> m [Block]) -> TableHead -> m TableHead forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableHead -> m TableHead walkTableHeadM query :: ([Block] -> c) -> TableHead -> c query = ([Block] -> c) -> TableHead -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableHead -> c queryTableHead -- -- Walk TableBody -- instance Walkable Inline TableBody where walkM :: (Inline -> m Inline) -> TableBody -> m TableBody walkM = (Inline -> m Inline) -> TableBody -> m TableBody forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableBody -> m TableBody walkTableBodyM query :: (Inline -> c) -> TableBody -> c query = (Inline -> c) -> TableBody -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableBody -> c queryTableBody instance Walkable [Inline] TableBody where walkM :: ([Inline] -> m [Inline]) -> TableBody -> m TableBody walkM = ([Inline] -> m [Inline]) -> TableBody -> m TableBody forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableBody -> m TableBody walkTableBodyM query :: ([Inline] -> c) -> TableBody -> c query = ([Inline] -> c) -> TableBody -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableBody -> c queryTableBody instance Walkable Block TableBody where walkM :: (Block -> m Block) -> TableBody -> m TableBody walkM = (Block -> m Block) -> TableBody -> m TableBody forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableBody -> m TableBody walkTableBodyM query :: (Block -> c) -> TableBody -> c query = (Block -> c) -> TableBody -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableBody -> c queryTableBody instance Walkable [Block] TableBody where walkM :: ([Block] -> m [Block]) -> TableBody -> m TableBody walkM = ([Block] -> m [Block]) -> TableBody -> m TableBody forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableBody -> m TableBody walkTableBodyM query :: ([Block] -> c) -> TableBody -> c query = ([Block] -> c) -> TableBody -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableBody -> c queryTableBody -- -- Walk TableFoot -- instance Walkable Inline TableFoot where walkM :: (Inline -> m Inline) -> TableFoot -> m TableFoot walkM = (Inline -> m Inline) -> TableFoot -> m TableFoot forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableFoot -> m TableFoot walkTableFootM query :: (Inline -> c) -> TableFoot -> c query = (Inline -> c) -> TableFoot -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableFoot -> c queryTableFoot instance Walkable [Inline] TableFoot where walkM :: ([Inline] -> m [Inline]) -> TableFoot -> m TableFoot walkM = ([Inline] -> m [Inline]) -> TableFoot -> m TableFoot forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableFoot -> m TableFoot walkTableFootM query :: ([Inline] -> c) -> TableFoot -> c query = ([Inline] -> c) -> TableFoot -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableFoot -> c queryTableFoot instance Walkable Block TableFoot where walkM :: (Block -> m Block) -> TableFoot -> m TableFoot walkM = (Block -> m Block) -> TableFoot -> m TableFoot forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableFoot -> m TableFoot walkTableFootM query :: (Block -> c) -> TableFoot -> c query = (Block -> c) -> TableFoot -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableFoot -> c queryTableFoot instance Walkable [Block] TableFoot where walkM :: ([Block] -> m [Block]) -> TableFoot -> m TableFoot walkM = ([Block] -> m [Block]) -> TableFoot -> m TableFoot forall a (m :: * -> *). (Walkable a Row, Monad m) => (a -> m a) -> TableFoot -> m TableFoot walkTableFootM query :: ([Block] -> c) -> TableFoot -> c query = ([Block] -> c) -> TableFoot -> c forall a c. (Walkable a Row, Monoid c) => (a -> c) -> TableFoot -> c queryTableFoot -- -- Walk Caption -- instance Walkable Inline Caption where walkM :: (Inline -> m Inline) -> Caption -> m Caption walkM = (Inline -> m Inline) -> Caption -> m Caption forall a (m :: * -> *). (Walkable a [Block], Walkable a [Inline], Monad m, Walkable a [Inline]) => (a -> m a) -> Caption -> m Caption walkCaptionM query :: (Inline -> c) -> Caption -> c query = (Inline -> c) -> Caption -> c 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 :: ([Inline] -> m [Inline]) -> Caption -> m Caption walkM = ([Inline] -> m [Inline]) -> Caption -> m Caption forall a (m :: * -> *). (Walkable a [Block], Walkable a [Inline], Monad m, Walkable a [Inline]) => (a -> m a) -> Caption -> m Caption walkCaptionM query :: ([Inline] -> c) -> Caption -> c query = ([Inline] -> c) -> Caption -> c 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 :: (Block -> m Block) -> Caption -> m Caption walkM = (Block -> m Block) -> Caption -> m Caption forall a (m :: * -> *). (Walkable a [Block], Walkable a [Inline], Monad m, Walkable a [Inline]) => (a -> m a) -> Caption -> m Caption walkCaptionM query :: (Block -> c) -> Caption -> c query = (Block -> c) -> Caption -> c 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 :: ([Block] -> m [Block]) -> Caption -> m Caption walkM = ([Block] -> m [Block]) -> Caption -> m Caption forall a (m :: * -> *). (Walkable a [Block], Walkable a [Inline], Monad m, Walkable a [Inline]) => (a -> m a) -> Caption -> m Caption walkCaptionM query :: ([Block] -> c) -> Caption -> c query = ([Block] -> c) -> Caption -> c 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 :: (Inline -> m Inline) -> Cell -> m Cell walkM = (Inline -> m Inline) -> Cell -> m Cell forall a (m :: * -> *). (Walkable a [Block], Monad m) => (a -> m a) -> Cell -> m Cell walkCellM query :: (Inline -> c) -> Cell -> c query = (Inline -> c) -> Cell -> c forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c queryCell instance Walkable [Inline] Cell where walkM :: ([Inline] -> m [Inline]) -> Cell -> m Cell walkM = ([Inline] -> m [Inline]) -> Cell -> m Cell forall a (m :: * -> *). (Walkable a [Block], Monad m) => (a -> m a) -> Cell -> m Cell walkCellM query :: ([Inline] -> c) -> Cell -> c query = ([Inline] -> c) -> Cell -> c forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c queryCell instance Walkable Block Cell where walkM :: (Block -> m Block) -> Cell -> m Cell walkM = (Block -> m Block) -> Cell -> m Cell forall a (m :: * -> *). (Walkable a [Block], Monad m) => (a -> m a) -> Cell -> m Cell walkCellM query :: (Block -> c) -> Cell -> c query = (Block -> c) -> Cell -> c forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c queryCell instance Walkable [Block] Cell where walkM :: ([Block] -> m [Block]) -> Cell -> m Cell walkM = ([Block] -> m [Block]) -> Cell -> m Cell forall a (m :: * -> *). (Walkable a [Block], Monad m) => (a -> m a) -> Cell -> m Cell walkCellM query :: ([Block] -> c) -> Cell -> c query = ([Block] -> c) -> Cell -> c forall a c. (Walkable a [Block], Monoid c) => (a -> c) -> Cell -> c queryCell -- -- Walk Citation -- instance Walkable Inline Citation where walkM :: (Inline -> m Inline) -> Citation -> m Citation walkM = (Inline -> m Inline) -> Citation -> m Citation forall a (m :: * -> *). (Walkable a [Inline], Monad m, Applicative m, Functor m) => (a -> m a) -> Citation -> m Citation walkCitationM query :: (Inline -> c) -> Citation -> c query = (Inline -> c) -> Citation -> c forall a c. (Walkable a [Inline], Monoid c) => (a -> c) -> Citation -> c queryCitation instance Walkable [Inline] Citation where walkM :: ([Inline] -> m [Inline]) -> Citation -> m Citation walkM = ([Inline] -> m [Inline]) -> Citation -> m Citation forall a (m :: * -> *). (Walkable a [Inline], Monad m, Applicative m, Functor m) => (a -> m a) -> Citation -> m Citation walkCitationM query :: ([Inline] -> c) -> Citation -> c query = ([Inline] -> c) -> Citation -> c forall a c. (Walkable a [Inline], Monoid c) => (a -> c) -> Citation -> c queryCitation instance Walkable Block Citation where walkM :: (Block -> m Block) -> Citation -> m Citation walkM = (Block -> m Block) -> Citation -> m Citation forall a (m :: * -> *). (Walkable a [Inline], Monad m, Applicative m, Functor m) => (a -> m a) -> Citation -> m Citation walkCitationM query :: (Block -> c) -> Citation -> c query = (Block -> c) -> Citation -> c forall a c. (Walkable a [Inline], Monoid c) => (a -> c) -> Citation -> c queryCitation instance Walkable [Block] Citation where walkM :: ([Block] -> m [Block]) -> Citation -> m Citation walkM = ([Block] -> m [Block]) -> Citation -> m Citation forall a (m :: * -> *). (Walkable a [Inline], Monad m, Applicative m, Functor m) => (a -> m a) -> Citation -> m Citation walkCitationM query :: ([Block] -> c) -> Citation -> c query = ([Block] -> c) -> Citation -> c 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 :: (a -> m a) -> Inline -> m Inline walkInlineM a -> m a _ (Str Text xs) = Inline -> m Inline 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Target -> Inline) -> m [Inline] -> m (Target -> Inline) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 m (Target -> Inline) -> m Target -> m Inline forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Target -> m Target 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 ([Inline] -> Target -> Inline) -> m [Inline] -> m (Target -> Inline) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 m (Target -> Inline) -> m Target -> m Inline forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Target -> m Target forall (f :: * -> *) a. Applicative f => a -> f a pure Target t walkInlineM a -> m a f (Note [Block] bs) = [Block] -> Inline Note ([Block] -> Inline) -> m [Block] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Block] -> m [Block] 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 ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Citation] -> [Inline] -> Inline) -> m [Citation] -> m ([Inline] -> Inline) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Citation] -> m [Citation] 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 m ([Inline] -> Inline) -> m [Inline] -> m Inline forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> (a -> m a) -> [Inline] -> m [Inline] 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 = Inline -> m Inline forall (m :: * -> *) a. Monad m => a -> m a return Inline LineBreak walkInlineM a -> m a _ Inline SoftBreak = Inline -> m Inline forall (m :: * -> *) a. Monad m => a -> m a return Inline SoftBreak walkInlineM a -> m a _ Inline Space = Inline -> m Inline forall (m :: * -> *) a. Monad m => a -> m a return Inline Space walkInlineM a -> m a _ x :: Inline x@Code {} = Inline -> m Inline forall (m :: * -> *) a. Monad m => a -> m a return Inline x walkInlineM a -> m a _ x :: Inline x@Math {} = Inline -> m Inline forall (m :: * -> *) a. Monad m => a -> m a return Inline x walkInlineM a -> m a _ x :: Inline x@RawInline {} = Inline -> m Inline 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 :: (a -> c) -> Inline -> c queryInline a -> c _ (Str Text _) = c forall a. Monoid a => a mempty queryInline a -> c f (Emph [Inline] xs) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Inline] -> c 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)= (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Citation] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [Citation] cs c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> [Inline] -> c 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 _) = c forall a. Monoid a => a mempty queryInline a -> c _ Inline Space = c forall a. Monoid a => a mempty queryInline a -> c _ Inline SoftBreak = c forall a. Monoid a => a mempty queryInline a -> c _ Inline LineBreak = c forall a. Monoid a => a mempty queryInline a -> c _ (Math MathType _ Text _) = c forall a. Monoid a => a mempty queryInline a -> c _ (RawInline Format _ Text _) = c forall a. Monoid a => a mempty queryInline a -> c f (Link Attr _ [Inline] xs Target _) = (a -> c) -> [Inline] -> c 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 _) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Block] -> c 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) = (a -> c) -> [Inline] -> c 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 :: (a -> m a) -> Block -> m Block walkBlockM a -> m a f (Para [Inline] xs) = [Inline] -> Block Para ([Inline] -> Block) -> m [Inline] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Inline] -> Block) -> m [Inline] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([[Inline]] -> Block) -> m [[Inline]] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [[Inline]] -> m [[Inline]] 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 ([Block] -> Block) -> m [Block] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Block] -> m [Block] 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 ([[Block]] -> Block) -> m [[Block]] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [[Block]] -> m [[Block]] 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 ([[Block]] -> Block) -> m [[Block]] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [[Block]] -> m [[Block]] 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 ([([Inline], [[Block]])] -> Block) -> m [([Inline], [[Block]])] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [([Inline], [[Block]])] -> m [([Inline], [[Block]])] 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 ([Inline] -> Block) -> m [Inline] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Inline] -> m [Inline] 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 ([Block] -> Block) -> m [Block] -> m Block forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Block] -> m [Block] 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 {} = Block -> m Block forall (m :: * -> *) a. Monad m => a -> m a return Block x walkBlockM a -> m a _ x :: Block x@RawBlock {} = Block -> m Block forall (m :: * -> *) a. Monad m => a -> m a return Block x walkBlockM a -> m a _ Block HorizontalRule = Block -> m Block forall (m :: * -> *) a. Monad m => a -> m a return Block HorizontalRule walkBlockM a -> m a _ Block Null = Block -> m Block forall (m :: * -> *) a. Monad m => a -> m a return Block Null walkBlockM a -> m a f (Table Attr attr Caption capt [ColSpec] as TableHead hs [TableBody] bs TableFoot fs) = do Caption capt' <- (a -> m a) -> Caption -> m Caption 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' <- (a -> m a) -> TableHead -> m TableHead 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' <- (a -> m a) -> [TableBody] -> m [TableBody] 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' <- (a -> m a) -> TableFoot -> m TableFoot 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 Block -> m Block forall (m :: * -> *) a. Monad m => a -> m a return (Block -> m Block) -> Block -> m Block 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' -- | 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 :: (a -> c) -> Block -> c queryBlock a -> c f (Para [Inline] xs) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [[Inline]] -> c 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 _) = c forall a. Monoid a => a mempty queryBlock a -> c _ (RawBlock Format _ Text _) = c forall a. Monoid a => a mempty queryBlock a -> c f (BlockQuote [Block] bs) = (a -> c) -> [Block] -> c 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) = (a -> c) -> [[Block]] -> c 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) = (a -> c) -> [[Block]] -> c 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) = (a -> c) -> [([Inline], [[Block]])] -> c 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) = (a -> c) -> [Inline] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [Inline] xs queryBlock a -> c _ Block HorizontalRule = c forall a. Monoid a => a mempty queryBlock a -> c f (Table Attr _ Caption capt [ColSpec] _ TableHead hs [TableBody] bs TableFoot fs) = (a -> c) -> Caption -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f Caption capt c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> TableHead -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f TableHead hs c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> [TableBody] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [TableBody] bs c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> TableFoot -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f TableFoot fs queryBlock a -> c f (Div Attr _ [Block] bs) = (a -> c) -> [Block] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [Block] bs queryBlock a -> c _ Block Null = c forall a. Monoid a => a mempty -- | 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 :: (a -> f a) -> MetaValue -> f MetaValue walkMetaValueM a -> f a f (MetaList [MetaValue] xs) = [MetaValue] -> MetaValue MetaList ([MetaValue] -> MetaValue) -> f [MetaValue] -> f MetaValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> f a) -> [MetaValue] -> f [MetaValue] 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) = MetaValue -> f MetaValue forall (m :: * -> *) a. Monad m => a -> m a return (MetaValue -> f MetaValue) -> MetaValue -> f MetaValue forall a b. (a -> b) -> a -> b $ Bool -> MetaValue MetaBool Bool b walkMetaValueM a -> f a _ (MetaString Text s) = MetaValue -> f MetaValue forall (m :: * -> *) a. Monad m => a -> m a return (MetaValue -> f MetaValue) -> MetaValue -> f MetaValue forall a b. (a -> b) -> a -> b $ Text -> MetaValue MetaString Text s walkMetaValueM a -> f a f (MetaInlines [Inline] xs) = [Inline] -> MetaValue MetaInlines ([Inline] -> MetaValue) -> f [Inline] -> f MetaValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> f a) -> [Inline] -> f [Inline] 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 ([Block] -> MetaValue) -> f [Block] -> f MetaValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> f a) -> [Block] -> f [Block] 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 (Map Text MetaValue -> MetaValue) -> f (Map Text MetaValue) -> f MetaValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> f a) -> Map Text MetaValue -> f (Map Text MetaValue) 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' :: (MetaValue -> f MetaValue) -> MetaValue -> f MetaValue walkMetaValueM' MetaValue -> f MetaValue f (MetaMap Map Text MetaValue m) = Map Text MetaValue -> MetaValue MetaMap (Map Text MetaValue -> MetaValue) -> ([(Text, MetaValue)] -> Map Text MetaValue) -> [(Text, MetaValue)] -> MetaValue forall b c a. (b -> c) -> (a -> b) -> a -> c . [(Text, MetaValue)] -> Map Text MetaValue forall k a. Eq k => [(k, a)] -> Map k a M.fromAscList ([(Text, MetaValue)] -> MetaValue) -> f [(Text, MetaValue)] -> f MetaValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ((Text, MetaValue) -> f (Text, MetaValue)) -> [(Text, MetaValue)] -> f [(Text, MetaValue)] forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) mapM (\(Text k, MetaValue v) -> (,) Text k (MetaValue -> (Text, MetaValue)) -> f MetaValue -> f (Text, MetaValue) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (MetaValue -> f MetaValue) -> MetaValue -> f MetaValue 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) (Map Text MetaValue -> [(Text, MetaValue)] 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 ([MetaValue] -> MetaValue) -> f [MetaValue] -> f MetaValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (MetaValue -> f MetaValue) -> [MetaValue] -> f [MetaValue] forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) mapM ((MetaValue -> f MetaValue) -> MetaValue -> f MetaValue 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 = MetaValue -> f MetaValue 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 :: (a -> c) -> MetaValue -> c queryMetaValue a -> c f (MetaList [MetaValue] xs) = (a -> c) -> [MetaValue] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [MetaValue] xs queryMetaValue a -> c _ (MetaBool Bool _) = c forall a. Monoid a => a mempty queryMetaValue a -> c _ (MetaString Text _) = c forall a. Monoid a => a mempty queryMetaValue a -> c f (MetaInlines [Inline] xs) = (a -> c) -> [Inline] -> c 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) = (a -> c) -> [Block] -> c 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) = (a -> c) -> Map Text MetaValue -> c 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' :: (MetaValue -> c) -> MetaValue -> c queryMetaValue' MetaValue -> c f (MetaMap Map Text MetaValue m) = (Text -> MetaValue -> c) -> Map Text MetaValue -> c forall m k a. Monoid m => (k -> a -> m) -> Map k a -> m M.foldMapWithKey ((MetaValue -> c) -> Text -> MetaValue -> c forall a b. a -> b -> a const ((MetaValue -> c) -> Text -> MetaValue -> c) -> (MetaValue -> c) -> Text -> MetaValue -> c forall a b. (a -> b) -> a -> b $ (MetaValue -> c) -> MetaValue -> c 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) = [c] -> c forall a. Monoid a => [a] -> a mconcat ([c] -> c) -> [c] -> c forall a b. (a -> b) -> a -> b $ (MetaValue -> c) -> [MetaValue] -> [c] forall a b. (a -> b) -> [a] -> [b] map ((MetaValue -> c) -> MetaValue -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query MetaValue -> c f) [MetaValue] xs queryMetaValue' MetaValue -> c _ MetaValue _ = c 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 :: (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' <- (a -> m a) -> [Inline] -> m [Inline] 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' <- (a -> m a) -> [Inline] -> m [Inline] 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 Citation -> m Citation forall (m :: * -> *) a. Monad m => a -> m a return (Citation -> m Citation) -> Citation -> m Citation 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 :: (a -> c) -> Citation -> c queryCitation a -> c f (Citation Text _ [Inline] pref [Inline] suff CitationMode _ Int _ Int _) = (a -> c) -> [Inline] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [Inline] pref c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> [Inline] -> c 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 :: (a -> m a) -> Row -> m Row walkRowM a -> m a f (Row Attr attr [Cell] bd) = Attr -> [Cell] -> Row Row Attr attr ([Cell] -> Row) -> m [Cell] -> m Row forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Cell] -> m [Cell] 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 :: (a -> c) -> Row -> c queryRow a -> c f (Row Attr _ [Cell] bd) = (a -> c) -> [Cell] -> c 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 :: (a -> m a) -> TableHead -> m TableHead walkTableHeadM a -> m a f (TableHead Attr attr [Row] body) = Attr -> [Row] -> TableHead TableHead Attr attr ([Row] -> TableHead) -> m [Row] -> m TableHead forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Row] -> m [Row] 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 :: (a -> c) -> TableHead -> c queryTableHead a -> c f (TableHead Attr _ [Row] body) = (a -> c) -> [Row] -> c 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 :: (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 ([Row] -> [Row] -> TableBody) -> m [Row] -> m ([Row] -> TableBody) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Row] -> m [Row] 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 m ([Row] -> TableBody) -> m [Row] -> m TableBody forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> (a -> m a) -> [Row] -> m [Row] 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 :: (a -> c) -> TableBody -> c queryTableBody a -> c f (TableBody Attr _ RowHeadColumns _ [Row] hd [Row] bd) = (a -> c) -> [Row] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [Row] hd c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> [Row] -> c 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 :: (a -> m a) -> TableFoot -> m TableFoot walkTableFootM a -> m a f (TableFoot Attr attr [Row] body) = Attr -> [Row] -> TableFoot TableFoot Attr attr ([Row] -> TableFoot) -> m [Row] -> m TableFoot forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Row] -> m [Row] 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 :: (a -> c) -> TableFoot -> c queryTableFoot a -> c f (TableFoot Attr _ [Row] body) = (a -> c) -> [Row] -> c 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 :: (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 ([Block] -> Cell) -> m [Block] -> m Cell forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> [Block] -> m [Block] 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 :: (a -> c) -> Cell -> c queryCell a -> c f (Cell Attr _ Alignment _ RowSpan _ ColSpan _ [Block] content) = (a -> c) -> [Block] -> c 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 :: (a -> m a) -> Caption -> m Caption walkCaptionM a -> m a f (Caption Maybe [Inline] mshort [Block] body) = Maybe [Inline] -> [Block] -> Caption Caption (Maybe [Inline] -> [Block] -> Caption) -> m (Maybe [Inline]) -> m ([Block] -> Caption) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (a -> m a) -> Maybe [Inline] -> m (Maybe [Inline]) 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 m ([Block] -> Caption) -> m [Block] -> m Caption forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> (a -> m a) -> [Block] -> m [Block] 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 :: (a -> c) -> Caption -> c queryCaption a -> c f (Caption Maybe [Inline] mshort [Block] body) = (a -> c) -> Maybe [Inline] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f Maybe [Inline] mshort c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> [Block] -> c 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 :: (a -> m a) -> Pandoc -> m Pandoc walkPandocM a -> m a f (Pandoc Meta m [Block] bs) = do Meta m' <- (a -> m a) -> Meta -> m Meta 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' <- (a -> m a) -> [Block] -> m [Block] 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 Pandoc -> m Pandoc forall (m :: * -> *) a. Monad m => a -> m a return (Pandoc -> m Pandoc) -> Pandoc -> m Pandoc 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 :: (a -> c) -> Pandoc -> c queryPandoc a -> c f (Pandoc Meta m [Block] bs) = (a -> c) -> Meta -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f Meta m c -> c -> c forall a. Semigroup a => a -> a -> a <> (a -> c) -> [Block] -> c forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c query a -> c f [Block] bs