@@ -13,6 +13,7 @@ module Hakyll.Web.Pandoc
1313 , pandocCompiler
1414 , pandocCompilerWith
1515 , pandocCompilerWithTransform
16+ , pandocCompilerWithTransformM
1617
1718 -- * Default options
1819 , defaultHakyllReaderOptions
@@ -23,6 +24,7 @@ module Hakyll.Web.Pandoc
2324--------------------------------------------------------------------------------
2425import Control.Applicative ((<$>))
2526import qualified Data.Set as S
27+import Data.Traversable (traverse)
2628import Text.Pandoc
2729
2830
@@ -113,6 +115,20 @@ pandocCompilerWithTransform ropt wopt f = cached cacheName $
113115 where
114116 cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
115117
118+--------------------------------------------------------------------------------
119+-- | Similar to 'pandocCompilerWithTransform', but the transformation
120+-- function is monadic. This is useful when you want the pandoc
121+-- tranfromation to use the 'Compiler' information such as routes,
122+-- metadata, etc
123+pandocCompilerWithTransformM :: ReaderOptions -> WriterOptions
124+ -> (Pandoc -> Compiler Pandoc)
125+ -> Compiler (Item String)
126+pandocCompilerWithTransformM ropt wopt f = cached cacheName $
127+ writePandocWith wopt <$>
128+ (traverse f
129+ =<< readPandocWith ropt <$> getResourceBody)
130+ where
131+ cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
116132
117133--------------------------------------------------------------------------------
118134-- | The default reader options for pandoc parsing in hakyll