on master help sign in
Added the `pandocCompilerWithTransformM` function
8a29542Daniil Frumin
src/Hakyll/Web/Pandoc.hs+16
@@ -13,6 +13,7 @@ module Hakyll.Web.Pandoc
13 , pandocCompiler
13 , pandocCompiler
14 , pandocCompilerWith
14 , pandocCompilerWith
15 , pandocCompilerWithTransform
15 , pandocCompilerWithTransform
16+ , pandocCompilerWithTransformM
16
17
17 -- * Default options
18 -- * Default options
18 , defaultHakyllReaderOptions
19 , defaultHakyllReaderOptions
@@ -23,6 +24,7 @@ module Hakyll.Web.Pandoc
23--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
24import Control.Applicative ((<$>))
25import Control.Applicative ((<$>))
25import qualified Data.Set as S
26import qualified Data.Set as S
27+import Data.Traversable (traverse)
26import Text.Pandoc
28import Text.Pandoc
27
29
28
30
@@ -113,6 +115,20 @@ pandocCompilerWithTransform ropt wopt f = cached cacheName $
113 where
115 where
114 cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
116 cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
115
117
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"
116
132
117--------------------------------------------------------------------------------
133--------------------------------------------------------------------------------
118-- | The default reader options for pandoc parsing in hakyll
134-- | The default reader options for pandoc parsing in hakyll