diff options
author | Norman Liu <57917002+dreamsmasher@users.noreply.github.com> | 2021-03-11 16:38:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-12 00:38:21 +0300 |
commit | b54212c7e2b8a84f95815e93a13223e1525c4f85 (patch) | |
tree | c7706121471cd7c18460d4fbd7f3445f561f6917 | |
parent | a5cf4470511bdf4fe7fe709b3dcf274fd9832d16 (diff) | |
download | hakyll-b54212c7e2b8a84f95815e93a13223e1525c4f85.tar.gz |
Add `renderPandocWithTransform` and `renderPandocWithTransformM`
* added function that allows for pre-pandoc transformations
* modified haddock docstring
* refactoring to avoid importing the kleisli fish
* Renamed `applyPandoc` to `renderPandocWithTransformM`, added non-monadic
variant. Exported previous new functions that I forgot to export.
-rw-r--r-- | lib/Hakyll/Web/Pandoc.hs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/Hakyll/Web/Pandoc.hs b/lib/Hakyll/Web/Pandoc.hs index 5f04de4..372465b 100644 --- a/lib/Hakyll/Web/Pandoc.hs +++ b/lib/Hakyll/Web/Pandoc.hs @@ -8,6 +8,8 @@ module Hakyll.Web.Pandoc , writePandocWith , renderPandoc , renderPandocWith + , renderPandocWithTransform + , renderPandocWithTransformM -- * Derived compilers , pandocCompiler @@ -104,6 +106,32 @@ renderPandocWith ropt wopt item = -------------------------------------------------------------------------------- +-- | An extension of `renderPandocWith`, which allows you to specify a custom +-- Pandoc transformation on the input `Item`. +-- Useful if you want to do your own transformations before running +-- custom Pandoc transformations, e.g. using a `funcField` to transform raw content. +renderPandocWithTransform :: ReaderOptions -> WriterOptions + -> (Pandoc -> Pandoc) + -> Item String + -> Compiler (Item String) +renderPandocWithTransform ropt wopt f = + renderPandocWithTransformM ropt wopt (return . f) + + +-------------------------------------------------------------------------------- +-- | Similar to `renderPandocWithTransform`, but the Pandoc transformation is +-- monadic. This is useful when you want the pandoc +-- transformation to use the `Compiler` information such as routes, +-- metadata, etc. along with your own transformations beforehand. +renderPandocWithTransformM :: ReaderOptions -> WriterOptions + -> (Pandoc -> Compiler Pandoc) + -> Item String + -> Compiler (Item String) +renderPandocWithTransformM ropt wopt f i = + writePandocWith wopt <$> (traverse f =<< readPandocWith ropt i) + + +-------------------------------------------------------------------------------- -- | Read a page render using pandoc pandocCompiler :: Compiler (Item String) pandocCompiler = @@ -137,9 +165,8 @@ pandocCompilerWithTransform ropt wopt f = pandocCompilerWithTransformM :: ReaderOptions -> WriterOptions -> (Pandoc -> Compiler Pandoc) -> Compiler (Item String) -pandocCompilerWithTransformM ropt wopt f = - writePandocWith wopt <$> - (traverse f =<< readPandocWith ropt =<< getResourceBody) +pandocCompilerWithTransformM ropt wopt f = + getResourceBody >>= renderPandocWithTransformM ropt wopt f -------------------------------------------------------------------------------- |