From e633df17dd72703a541c46d829096dfe40b75e50 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 15 Dec 2012 18:02:47 +0100 Subject: Rename pageCompiler to pandocCompiler --- src/Hakyll/Web/Pandoc.hs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/Hakyll/Web/Pandoc.hs') diff --git a/src/Hakyll/Web/Pandoc.hs b/src/Hakyll/Web/Pandoc.hs index c2319dc..82784be 100644 --- a/src/Hakyll/Web/Pandoc.hs +++ b/src/Hakyll/Web/Pandoc.hs @@ -1,5 +1,5 @@ -------------------------------------------------------------------------------- --- | Module exporting convenientpandoc bindings +-- | Module exporting convenient pandoc bindings module Hakyll.Web.Pandoc ( -- * The basic building blocks readPandoc @@ -9,6 +9,11 @@ module Hakyll.Web.Pandoc , renderPandoc , renderPandocWith + -- * Derived compilers + , pandocCompiler + , pandocCompilerWith + , pandocCompilerWithTransform + -- * Default options , defaultHakyllParserState , defaultHakyllWriterOptions @@ -16,10 +21,12 @@ module Hakyll.Web.Pandoc -------------------------------------------------------------------------------- +import Control.Applicative ((<$>)) import Text.Pandoc -------------------------------------------------------------------------------- +import Hakyll.Core.Compiler import Hakyll.Core.Item import Hakyll.Web.Pandoc.FileType @@ -78,6 +85,32 @@ renderPandocWith :: ParserState -> WriterOptions -> Item String -> Item String renderPandocWith state options = writePandocWith options . readPandocWith state +-------------------------------------------------------------------------------- +-- | Read a page render using pandoc +pandocCompiler :: Compiler (Item String) +pandocCompiler = + pandocCompilerWith defaultHakyllParserState defaultHakyllWriterOptions + + +-------------------------------------------------------------------------------- +-- | A version of 'pandocCompiler' which allows you to specify your own pandoc +-- options +pandocCompilerWith :: ParserState -> WriterOptions -> Compiler (Item String) +pandocCompilerWith state options = pandocCompilerWithTransform state options id + + +-------------------------------------------------------------------------------- +-- | An extension of 'pandocCompilerWith' which allows you to specify a custom +-- pandoc transformation for the content +pandocCompilerWithTransform :: ParserState -> WriterOptions + -> (Pandoc -> Pandoc) + -> Compiler (Item String) +pandocCompilerWithTransform state options f = cached cacheName $ + writePandocWith options . fmap f . readPandocWith state <$> getResourceBody + where + cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc" + + -------------------------------------------------------------------------------- -- | The default reader options for pandoc parsing in hakyll defaultHakyllParserState :: ParserState -- cgit v1.2.3