Skip to content

Commit

Permalink
Add variants of pandoc renderer and compiler for items
Browse files Browse the repository at this point in the history
Add renderPandocItemWithTransformM and pandocItemCompilerWithTransformM,
which work like the respective functions without the `item' infix, but
the transformation function is an Item Pandoc -> Item Pandoc instead of
just a Pandoc -> Pandoc. This allows one to more seamlessly compose
functions that do require the extra information that an item provides,
like bibliographic transformations.
  • Loading branch information
slotThe committed Oct 24, 2024
1 parent 5e252d2 commit c2026bb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/Hakyll/Web/Pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ module Hakyll.Web.Pandoc
, renderPandocWith
, renderPandocWithTransform
, renderPandocWithTransformM
, renderPandocItemWithTransformM

-- * Derived compilers
, pandocCompiler
, pandocCompilerWith
, pandocCompilerWithTransform
, pandocCompilerWithTransformM
, pandocItemCompilerWithTransformM

-- * Default options
, defaultHakyllReaderOptions
Expand Down Expand Up @@ -132,6 +134,21 @@ renderPandocWithTransformM ropt wopt f i =
writePandocWith wopt <$> (traverse f =<< readPandocWith ropt i)


--------------------------------------------------------------------------------
-- | Like 'renderPandocWithTransformM', but work on an 'Item' 'Pandoc' instead
-- of just a 'Pandoc'. This allows for more seamless composition of functions
-- that require the extra information that an 'Item' provides, like
-- bibliographic transformations with
-- 'Hakyll.Web.Pandoc.Biblio.processPandocBiblio'.
renderPandocItemWithTransformM
:: ReaderOptions -> WriterOptions
-> (Item Pandoc -> Compiler (Item Pandoc))
-> Item String
-> Compiler (Item String)
renderPandocItemWithTransformM ropt wopt f i =
writePandocWith wopt <$> (f =<< readPandocWith ropt i)


--------------------------------------------------------------------------------
-- | Read a page render using pandoc
pandocCompiler :: Compiler (Item String)
Expand Down Expand Up @@ -170,6 +187,20 @@ pandocCompilerWithTransformM ropt wopt f =
getResourceBody >>= renderPandocWithTransformM ropt wopt f


--------------------------------------------------------------------------------
-- | Like 'pandocCompilerWithTransformM', but work on an 'Item' 'Pandoc'
-- instead of just a 'Pandoc'. This allows for more seamless composition of
-- functions that require the extra information that an 'Item' provides, like
-- bibliographic transformations with
-- 'Hakyll.Web.Pandoc.Biblio.processPandocBiblio'.
pandocItemCompilerWithTransformM
:: ReaderOptions -> WriterOptions
-> (Item Pandoc -> Compiler (Item Pandoc))
-> Compiler (Item String)
pandocItemCompilerWithTransformM ropt wopt f =
getResourceBody >>= renderPandocItemWithTransformM ropt wopt f


--------------------------------------------------------------------------------
-- | The default reader options for pandoc parsing in hakyll
defaultHakyllReaderOptions :: ReaderOptions
Expand Down

0 comments on commit c2026bb

Please sign in to comment.